我已经编写了下面的代码,用于在Chrome浏览器中打开一个站点并验证其标题。但使用时System.setProperty()
设置ChromeDriver
路径,它给了我语法错误,当我评论了线我得到:无法在Eclipse中使用ChromeDriver运行TestNG测试用例
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property..
我的代码:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class FirsttestNGFile {
String BaseURL = "http://newtours.demoaut.com/";
System.setProperty("webdriver.chrome.driver", "E:\\Automation Jars\\chromedriver_win32\\chromedriver.exe"); -- If I comment this line, I get Illegal state Exception for chromedriver path; if not commented , I get syntax error
WebDriver driver = new ChromeDriver();
@Test
public void verifyHomePageTitle() {
driver.get(BaseURL);
String ExpectedTitle = "Welcome: Mercury Tours";
String ActualTitle = driver.getTitle();
Assert.assertEquals(ExpectedTitle, ActualTitle);
driver.quit();
}
}
我也尝试过Project-> Clean;但是这并没有帮助 –