簡體   English   中英

E2E 測試未在 Jenkins 作業上運行

[英]E2E tests are not running on Jenkins job

我在本地安裝了兩個 Docker 容器,其中包括 Jenkins 和 Selenium。 我有一個用 Java 編寫的 Maven 項目,我在其中創建了一套使用 Selenium 實現的 E2E(端到端)測試。 從 IntelliJ 的終端,使用“mvn test”(或 mvn clean test 或其他組合)命令,即使我對 Chrome 驅動程序使用無頭或不使用,測試也會運行。 此外,這是用 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 上創建了一個基於我的 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

上面配置了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),但現在閱讀並應用后就可以了: 如何在啟動chromedriver時修復“[嚴重]:綁定()失敗:無法分配請求的地址(99)”

在所有這些操作以及可能忘記寫在這里的其他操作之后,現在似乎是 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 Selenium HTML Report chromedriver Jira Pipeline Maven Integration Selenium Capability Axis NodeJS

到目前為止還閱讀並使用了那些(在這種情況下可能對其他人有用):

Selenium Chrome 瀏覽器 org.openqa.selenium.WebDriverException:等待驅動程序服務器啟動超時

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

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

Maven 構建成功,但沒有在 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 失敗后不繼續執行測試

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 上運行我的端到端測試並構建一個工作,任何建議都會有所幫助!

在 Jenkins 的 VM 上本地安裝解決了通信問題:

  • 手動安裝:Chromium(作為 Linux 機器)和
  • ChromeDriver 插件,也是從命令行手動安裝的,因為 Jenkins 界面的插件版本較低,與上一版本的 Chromium 不兼容(91...)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM