2

我有一个属性文件,用于加载 chrome 的不同安装位置的位置:

mac.chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
win.xp.chrome="%HOMEPATH%\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe"
win.7.chrome="C:\\Users\\%USERNAME%\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
linux.chrome="//usr//bin//google-chrome"

我读了这些,当我设置 webdriver.chrome.driver 属性时作为调试我记录它:

System.setProperty("webdriver.chrome.driver", (String)props.get("mac.chrome"));
log.logInfo("Mac Chrome Driver Property Set To: " + System.getProperty("webdriver.chrome.driver"));

记录器输出:

INFO: Mac Chrome Driver Property Set To: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

当我执行测试时,我看到以下错误:

[junit] The driver executable does not exist: /Users/<user>/eclipseproject/automation/com/gui/"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
[junit] java.lang.IllegalStateException: The driver executable does not exist: /Users/<user>/eclipseproject/automation/com/gui/"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
[junit]     at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
[junit]     at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:117)
[junit]     at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:112)
[junit]     at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:75)
[junit]     at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
[junit]     at drivermanager.DriverManagement.initializeDriver(DriverManagement.java:46)
[junit]     at tests.TestChromeChrome.setUp(TestAlerts.java:44)

我在发布 absolutePath 的错误中看到,这很有意义,因为 DriverService.checkExecutable 执行了 exe.getAbsolutePath() 调用,但我不明白为什么我的项目的路径也包括在内。如果有人有任何建议,那就太棒了!

4

1 回答 1

1

在浏览器开始正确启动之前,需要为 chrome 设置适当的 DesiredCapabilities 对象。还需要从我的属性文件中删除“”(这解决了 IllegalStateException)。

于 2013-06-20T19:53:09.973 回答