我有一个属性文件,用于加载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 prop我作为调试我记录它:
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)
我在错误中看到绝对路径已发布,这有意义,因为DriverService.checkExecutable执行exe.getAbsolutePath()调用,但我不明白为什么我的项目的路径也包含在内。如果有人有任何建议会很棒!
答案 0 :(得分:1)
在浏览器开始正确启动之前,需要为chrome设置正确的DesiredCapabilities对象。还需要从我的属性文件中删除“”(它解决了IllegalStateException)。