简体   繁体   中英

E2E tests are not running on Jenkins job

I have installed locally two Docker containers which include Jenkins and Selenium. I have a Maven project written in Java where I created a suite of E2E (End To End) tests realised using Selenium. 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. Also, this is one of the plugins written in 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.

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:

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:

[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:

  1. libglib2.0-0 (using the indications from Maythux: https://askubuntu.com/questions/58664/cant-install-package-libglib2-0-dev-because-it-depends-on-some-unknown-version )
  2. libnss3 (simply using: 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

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. 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

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

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

The Failsafe Plugin is designed to run integration tests while the Surefire Plugin is designed to run unit tests.

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>

I have also used the Maven Failsafe plugin, but unfortunately nothing changed. TestNG version 7.0.0 used now.

So, I want to run my end to end tests on Jenkins with a job build in, any advice will be helpful!

The communication issue was solved installing locally on the VM of the Jenkins:

  • manually installed: Chromium (being a Linux machine) and
  • ChromeDriver plugin, also installed manually from the command line, since the plugin from the Jenkins interface was a lower version, which was not compatible with the last version of Chromium (91...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM