Skip to content

Commit 3aef330

Browse files
authored
Merge pull request #335 from immutable/feature/sdk-3403-windows-tests
[SDK-3403] add Windows UI tests
2 parents 493055b + 2a72552 commit 3aef330

File tree

8 files changed

+217
-28
lines changed

8 files changed

+217
-28
lines changed

.github/workflows/test-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
with:
7979
unityVersion: 2021.3.26f1
8080
targetPlatform: ${{ matrix.targetPlatform }}
81-
projectPath: './sample'
81+
projectPath: sample
8282
- name: Deploy to GitHub Pages
8383
uses: JamesIves/[email protected]
8484
if: matrix.targetPlatform == 'WebGL'

.github/workflows/ui-tests.yml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,28 @@ concurrency:
1212

1313
jobs:
1414
build:
15-
name: Build sample game for AltTester 🛠️
15+
name: Build ${{ matrix.targetPlatform }} for AltTester 🛠️
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+
buildPath: MacOS
24+
- targetPlatform: StandaloneWindows64
25+
buildMethod: WindowsBuilder.BuildForAltTester
26+
buildPath: Windows64
1727
steps:
1828
- uses: actions/checkout@v3
1929
with:
2030
lfs: true
2131
- uses: actions/cache@v3
2232
with:
2333
path: Library
24-
key: Library-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }}
34+
key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }}
2535
restore-keys: |
36+
Library-${{ matrix.targetPlatform }}
2637
Library-
2738
- name: Build project
2839
uses: game-ci/unity-builder@v4
@@ -31,39 +42,48 @@ jobs:
3142
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
3243
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
3344
with:
34-
targetPlatform: StandaloneOSX
45+
targetPlatform: ${{ matrix.targetPlatform }}
3546
projectPath: sample
36-
buildMethod: MacBuilder.BuildForAltTester
47+
buildMethod: ${{ matrix.buildMethod }}
3748
customParameters: -logFile logFile.log -quit -batchmode
49+
- name: List build directory
50+
run: ls -R sample/Builds/
3851
- name: Upload artifact
3952
uses: actions/upload-artifact@v4
4053
with:
41-
name: Build-StandaloneOSX
42-
path: sample/Builds/MacOS
54+
name: Build-${{ matrix.targetPlatform }}
55+
path: sample/Builds/${{ matrix.buildPath }}
4356
test:
44-
name: Run UI tests on AltTester 🧪
45-
runs-on: self-hosted
57+
name: Run ${{ matrix.targetPlatform }} UI tests 🧪
4658
needs: build
59+
strategy:
60+
matrix:
61+
include:
62+
- targetPlatform: StandaloneOSX
63+
runs-on: [self-hosted, macOS]
64+
test_script: test_mac.sh
65+
- targetPlatform: StandaloneWindows64
66+
runs-on: [self-hosted, windows]
67+
test_script: test_windows.ps1
68+
runs-on: ${{ matrix.runs-on }}
4769
steps:
4870
- uses: actions/checkout@v3
4971
with:
5072
lfs: true
5173
- uses: actions/download-artifact@v4
5274
with:
53-
name: Build-StandaloneOSX
75+
name: Build-${{ matrix.targetPlatform }}
76+
path: sample/Tests
5477
- uses: actions/setup-python@v4
5578
with:
5679
python-version: "3.10"
5780
- name: Install dependencies
5881
run: pip install -r "sample/Tests/requirements.txt"
5982
- name: Run UI tests
6083
env:
61-
UNITY_APP_PATH: ${{ github.workspace }}/SampleApp.app
84+
UNITY_APP_PATH: SampleApp.app
6285
UNITY_APP_NAME: SampleApp
6386
MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
6487
working-directory: sample/Tests
65-
run: |
66-
chmod -R 755 ${{ github.workspace }}/SampleApp.app
67-
chmod +x test_mac.sh
68-
./test_mac.sh
88+
run: ./${{ matrix.test_script }}
6989

sample/Assets/Editor/AndroidBuilder.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#if UNITY_EDITOR
2-
31
using UnityEngine;
42
using UnityEditor;
53
using UnityEditor.SceneManagement;
@@ -136,5 +134,3 @@ public static void RemoveAltFromScene(string scene)
136134
}
137135

138136
}
139-
140-
#endif

sample/Assets/Editor/WindowsBuilder.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#if UNITY_EDITOR_WIN
2-
31
using UnityEngine;
42
using UnityEditor;
53
using UnityEditor.SceneManagement;
@@ -132,6 +130,4 @@ public static void RemoveAltFromScene(string scene)
132130
}
133131
}
134132

135-
}
136-
137-
#endif
133+
}

sample/Tests/src/device_code_login_windows.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
from selenium.webdriver.support import expected_conditions as EC
77
from selenium.webdriver.common.keys import Keys
88
import time
9-
from gmail_fetch_otp import fetch_gmail_code
10-
11-
9+
from fetch_otp import EMAIL, fetch_code
1210

1311
# Add chrome.exe to environment variable
1412
# Download chrome driver and add to environment variable
@@ -46,7 +44,7 @@ def main():
4644
time.sleep(10)
4745

4846
print("Get OTP from Gmail...")
49-
code = fetch_gmail_code()
47+
code = fetch_code()
5048
if code:
5149
print(f"Successfully fetched OTP: {code}")
5250
else:

sample/Tests/switch-app.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
param (
2+
[string]$appName
3+
)
4+
5+
Add-Type @"
6+
using System;
7+
using System.Runtime.InteropServices;
8+
public class User32 {
9+
[DllImport("user32.dll")]
10+
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
11+
[DllImport("user32.dll")]
12+
[return: MarshalAs(UnmanagedType.Bool)]
13+
public static extern bool SetForegroundWindow(IntPtr hWnd);
14+
}
15+
"@
16+
17+
$hWnd = [User32]::FindWindow([NullString]::Value, $appName)
18+
if ($hWnd -ne [IntPtr]::Zero) {
19+
[User32]::SetForegroundWindow($hWnd) | Out-Null
20+
} else {
21+
Write-Output "Window not found"
22+
}

sample/Tests/test_mac.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ app_name="${UNITY_APP_NAME:-SampleApp}"
5656
# Capture the start time
5757
start_time=$(date +%s)
5858

59+
# Set permissions for the app bundle
60+
chmod -R 755 "$app_path"
61+
5962
echo "Starting Unity sample app..."
6063
open_sample_app "$app_path"
6164

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 "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 = "C:\Program Files\Google\Chrome\Application\chrome.exe"
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)