webdriver + jenkins执行用例报“unknown error: cannot find Chrome binary”

本文解决在Jenkins环境中使用Selenium时遇到的ChromeDriver无法找到Chrome浏览器的问题。通过设置WebDriver属性和ChromeOptions,指定Chrome浏览器的路径,成功解决了找不到Chromebinary的错误。

引自:https://blog.youkuaiyun.com/dreamtl/article/details/53486563

在eclipse ide中好着的,但集成到jenkins报错:org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary

解决方法:

分析:可能是因没有定位chrome浏览器的位置,找不到binary ,所以报错,增加红框语句:

System.setProperty("webdriver.chrome.driver", "files/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setBinary("chrome.exe路径");
ChromeDriver driver = new ChromeDriver(options);

然后打断点发现:binary是有值的;重启jenkins好了;
 

=============== ROOT CAUSE ===================== Caused by: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html ================================================ 08-15-2025 03:37:49 PM Test Cases/Get Report in CWS Elapsed time: 2.160s Test Cases/Get Report in CWS FAILED. Reason: com.kms.katalon.core.exception.StepFailedException: Unable to open browser with url: '' at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:117) at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:43) at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword.openBrowser(OpenBrowserKeyword.groovy:47) at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword.execute(OpenBrowserKeyword.groovy:33) at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74) at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.openBrowser(WebUiBuiltInKeywords.groovy:62) at Get Report in CWS.run(Get Report in CWS:62) at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194) at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119) at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448) at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439) at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418) at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410) at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285) at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:137) at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:125) at TempTestCase1755243465405.run(TempTestCase1755243465405.groovy:25) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) Caused by: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created from unknown error: cannot find Chrome binary Host info: host: 'CNM62C3LR3', ip: '192.168.1.7' Build info: version: '4.22.0', revision: 'c5f3146703' System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.14' Driver info: com.kms.katalon.selenium.driver.CChromeDriver Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, unhandledPromptBehavior: ignore, webSocketUrl: true}]}] at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:114) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:61) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:162) at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:232) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:161) at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:114) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:72) at com.kms.katalon.selenium.driver.CChromeDriver.<init>(CChromeDriver.java:13) at com.kms.katalon.core.webui.driver.chrome.ChromeDriverBuilder.createDriver(ChromeDriverBuilder.java:41) at com.kms.katalon.core.webui.driver.AbstractDriverBuilder.build(AbstractDriverBuilder.java:39) at com.kms.katalon.core.webui.driver.DriverFactory.startNewBrowser(DriverFactory.java:251) at com.kms.katalon.core.webui.driver.DriverFactory.openWebDriver(DriverFactory.java:161) at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword$_openBrowser_closure1.doCall(OpenBrowserKeyword.groovy:40) at com.kms.katalon.core.webui.keyword.builtin.OpenBrowserKeyword$_openBrowser_closure1.call(OpenBrowserKeyword.groovy) at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:35) ... 18 more 這個報錯可以讓我在katalon的test Case中進行處理嗎
08-16
在Linux系统中出现 `unknown error: cannot find Chrome binary` 错,通常是因为Selenium无法找到Chrome浏览器的可执行文件路径。以下是一些可行的解决方法: ### 明确Chrome执行文件路径 要保证Selenium能找到Chrome的可执行文件,就需要在代码里明确指定其路径。示代码如下: ```python from selenium import webdriver from selenium.webdriver.chrome.service import Service # 指定ChromeDriver的路径 service = Service('/path/to/chromedriver') # 指定Chrome二进制文件的路径 options = webdriver.ChromeOptions() options.binary_location = '/usr/bin/google-chrome' # 根据实际情况修改 # 创建Chrome浏览器实 driver = webdriver.Chrome(service=service, options=options) ``` ### 检查Chrome是否安装 要确保Chrome浏览器已经安装在Linux系统中。可以通过以下命令来安装Chrome: ```bash # 添加Google Chrome存储库 wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list # 更新包列表并安装Google Chrome sudo apt-get update sudo apt-get install google-chrome-stable ``` ### 检查ChromeDriver版本 要保证使用的ChromeDriver版本与安装的Chrome浏览器版本兼容。可以从[ChromeDriver官方网站](https://sites.google.com/chromium.org/driver/)下载匹配的ChromeDriver版本。下载完成后,将其添加到系统的`PATH`环境变量中,或者在代码里指定其路径。 ### 检查文件权限 要确保Chrome执行文件和ChromeDriver文件具有执行权限。可以使用以下命令为文件添加执行权限: ```bash chmod +x /usr/bin/google-chrome chmod +x /path/to/chromedriver ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值