我的 Java 桌面应用程序有一些基本的自动化 GUI 测试,这些测试可以在 Windows 桌面上运行。在 GitHub 上他们失败了
X11GraphicsEnvironment.java 处的 java.awt.AWTError:-2
我从默认的
Java CI with Gradle
工作流程开始,并添加了一些尝试设置 xvfb 的步骤,以便它有一个可以使用的显示器,但它仍然失败。有没有办法修改工作流程以便 X11 可用于测试?
name: Java CI with Gradle
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Set up virtual X11
run: sudo apt-get install xvfb
- name: Start virtual frame buffer
run: Xvfb :19 -screen 0 1024x768x16 &
- name: set display
run: export DISPLAY=:19
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
我最终使用 JUnit
@Tag
s 拆分 GUI 测试,然后添加单独的 gradle 任务:
task nonGuiTest(type: Test) {
useJUnitPlatform {
excludeTags 'gui'
}
}
task guiTest(type: Test) {
useJUnitPlatform {
includeTags 'gui'
}
}
然后在工作流程中
build -x test
GabrielBB/xvfb-action@v1
操作来设置 xvfbname: Java CI with Gradle
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: headless tests
run: ./gradlew nonGuiTest
- name: GUI tests
uses: GabrielBB/xvfb-action@v1
with:
run: ./gradlew guiTest
我将以下内容添加到需要 GUI 来运行测试的步骤中:
uses: coactions/[email protected]
with:
run: ...