JUnit(Selenium WebDriver)在Chrome浏览器中打开www.google.co.uk
我曾尝试在JUnit(Selenium WebDriver)测试用例下运行以在Chrome浏览器中打开Google,但它失败并显示错误消息
“ChromeDriver可执行文件的路径必须由webdriver.chrome.driver系统属性设置;有关更多信息,请参阅http://code.google.com/p/selenium/wiki/ChromeDriver。”
正如该网站所述,我下载了ChromeDriver.exe,但不知道应该放置哪个PATH ? 或者如何在webdriver.chrome.driver中设置ChromeDriver路径?
请指教。
我的JUnit测试用例(将Firefox驱动程序更改为Chrome驱动程序):
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
public class Chrome_Open_Google {
private WebDriver driver;
private String baseUrl;
@Test
public void Test_Google_Chrome() throws Exception {
driver = new ChromeDriver();
baseUrl = "http://www.google.co.uk/";
driver.get(baseUrl);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
我相信你有几个选择:
要么指定您的PATH系统变量中的文件夹(您的chromedriver二进制文件) - 以下是方法
或者通过使用-Dwebdriver.chrome.driver=the/path/to/it
参数来调用应用程序webdriver.chrome.driver
作为系统属性。
或者相同的编程方式: System.setProperty("webdriver.chrome.driver", "your/path/to/it");
或这个:
private static ChromeDriverService service;
private WebDriver driver;
@BeforeClass
public static void createAndStartService() {
service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("path/to/my/chromedriver"))
.usingAnyFreePort()
.build();
service.start();
}
@Before
public void createDriver() {
driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@AfterClass
public static void createAndStopService() {
service.stop();
}
System.setProperty(“webdriver.chrome.driver”,“your path to it”);
例如:
System.setProperty("webdriver.chrome.driver", "C:Seleniumdriverchromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
链接地址: http://www.djcxy.com/p/52325.html
上一篇: JUnit (Selenium WebDriver) to open www.google.co.uk in Chrome Browser
下一篇: What is the difference between Selenium IDE, Server, RC, 2.0, and WebDriver?