Skip to content

Commit 9300646

Browse files
committed
feat: add windows UI tests
1 parent 493055b commit 9300646

File tree

2 files changed

+184
-10
lines changed

2 files changed

+184
-10
lines changed

.github/workflows/ui-tests.yml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@ concurrency:
1212

1313
jobs:
1414
build:
15-
name: Build sample game for AltTester 🛠️
15+
name: Build sample game for AltTester ${{ matrix.targetPlatform }} 🛠️
1616
runs-on: ubuntu-latest-8-cores
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- targetPlatform: StandaloneOSX
22+
buildMethod: MacBuilder.BuildForAltTester
23+
- targetPlatform: StandaloneWindows64
24+
buildMethod: WindowsBuilder.BuildForAltTester
1725
steps:
1826
- uses: actions/checkout@v3
1927
with:
2028
lfs: true
2129
- uses: actions/cache@v3
2230
with:
2331
path: Library
24-
key: Library-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }}
32+
key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }}
2533
restore-keys: |
34+
Library-${{ matrix.targetPlatform }}
2635
Library-
2736
- name: Build project
2837
uses: game-ci/unity-builder@v4
@@ -31,26 +40,37 @@ jobs:
3140
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
3241
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
3342
with:
34-
targetPlatform: StandaloneOSX
43+
targetPlatform: ${{ matrix.targetPlatform }}
3544
projectPath: sample
36-
buildMethod: MacBuilder.BuildForAltTester
45+
buildMethod: ${{ matrix.buildMethod }}
3746
customParameters: -logFile logFile.log -quit -batchmode
3847
- name: Upload artifact
3948
uses: actions/upload-artifact@v4
4049
with:
41-
name: Build-StandaloneOSX
42-
path: sample/Builds/MacOS
50+
name: Build-${{ matrix.targetPlatform }}
51+
path: build
4352
test:
4453
name: Run UI tests on AltTester 🧪
45-
runs-on: self-hosted
4654
needs: build
55+
strategy:
56+
matrix:
57+
include:
58+
- targetPlatform: StandaloneOSX
59+
runs-on: [self-hosted, macOS]
60+
artifact: Build-StandaloneOSX
61+
test_script: test_mac.sh
62+
- targetPlatform: StandaloneWindows64
63+
runs-on: [self-hosted, windows]
64+
artifact: Build-StandaloneWindows64
65+
test_script: test_windows.ps1
66+
runs-on: ${{ matrix.runs-on }}
4767
steps:
4868
- uses: actions/checkout@v3
4969
with:
5070
lfs: true
5171
- uses: actions/download-artifact@v4
5272
with:
53-
name: Build-StandaloneOSX
73+
name: ${{ matrix.artifact }}
5474
- uses: actions/setup-python@v4
5575
with:
5676
python-version: "3.10"
@@ -64,6 +84,6 @@ jobs:
6484
working-directory: sample/Tests
6585
run: |
6686
chmod -R 755 ${{ github.workspace }}/SampleApp.app
67-
chmod +x test_mac.sh
68-
./test_mac.sh
87+
chmod +x ${{ matrix.test_script }}
88+
./${{ matrix.test_script }}
6989

