JMeter集成ChromeWebDriver在Bamboo运行失败,本地Maven正常
解决Bamboo平台上JMeter集成ChromeWebDriver的运行问题
从报错信息可直接定位核心问题:
2024-03-11 01:43:54,436 ERROR o.a.j.t.JMeterThread: Error calling threadStarted
java.lang.IllegalStateException: Actual executable Unable to find executable for: /opt/bamboo-agent-home/xml-data/build-dir/MOZ-MUPS-LOAD/MUPFormsSanityScript/target/af52d122-4105-45d7-b873-17f713a00fc6/jmeter/bin/C:\Stash\mup.test\MUPFormsSanityScript\src\test\resources\Drivers\chromedriver.exe
你的JMeter脚本硬编码了Windows环境下的chromedriver路径(C:\Stash\...\chromedriver.exe),但Bamboo运行在Linux环境中,引发两个致命问题:
- Linux系统无法识别Windows格式路径,错误地将其拼接到本地工作目录后,找不到对应文件
- Linux环境无法直接执行
.exe格式的可执行文件
需要做以下配置调整:
1. 环境分离配置,取消硬编码路径
- 在JMeter脚本中使用参数化路径,比如用
${__P(chromedriver.path)}替代固定路径 - 在Maven的
pom.xml中配置多环境profile:<profiles> <profile> <id>windows</id> <properties> <chromedriver.path>C:\Stash\mup.test\MUPFormsSanityScript\src\test\resources\Drivers\chromedriver.exe</chromedriver.path> </properties> </profile> <profile> <id>linux</id> <properties> <chromedriver.path>/path/to/bamboo/chromedriver</chromedriver.path> </properties> </profile> </profiles> - 本地运行用
mvn test -P windows,Bamboo构建时指定mvn test -P linux
2. 适配Bamboo的Linux运行环境
- 在Bamboo Agent上安装与chromedriver版本匹配的Chrome浏览器(版本必须严格对应,否则会启动失败)
- 给chromedriver添加可执行权限:
chmod +x /path/to/chromedriver - 配置Chrome无头模式(Bamboo通常无桌面环境),在JMeter的ChromeOptions中添加参数:
--headless=new --disable-gpu --no-sandbox
3. 路径规范优化
- 可将chromedriver放到Bamboo Agent的系统PATH中,脚本里直接写
chromedriver即可,无需指定全路径 - 如果通过Maven打包携带chromedriver,需在
pom.xml中配置资源过滤,根据环境复制对应平台的驱动文件到目标目录
内容的提问来源于stack exchange,提问作者PRANESH
相关产品推荐
相关产品推荐

