chrome在jmeter docker容器中启动失败

问题描述 投票:0回答:1

我创建了一个 docker 映像,其中包含所有 jmeter 包、库,并且我能够在正在运行的容器中调用一些其他 jmeter 测试用例。

但是对于特殊的selenium jmeter测试用例,需要chrome以无头模式运行,它会失败,因为chrome未启动(?)

这是我的软件包的版本:

jmeter: 5.6.2
selenium-plugin on jmeter: 4.13
google-chrome: 120.0.6099.109
chrome-driver: 120.0.6099.109

我检查了jmeter日志,上面写着:

2024-01-10 16:50:36,994 ERROR o.a.j.t.JMeterThread: Error calling threadStarted
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Host info: host: 'aac0c7996ca3', ip: '172.17.0.2'
Build info: version: '4.13.0', revision: 'ba948ece5b*'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-166-generic', java.version: '1.8.0_392'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: true, browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --start-maximized, --headless=new], binary: /usr/bin/google-chrome, extensions: []}, proxy: Proxy(system)}]}]
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:140) ~[selenium-remote-driver-4.13.0.jar:?]

我用谷歌搜索了这个问题,有人建议让 chrome 以这样的选项启动:

--disable-dev-shm-usage

我可以在 jmeter 项目中给出 google-chrome 的位置以及运行选项吗?

谢谢,

杰克

docker google-chrome selenium-webdriver jmeter
1个回答
0
投票

尝试运行您的容器,例如:

docker run -it your-image-name-here /bin/sh -c "/usr/bin/google-chrome --headless"

看看输出是什么,然后在修复 Chrome 安装后采取必要的操作,JMeter 也应该能够启动它。

如果您刚刚从此页面下载:https://googlechromelabs.github.io/chrome-for-testing/

在尝试启动 Chrome 之前,您可能需要安装一些依赖项,以下是在 Ubuntu 22.04

上需要安装的内容
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ffff1b00000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ffff1afb000)
    libgobject-2.0.so.0 => not found
    libglib-2.0.so.0 => not found
    libnss3.so => not found
    libnssutil3.so => not found
    libsmime3.so => not found
    libnspr4.so => not found
    libdbus-1.so.3 => not found
    libatk-1.0.so.0 => not found
    libatk-bridge-2.0.so.0 => not found
    libcups.so.2 => not found
    libgio-2.0.so.0 => not found
    libdrm.so.2 => not found
    libexpat.so.1 => not found
    libxcb.so.1 => not found
    libxkbcommon.so.0 => not found
    libatspi.so.0 => not found
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffff1a0e000)
    libX11.so.6 => not found
    libXcomposite.so.1 => not found
    libXdamage.so.1 => not found
    libXext.so.6 => not found
    libXfixes.so.3 => not found
    libXrandr.so.2 => not found
    libgbm.so.1 => not found
    libpango-1.0.so.0 => not found
    libcairo.so.2 => not found
    libasound.so.2 => not found
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ffff19ea000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffff17c2000)
    /lib64/ld-linux-x86-64.so.2 (0x00007ffffffc4000)

接下来考虑提供您的 Dockerfile 和 JMeter .jmx 测试计划,换句话说,一个 最小可重现示例,因为我们不知道为什么 Chrome 无法在您的容器中启动,并且您有限的输出无法告诉完整的故事。

这是一个示例 Dockerfile,它使用您尝试使用的 Chrome 和 JMeter 版本:

FROM ubuntu:22.04

