package newpackage;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;public class PG1 {public static void main(String[] args) {// declaration and instantiation of objects/variablesWebDriver driver ;System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\Mozilla Firefox");driver = new FirefoxDriver();String baseUrl = "http://newtours.demoaut.com";String expectedTitle = "Welcome: Mercury Tours";String actualTitle = "";// launch Fire fox and direct it to the Base URLdriver.get(baseUrl);// get the actual value of the titleactualTitle = driver.getTitle();/** compare the actual title of the page with the expected one and print* the result as "Passed" or "Failed"*/if (actualTitle.contentEquals(expectedTitle)){System.out.println("Test Passed!");} else {System.out.println("Test Failed");}//close Fire foxdriver.close();// exit the program explicitlySystem.exit(0);}
I did find the solution to this problem. Quite a silly one!
Eclipse takes up the highest JavaSE version for execution. Now Java had released JDK-13 earlier and JDK-1.8 just recently.
If you have been using all the latest software releases like me, it is highly probable your Eclipse is also picking up the incorrect version.
No worries!! Just scrap this Java project, create a new one and while setting it up select the correct JavaSE (1.8 in my case) for execution and you should be good to go. Eclipse will set this as default and use it for all your future projects.
Let me know if this worked for you too. Happy Coding!!