cannot find Chrome binary问题解决办法

新手一枚,最近一直在学习Jenkins+testng+maven测试框架,遇到一个这样问题:

本地IDEA执行测试用例正常,但使用Jenkins时就会报以下错误信息:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
[TestNGContentHandler] [WARN] It is strongly recommended to add "<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >" at the top of your file, otherwise TestNG may fail or not work as expected.
Starting ChromeDriver 2.29.461591 (62ebf098771772160f391d75e589dc567915b233) on port 12009
Only local connections are allowed.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Tests run: 2, Failures: 1, Errors: 0, Skipped: 1, Time elapsed: 2.714 sec <<< FAILURE! - in TestSuite
beforeMethod(cases.ALoginTest)  Time elapsed: 2.547 sec  <<< FAILURE!
org.openqa.selenium.WebDriverException: 
unknown error: cannot find Chrome binary
  (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 112 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: '123-PC', ip: '172.16.20.181', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: driver.version: ChromeDriver

而且奇怪的是在使用IE浏览器打开测试用例时正常。

经过Google后发现这样一篇文章:https://stackoverflow.com/questions/41144934/cannot-find-chrome-binary-when-executing-a-selenium-testng-test-in-jenkins-on

然后按照上面方法进行操作:

ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Users\\123\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","E:/seleniumsever/chromedriver.exe");
driver = new ChromeDriver();
经过验证还是报同样问题。

考虑到权限问题,于是重装了chrome,目录在

C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe

然后代码改成如下:

ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","E:/seleniumsever/chromedriver.exe");
driver = new ChromeDriver();
再次在Jenkins上重试,问题解决!!!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值