RUN apt update
RUN apt install wget gnupg unzip -y
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt update
RUN apt install google-chrome-stable openjdk-8-jdk-headless -y
RUN wget -q https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.6.2.tgz
RUN tar xf apache-jmeter-5.6.2.tgz
RUN wget -q https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.109/linux64/chrome-linux64.zip
RUN unzip chrome-linux64.zip
RUN mv chrome-linux64/chrome /usr/bin/google-chrome
WORKDIR /apache-jmeter-5.6.2/bin
RUN wget -q https://jmeter-plugins.org/get/ -O ../lib/ext/jmeter-plugins-manager.jar
RUN wget -q https://repo1.maven.org/maven2/kg/apc/cmdrunner/2.3/cmdrunner-2.3.jar -P ../lib/
RUN java -cp ../lib/ext/jmeter-plugins-manager.jar org.jmeterplugins.repository.PluginManagerCMDInstaller
RUN ./PluginsManagerCMD.sh install jpgc-webdriver
RUN google-chrome --sandbox --version
RUN wget -q https://chromedriver.storage.googleapis.com/$(google-chrome --sandbox --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')/chromedriver_linux64.zip || wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$(google-chrome --sandbox --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')/linux64/chromedriver-linux64.zip
RUN unzip -j chromedriver-linux64.zip chromedriver-linux64/chromedriver chromedriver || true
RUN <<EOF cat >> test.jmx
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.2">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.tearDown_on_shutdown">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<stringProp name="LoopController.loops">1</stringProp>
<boolProp name="LoopController.continue_forever">false</boolProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.delayedStart">false</boolProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</ThreadGroup>
<hashTree>
<com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler guiclass="com.googlecode.jmeter.plugins.webdriver.sampler.gui.WebDriverSamplerGui" testclass="com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler" testname="jp@gc - WebDriver Sampler" enabled="true">
<stringProp name="WebDriverSampler.script">WDS.sampleResult.sampleStart()
WDS.browser.get(&apos;http://jmeter-plugins.org&apos;)
System.out.println(&quot;I&apos;m too stupid for launching JMeter in Docker, I need to quit IT and become a rickshaw&quot;)
WDS.sampleResult.sampleEnd()
</stringProp>
<stringProp name="WebDriverSampler.parameters"></stringProp>
<stringProp name="WebDriverSampler.language">groovy</stringProp>
</com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler>
<hashTree/>
<com.googlecode.jmeter.plugins.webdriver.config.ChromeDriverConfig guiclass="com.googlecode.jmeter.plugins.webdriver.config.gui.ChromeDriverConfigGui" testclass="com.googlecode.jmeter.plugins.webdriver.config.ChromeDriverConfig" testname="jp@gc - Chrome Driver Config" enabled="true">
<boolProp name="WebDriverConfig.acceptinsecurecerts">false</boolProp>
<boolProp name="WebDriverConfig.reset_per_iteration">false</boolProp>
<stringProp name="WebDriverConfig.driver_path">/apache-jmeter-5.6.2/bin/chromedriver</stringProp>
<boolProp name="WebDriverConfig.dev_mode">false</boolProp>
<boolProp name="WebDriverConfig.headless">true</boolProp>
<boolProp name="WebDriverConfig.maximize_browser">true</boolProp>
<stringProp name="ChromeDriverConfig.additional_args">--no-sandbox</stringProp>
<stringProp name="ChromeDriverConfig.binary_path"></stringProp>
<stringProp name="WebDriverConfig.proxy_type">SYSTEM</stringProp>
<stringProp name="WebDriverConfig.proxy_pac_url"></stringProp>
<stringProp name="WebDriverConfig.http_host"></stringProp>
<intProp name="WebDriverConfig.http_port">8080</intProp>
<boolProp name="WebDriverConfig.use_http_for_all_protocols">true</boolProp>
<stringProp name="WebDriverConfig.https_host"></stringProp>
<intProp name="WebDriverConfig.https_port">8080</intProp>
<stringProp name="WebDriverConfig.ftp_host"></stringProp>
<intProp name="WebDriverConfig.ftp_port">8080</intProp>
<stringProp name="WebDriverConfig.socks_host"></stringProp>
<intProp name="WebDriverConfig.socks_port">8080</intProp>
<stringProp name="WebDriverConfig.no_proxy">localhost</stringProp>
<stringProp name="WebDriverConfig.custom_capabilites"></stringProp>
</com.googlecode.jmeter.plugins.webdriver.config.ChromeDriverConfig>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
EOF
ENTRYPOINT ["/bin/bash", "-c","./jmeter.sh -n -t test.jmx -l result.jtl"]

如果你像这样构建它:

docker build --platform linux/amd64 -t jmeter-webdriver . 

然后运行它:

docker run -it jmeter-webdriver

您应该会看到一个成功的请求。

随意使用它作为基础或按原样使用。

更多信息:如何将 Docker 与 JMeter 结合使用

© www.soinside.com 2019 - 2024. All rights reserved.