[英]E2E tests are not running on Jenkins job
I have installed locally two Docker containers which include Jenkins and Selenium.我在本地安装了两个 Docker 容器,其中包括 Jenkins 和 Selenium。 I have a Maven project written in Java where I created a suite of E2E (End To End) tests realised using Selenium.
我有一个用 Java 编写的 Maven 项目,我在其中创建了一套使用 Selenium 实现的 E2E(端到端)测试。 From the terminal of IntelliJ, using "mvn test" (or mvn clean test or other combinations) command, the tests are running even if I use headless or not for Chrome Driver.
从 IntelliJ 的终端,使用“mvn test”(或 mvn clean test 或其他组合)命令,即使我对 Chrome 驱动程序使用无头或不使用,测试也会运行。 Also, this is one of the plugins written in POM:
此外,这是用 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>
The XML suite file contains the classes and the methods of each automated test. XML 套件文件包含每个自动化测试的类和方法。
The problem appears on Jenkins.问题出现在詹金斯身上。 So, I have created on Jenkins a job based on my Maven project where I set up the following goal and options after many tries (just to check if the result will become the wished one) for the Build section:
因此,我在 Jenkins 上创建了一个基于我的 Maven 项目的工作,我在多次尝试后为 Build 部分设置了以下目标和选项(只是为了检查结果是否会成为希望的结果):
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
The fork-count was configured above because of the following error when the jenkins job was built:上面配置了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]
After that, I have also installed those libraries at the root of the Jenkins container, due to the errors that appeared in the maven surefire report:之后,由于 maven surefire 报告中出现的错误,我还在 Jenkins 容器的根目录下安装了这些库:
root@04f87025a7fb:/# apt-get install libnss3
) root@04f87025a7fb:/# apt-get install libnss3
) I have also interfered with: cannot assign requested address (99), but now is ok after reading and applying this: How to fix "[SEVERE]: bind() failed: Cannot assign requested address (99)" while starting chromedriver我也干扰了:无法分配请求的地址(99),但现在阅读并应用后就可以了: 如何在启动chromedriver时修复“[严重]:绑定()失败:无法分配请求的地址(99)”
After all of this operations and maybe others that it is possible to forgot writing here, now it seems to be a communication error between Jenkins and the Chrome Web Driver (or anything else) from which I ask for your help for suggestions.在所有这些操作以及可能忘记写在这里的其他操作之后,现在似乎是 Jenkins 和 Chrome Web 驱动程序(或其他任何东西)之间的通信错误,我向您寻求建议。 My last report after running a job says:
我运行工作后的最后一份报告说:
[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
Old error:旧错误:
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'
Plugins installed on Jenkins: Selenium Selenium HTML Report chromedriver Jira Pipeline Maven Integration Selenium Capability Axis NodeJS Jenkins 上安装的插件:Selenium Selenium HTML Report chromedriver Jira Pipeline Maven Integration Selenium Capability Axis NodeJS
Also read and used those until now (that maybe will be useful for others in this situation):到目前为止还阅读并使用了那些(在这种情况下可能对其他人有用):
Selenium Chrome Browser org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start Selenium Chrome 浏览器 org.openqa.selenium.WebDriverException:等待驱动程序服务器启动超时
https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html
https://howtodoinjava.com/testng/how-to-execute-testng-tests-with-maven-build/ https://howtodoinjava.com/testng/how-to-execute-testng-tests-with-maven-build/
Maven BUILD SUCCESSFUL but no tests executed in Selenium Maven 构建成功,但没有在 Selenium 中执行测试
The Failsafe Plugin is designed to run integration tests while the Surefire Plugin is designed to run unit tests. Failsafe 插件旨在运行集成测试,而 Surefire 插件旨在运行单元测试。
https://maven.apache.org/components/surefire/maven-failsafe-plugin/ https://maven.apache.org/components/surefire/maven-failsafe-plugin/
https://www.geekyhacker.com/2020/07/11/run-integration-tests-with-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 TestNG 失败后不继续执行测试
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>
I have also used the Maven Failsafe plugin, but unfortunately nothing changed.我也使用了 Maven Failsafe 插件,但不幸的是没有任何改变。 TestNG version 7.0.0 used now.
现在使用的 TestNG 版本 7.0.0。
So, I want to run my end to end tests on Jenkins with a job build in, any advice will be helpful!所以,我想在 Jenkins 上运行我的端到端测试并构建一个工作,任何建议都会有所帮助!
The communication issue was solved installing locally on the VM of the Jenkins:在 Jenkins 的 VM 上本地安装解决了通信问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.