On Eclipse, The error red line was showing below the ChromeDriver statement and Line 18 (WebDriver driver = new ChromeDriver). Is that code correct?
Code:
package firsttestngpackage;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class FirstTestNGFile {
public String baseUrl = "http://demo.guru99.com/test/newtours/";
String driverPath=
"C:\\Users\\manoj\\Documents\\QA\\COURSE\\ChromeDriver94\\chromedriver.exe";
//public WebDriver driver;
@Test
public void f() {
System.out.println("launching chrome browser");
System.setProperty("webdriver.chrome.driver", driverPath);
WebDriver driver = new ChromeDriver();
driver.get(baseUrl);
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = driver.getTitle();
Assert.assertEquals(actualTitle, expectedTitle);
driver.close();
}
}
CodePudding user response:
Yes it looks fine to me.
Additionally, you'd have to import WebDriver
as well.
import org.openqa.selenium.WebDriver;
If that still did not work, I would suggest to take WebDriver driver
out of @Test
Sample code :
private WebDriver driver;
public String baseUrl = "http://demo.guru99.com/test/newtours/";
String driverPath = "C:\\Users\\manoj\\Documents\\QA\\COURSE\\ChromeDriver94\\chromedriver.exe";
@Test
public void f() {
System.out.println("launching chrome browser");
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver();
driver.get(baseUrl);
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = driver.getTitle();
Assert.assertEquals(actualTitle, expectedTitle);
driver.close();
}
CodePudding user response:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
// Few important imports in selenium to look.
// WebDriver interface is important for using methods
get(),getCurrentUrl(),findElement(),close(),quit() etc