sample/Tests/test_windows.ps1

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Function to stop the Unity sample app if it's running
2+
function Stop-SampleApp {
3+
$process = Get-Process -Name "SampleApp" -ErrorAction SilentlyContinue
4+
if ($process) {
5+
Stop-Process -Id $process.Id
6+
Write-Output "SampleApp.exe has been closed."
7+
} else {
8+
Write-Output "SampleApp.exe is not running."
9+
}
10+
Start-Sleep -Seconds 5
11+
}
12+
13+
# Function to start the Unity sample app
14+
function Start-SampleApp {
15+
Write-Output "Starting Unity sample app..."
16+
Start-Process -FilePath "build\output\Windows64\SampleApp.exe"
17+
Start-Sleep -Seconds 10
18+
}
19+
20+
# Function to bring the Unity sample app to the foreground
21+
function Bring-SampleAppToForeground {
22+
$POWERSHELL_SCRIPT_PATH = "./switch-app.ps1"
23+
Write-Output "Bringing Unity sample app to the foreground..."
24+
powershell.exe -Command "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process; & '$POWERSHELL_SCRIPT_PATH' -appName 'Immutable Sample'"
25+
}
26+
27+
# Function to run pytest tests
28+
function Run-Pytest {
29+
param (
30+
[string]$testFile
31+
)
32+
Write-Output "Running pytest for $testFile..."
33+
Start-Process -FilePath "pytest" -ArgumentList $testFile -NoNewWindow -PassThru | Wait-Process
34+
}
35+
36+
# Function to stop Chrome if it's running
37+
function Stop-Chrome {
38+
Write-Output "Stopping Chrome.."
39+
$process = Get-Process -Name "chrome" -ErrorAction SilentlyContinue
40+
if ($process) {
41+
$process | ForEach-Object {
42+
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
43+
}
44+
Write-Output "All Chrome processes have been closed."
45+
} else {
46+
Write-Output "Chrome is not running."
47+
}
48+
49+
Start-Sleep -Seconds 10
50+
}
51+
52+
# Login
53+
function Login {
54+
param (
55+
[string]$testFile
56+
)
57+
# Start Chrome for remote debugging
58+
Write-Output "Starting Chrome..."
59+
$chromePath = (Get-Command chrome.exe).Source
60+
Start-Process -FilePath $chromePath -ArgumentList "--remote-debugging-port=9222"
61+
62+
# Run Python script for login
63+
Write-Output "Running python script to login..."
64+
$pythonProcess = Start-Process -FilePath "python" -ArgumentList "src/device_code_login_windows.py" -NoNewWindow -PassThru
65+
Write-Output "Python script running in the background..."
66+
67+
Start-Sleep -Seconds 5
68+
69+
Bring-SampleAppToForeground
70+
71+
Write-Output "Running login test..."
72+
$pytestProcess = Start-Process -FilePath "pytest" -ArgumentList $testFile -NoNewWindow -PassThru
73+
74+
$pythonProcess | Wait-Process
75+
76+
Bring-SampleAppToForeground
77+
78+
$pytestProcess | Wait-Process
79+
80+
Stop-Chrome
81+
}
82+
83+
# Logout
84+
function Logout {
85+
# Start Chrome for remote debugging
86+
Write-Output "Starting Chrome..."
87+
$chromePath = (Get-Command chrome.exe).Source
88+
Start-Process -FilePath $chromePath -ArgumentList "--remote-debugging-port=9222"
89+
90+
Write-Output "Running python script to logout..."
91+
$pythonProcess = Start-Process -FilePath "python" -ArgumentList "src/device_code_logout_windows.py" -NoNewWindow -PassThru
92+
Start-Sleep -Seconds 5
93+
94+
Bring-SampleAppToForeground
95+
96+
Write-Output "Running logout test..."
97+
$pytestProcess = Start-Process -FilePath "pytest" -ArgumentList "test/test_mac_device_code_logout.py" -NoNewWindow -PassThru
98+
99+
$pythonProcess | Wait-Process
100+
101+
Bring-SampleAppToForeground
102+
103+
$pytestProcess | Wait-Process
104+
105+
Stop-Chrome
106+
}
107+
108+
# Capture the start time
109+
$startTime = Get-Date
110+
111+
# Start Unity sample app
112+
Start-SampleApp
113+
114+
# Login
115+
Login "test/test_windows.py::WindowsTest::test_1_device_code_login"
116+
117+
# Run IMX and zkEVM tests
118+
Run-Pytest "test/test.py"
119+
120+
# Relogin
121+
Stop-SampleApp
122+
Start-SampleApp
123+
Run-Pytest "test/test_windows.py::WindowsTest::test_3_device_code_relogin"
124+
125+
# Reconnect
126+
Stop-SampleApp
127+
Start-SampleApp
128+
Run-Pytest "test/test_windows.py::WindowsTest::test_4_device_code_reconnect"
129+
130+
# Logout
131+
Logout
132+
133+
# Connect IMX
134+
Stop-SampleApp
135+
Start-SampleApp
136+
Write-Output "Connect to IMX..."
137+
Login "test/test_windows.py::WindowsTest::test_2_device_code_connect_imx"
138+
139+
# Bring the Unity sample app to the foreground
140+
Bring-SampleAppToForeground
141+
142+
# Logout
143+
Logout
144+
145+
# Final stop of Unity sample app
146+
Stop-SampleApp
147+
148+
# Capture the end time
149+
$endTime = Get-Date
150+
151+
# Calculate and display the elapsed time
152+
$elapsedTime = $endTime - $startTime
153+
Write-Output "All tests completed."
154+
Write-Output "Elapsed time: $($elapsedTime.TotalMinutes) minutes"

0 commit comments

Comments
 (0)