我已经设置了一个存储库,用于使用 TestNG 和 Maven 构建/运行 selenium 测试。在我的机器上本地运行测试,测试运行没有任何问题,但在为存储库设置 Github 操作后,那里的运行显示 0/0 测试已运行。否则构建过程不会出现错误。
这里有一个链接,指向发生这种情况时运行的示例操作。
关于什么阻止测试在行动中运行有什么想法吗?
项目存储库:https://github.com/camescasse/java-automation/
这是我的 actions.yml:
name: Selenium Tests
on:
push:
branches:
- master
- 38-fix-github-actions-test-run
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
distribution: 'zulu'
java-version: '22'
cache: 'maven'
- name: Build with Maven, run tests
run: mvn -B clean test
和我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>java-automation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.19.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.truth/truth -->
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
到目前为止,我已经尝试手动安装 chromedriver 依赖项,即使它们应该已经与 Selenium 一起安装。还尝试降级到较旧的 java 版本一直到 17。
我尝试克隆您的项目并在本地运行它们。这是我注意到的:
maven-surefire-plugin:2.12.4:test
。请参阅此处[INFO] --- surefire:2.12.4:test (default-test) @ java-automation ---
[INFO] Surefire report directory: /Users/kmahadevan/githome/playground/so/java-automation/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running BaseTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@326de728
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.43 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
现在,当您增强 pom 文件以包含最新发布的 Surefire 插件版本时(片段如下所示)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
</plugins>
</build>
然后运行相同的测试,您应该看到如下所示的失败
[INFO] --- surefire:3.2.5:test (default-test) @ java-automation ---
[INFO] Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
.properties file not found
Apr 22, 2024 11:46:39 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 124, returning the closest version; found: 123; Please update to a Selenium version that supports CDP version 124
Apr 22, 2024 11:46:46 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 124, returning the closest version; found: 123; Please update to a Selenium version that supports CDP version 124
Apr 22, 2024 11:47:02 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 124, returning the closest version; found: 123; Please update to a Selenium version that supports CDP version 124
Apr 22, 2024 11:47:06 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 124, returning the closest version; found: 123; Please update to a Selenium version that supports CDP version 124
Apr 22, 2024 11:47:13 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 124, returning the closest version; found: 123; Please update to a Selenium version that supports CDP version 124
[ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 50.33 s <<< FAILURE! -- in TestSuite
您可能还想考虑将 slf4j 实现之一添加到您的 pom 文件中( slf4j-simple.jar 或 slf4j-log4j12.jar 或 slf4j-jdk14.jar 或 logback-classic.jar )作为依赖项,以便您开始查看日志