【问题标题】:E2E tests are not running on Jenkins jobE2E 测试未在 Jenkins 作业上运行
【发布时间】:2021-07-22 14:31:41
【问题描述】:

我在本地安装了两个 Docker 容器,其中包括 Jenkins 和 Selenium。我有一个用 Java 编写的 Maven 项目,我在其中创建了一套使用 Selenium 实现的 E2E(端到端)测试。从 IntelliJ 的终端,使用“mvn test”(或 mvn clean test 或其他组合)命令,即使我对 Chrome 驱动程序使用 headless 或不使用,测试也在运行。 另外,这是用 POM 编写的插件之一:

<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>${maven-surefire-plugin.version}</version>
          <configuration>
            <forkCount>3</forkCount>
            <reuseForks>true</reuseForks>
            <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
            <suiteXmlFiles>
              <suiteXmlFile>testng_suiteTest.xml</suiteXmlFile>
            </suiteXmlFiles>
          </configuration>
        </plugin>

XML 套件文件包含每个自动化测试的类和方法。

问题出现在 Jenkins 上。因此,我在 Jenkins 上创建了一个基于我的 Maven 项目的工作,我在多次尝试后为构建部分设置了以下目标和选项(只是为了检查结果是否会成为希望的结果):

clean install test -DsuiteXmlFile=testngSuite.xml -Dwebdriver.chrome.driver=/var/jenkins_home/tools/chromedriver/chromedriver -Dselenium.browser=chrome -Dwebdriver.chrome.whitelistedIps=172.17.0.2

上面配置了fork-count,因为构建jenkins作业时出现以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project : 
Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: 
The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1]

之后,由于 maven surefire 报告中出现的错误,我还在 Jenkins 容器的根目录下安装了这些库:

  1. libglib2.0-0(使用来自 Maythux 的指示:https://askubuntu.com/questions/58664/cant-install-package-libglib2-0-dev-because-it-depends-on-some-unknown-version
  2. libnss3(只需使用:root@04f87025a7fb:/# apt-get install libnss3

我也干扰了:无法分配请求的地址(99),但在阅读并应用后现在可以了:How to fix "[SEVERE]: bind() failed: Cannot assign requested address (99)" while starting chromedriver

在完成所有这些操作以及可能忘记在这里写的其他操作之后,现在似乎是 Jenkins 和 Chrome Web 驱动程序(或其他任何东西)之间的通信错误,我向您寻求建议的帮助。 我在工作后的最后一份报告说:

[INFO] Running TestSuite
Jul 22, 2021 10:06:44 AM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
Starting ChromeDriver 92.0.4515.43 (8c61b7e2989f2990d42f859cac71319137787cce-refs/branch-heads/4515@{#306}) on port 18974
Remote connections are allowed by an allowlist (172.17.0.2).
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jul 22, 2021 10:06:45 AM org.openqa.selenium.json.JsonOutput lambda$new$12
WARNING: Attempt to convert JsonElement from GSON. This functionality is deprecated. Diagnostic stacktrace follows
org.openqa.selenium.json.JsonException: Stack trace to determine cause of warning
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: '04f87025a7fb', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.25-linuxkit', java.version: '1.8.0_292'
.........
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[ERROR] There are test failures.
.........
An error occurred while instantiating class com.projectName.hr.E2E_Testing.E2E_ClientAboutSection_Test: null
org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
An error occurred while instantiating class com.projectName.hr.E2E_Testing.E2E_ClientAboutSection_Test: null
.........
[INFO] Skipping execution of surefire because it has already been run for this configuration
[JENKINS] Recording test results
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.967 s
[INFO] Finished at: 2021-07-22T10:06:46Z
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /var/jenkins_home/workspace/E2E/automation/pom.xml to com.incrys.hr/automation/1.0-SNAPSHOT/automation-1.0-SNAPSHOT.pom
channel stopped
Finished: SUCCESS

老错误:

Caused by: java.lang.ExceptionInInitializerError
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:23)
    at org.testng.internal.InstanceCreator.instantiateUsingDefaultConstructor(InstanceCreator.java:193)
    at org.testng.internal.InstanceCreator.createInstanceUsingObjectFactory(InstanceCreator.java:113)
    ... 26 more
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: '04f87025a7fb', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.25-linuxkit', java.version: '1.8.0_292'

Jenkins 上安装的插件: 硒 Selenium HTML 报告 铬驱动程序 吉拉 管道 Maven 集成 Selenium 能力轴 NodeJS

到目前为止还阅读并使用了那些(在这种情况下可能对其他人有用):

Selenium Chrome Browser org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start

https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

https://howtodoinjava.com/testng/how-to-execute-testng-tests-with-maven-build/

Maven BUILD SUCCESSFUL but no tests executed in Selenium

Failsafe 插件旨在运行集成测试,而 Surefire 插件旨在运行单元测试。

https://maven.apache.org/components/surefire/maven-failsafe-plugin/

https://www.geekyhacker.com/2020/07/11/run-integration-tests-with-maven-failsafe-plugin/

TestNG does not continue execute tests after failure

configfailurepolicy="continue" 


  <properties>
    <java.version>1.8</java.version>
    <org.mapstruct.version>1.4.1.Final</org.mapstruct.version>
    <junit.jupiter.version>5.3.2</junit.jupiter.version>
    <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
    <maven-jar-plugin.version>3.8.1</maven-jar-plugin.version>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

我也使用了 Maven Failsafe 插件,但遗憾的是没有任何改变。 现在使用的 TestNG 版本 7.0.0。

所以,我想通过内置作业在 Jenkins 上运行我的端到端测试,任何建议都会有所帮助!

【问题讨论】:

  • 首先我强烈建议不要使用surefire来运行E2E测试,因为它们属于故障安全插件......此外,我建议使用testcontainers.org来支持通过selenium结合故障安全和JUnit运行UI测试木星 (fosdem.org/2021/schedule/event/endtoendtests)
  • 我还看到你使用的是古老版本的surefire插件,你真的应该使用更新的版本(你使用哪个版本的Maven?)哪个JDK版本等等。
  • 我也使用了故障保护插件,但不幸的是没有任何改变,我会用它挖掘更多。 1.85.3.22.22.2版本> 3.8.11.71.7 maven.compiler.target> Maven插件也使用了其他版本,TestNG是7.0.0版本,没什么变化。
  • 首先,如果您想使用 junit jupiter,最小 Java 版本是 8。其次,您是否尝试在同一个项目中使用 Test NG 和 JUnit Jupiter?
  • 我在运行版本 92.0.4515.43 时遇到问题,也许这也是您的问题。不过它运行良好,就像无头一样。

标签: docker maven jenkins selenium-chromedriver e2e-testing


【解决方案1】:

在 Jenkins 的虚拟机上本地安装解决了通信问题:

  • 手动安装:Chromium(作为 Linux 机器)和
  • ChromeDriver 插件,也是从命令行手动安装的,因为 Jenkins 界面的插件版本较低,与 Chromium 的最新版本 (91...) 不兼容

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-03
    • 1970-01-01
    • 2017-12-22
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多