diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index c83b1d65..aefa89f5 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -78,7 +78,7 @@ jobs: with: unityVersion: 2021.3.26f1 targetPlatform: ${{ matrix.targetPlatform }} - projectPath: './sample' + projectPath: sample - name: Deploy to GitHub Pages uses: JamesIves/github-pages-deploy-action@4.1.3 if: matrix.targetPlatform == 'WebGL' diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml index 02e55325..65f4c9c1 100644 --- a/.github/workflows/ui-tests.yml +++ b/.github/workflows/ui-tests.yml @@ -12,8 +12,18 @@ concurrency: jobs: build: - name: Build sample game for AltTester 🛠️ + name: Build ${{ matrix.targetPlatform }} for AltTester 🛠️ runs-on: ubuntu-latest-8-cores + strategy: + fail-fast: false + matrix: + include: + - targetPlatform: StandaloneOSX + buildMethod: MacBuilder.BuildForAltTester + buildPath: MacOS + - targetPlatform: StandaloneWindows64 + buildMethod: WindowsBuilder.BuildForAltTester + buildPath: Windows64 steps: - uses: actions/checkout@v3 with: @@ -21,8 +31,9 @@ jobs: - uses: actions/cache@v3 with: path: Library - key: Library-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }} + key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }} restore-keys: | + Library-${{ matrix.targetPlatform }} Library- - name: Build project uses: game-ci/unity-builder@v4 @@ -31,26 +42,38 @@ jobs: UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} with: - targetPlatform: StandaloneOSX + targetPlatform: ${{ matrix.targetPlatform }} projectPath: sample - buildMethod: MacBuilder.BuildForAltTester + buildMethod: ${{ matrix.buildMethod }} customParameters: -logFile logFile.log -quit -batchmode + - name: List build directory + run: ls -R sample/Builds/ - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: Build-StandaloneOSX - path: sample/Builds/MacOS + name: Build-${{ matrix.targetPlatform }} + path: sample/Builds/${{ matrix.buildPath }} test: - name: Run UI tests on AltTester 🧪 - runs-on: self-hosted + name: Run ${{ matrix.targetPlatform }} UI tests 🧪 needs: build + strategy: + matrix: + include: + - targetPlatform: StandaloneOSX + runs-on: [self-hosted, macOS] + test_script: test_mac.sh + - targetPlatform: StandaloneWindows64 + runs-on: [self-hosted, windows] + test_script: test_windows.ps1 + runs-on: ${{ matrix.runs-on }} steps: - uses: actions/checkout@v3 with: lfs: true - uses: actions/download-artifact@v4 with: - name: Build-StandaloneOSX + name: Build-${{ matrix.targetPlatform }} + path: sample/Tests - uses: actions/setup-python@v4 with: python-version: "3.10" @@ -58,12 +81,9 @@ jobs: run: pip install -r "sample/Tests/requirements.txt" - name: Run UI tests env: - UNITY_APP_PATH: ${{ github.workspace }}/SampleApp.app + UNITY_APP_PATH: SampleApp.app UNITY_APP_NAME: SampleApp MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }} working-directory: sample/Tests - run: | - chmod -R 755 ${{ github.workspace }}/SampleApp.app - chmod +x test_mac.sh - ./test_mac.sh + run: ./${{ matrix.test_script }} \ No newline at end of file diff --git a/sample/Assets/Editor/AndroidBuilder.cs b/sample/Assets/Editor/AndroidBuilder.cs index 3960ba2e..3b829da1 100644 --- a/sample/Assets/Editor/AndroidBuilder.cs +++ b/sample/Assets/Editor/AndroidBuilder.cs @@ -1,5 +1,3 @@ -#if UNITY_EDITOR - using UnityEngine; using UnityEditor; using UnityEditor.SceneManagement; @@ -136,5 +134,3 @@ public static void RemoveAltFromScene(string scene) } } - -#endif diff --git a/sample/Assets/Editor/WindowsBuilder.cs b/sample/Assets/Editor/WindowsBuilder.cs index 450a6023..31b2f503 100644 --- a/sample/Assets/Editor/WindowsBuilder.cs +++ b/sample/Assets/Editor/WindowsBuilder.cs @@ -1,5 +1,3 @@ -#if UNITY_EDITOR_WIN - using UnityEngine; using UnityEditor; using UnityEditor.SceneManagement; @@ -132,6 +130,4 @@ public static void RemoveAltFromScene(string scene) } } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/sample/Tests/src/device_code_login_windows.py b/sample/Tests/src/device_code_login_windows.py index 80a30b2a..74829bd7 100644 --- a/sample/Tests/src/device_code_login_windows.py +++ b/sample/Tests/src/device_code_login_windows.py @@ -6,9 +6,7 @@ from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.keys import Keys import time -from gmail_fetch_otp import fetch_gmail_code - -EMAIL = 'user-33f17f82-274b-4269-9ce6-c620e89fcd8d@mailslurp.biz' +from fetch_otp import EMAIL, fetch_code # Add chrome.exe to environment variable # Download chrome driver and add to environment variable @@ -46,7 +44,7 @@ def main(): time.sleep(10) print("Get OTP from Gmail...") - code = fetch_gmail_code() + code = fetch_code() if code: print(f"Successfully fetched OTP: {code}") else: diff --git a/sample/Tests/switch-app.ps1 b/sample/Tests/switch-app.ps1 new file mode 100644 index 00000000..0dc5acc9 --- /dev/null +++ b/sample/Tests/switch-app.ps1 @@ -0,0 +1,22 @@ +param ( + [string]$appName +) + +Add-Type @" +using System; +using System.Runtime.InteropServices; +public class User32 { + [DllImport("user32.dll")] + public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetForegroundWindow(IntPtr hWnd); +} +"@ + +$hWnd = [User32]::FindWindow([NullString]::Value, $appName) +if ($hWnd -ne [IntPtr]::Zero) { + [User32]::SetForegroundWindow($hWnd) | Out-Null +} else { + Write-Output "Window not found" +} \ No newline at end of file diff --git a/sample/Tests/test_mac.sh b/sample/Tests/test_mac.sh index eb434081..89e03bbf 100755 --- a/sample/Tests/test_mac.sh +++ b/sample/Tests/test_mac.sh @@ -56,6 +56,9 @@ app_name="${UNITY_APP_NAME:-SampleApp}" # Capture the start time start_time=$(date +%s) +# Set permissions for the app bundle +chmod -R 755 "$app_path" + echo "Starting Unity sample app..." open_sample_app "$app_path" diff --git a/sample/Tests/test_windows.ps1 b/sample/Tests/test_windows.ps1 new file mode 100644 index 00000000..e023f590 --- /dev/null +++ b/sample/Tests/test_windows.ps1 @@ -0,0 +1,154 @@ +# Function to stop the Unity sample app if it's running +function Stop-SampleApp { + $process = Get-Process -Name "SampleApp" -ErrorAction SilentlyContinue + if ($process) { + Stop-Process -Id $process.Id + Write-Output "SampleApp.exe has been closed." + } else { + Write-Output "SampleApp.exe is not running." + } + Start-Sleep -Seconds 5 +} + +# Function to start the Unity sample app +function Start-SampleApp { + Write-Output "Starting Unity sample app..." + Start-Process -FilePath "SampleApp.exe" + Start-Sleep -Seconds 10 +} + +# Function to bring the Unity sample app to the foreground +function Bring-SampleAppToForeground { + $POWERSHELL_SCRIPT_PATH = "./switch-app.ps1" + Write-Output "Bringing Unity sample app to the foreground..." + powershell.exe -Command "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process; & '$POWERSHELL_SCRIPT_PATH' -appName 'Immutable Sample'" +} + +# Function to run pytest tests +function Run-Pytest { + param ( + [string]$testFile + ) + Write-Output "Running pytest for $testFile..." + Start-Process -FilePath "pytest" -ArgumentList $testFile -NoNewWindow -PassThru | Wait-Process +} + +# Function to stop Chrome if it's running +function Stop-Chrome { + Write-Output "Stopping Chrome.." + $process = Get-Process -Name "chrome" -ErrorAction SilentlyContinue + if ($process) { + $process | ForEach-Object { + Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue + } + Write-Output "All Chrome processes have been closed." + } else { + Write-Output "Chrome is not running." + } + + Start-Sleep -Seconds 10 +} + +# Login +function Login { + param ( + [string]$testFile + ) + # Start Chrome for remote debugging + Write-Output "Starting Chrome..." + $chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe" + Start-Process -FilePath $chromePath -ArgumentList "--remote-debugging-port=9222" + + # Run Python script for login + Write-Output "Running python script to login..." + $pythonProcess = Start-Process -FilePath "python" -ArgumentList "src/device_code_login_windows.py" -NoNewWindow -PassThru + Write-Output "Python script running in the background..." + + Start-Sleep -Seconds 5 + + Bring-SampleAppToForeground + + Write-Output "Running login test..." + $pytestProcess = Start-Process -FilePath "pytest" -ArgumentList $testFile -NoNewWindow -PassThru + + $pythonProcess | Wait-Process + + Bring-SampleAppToForeground + + $pytestProcess | Wait-Process + + Stop-Chrome +} + +# Logout +function Logout { + # Start Chrome for remote debugging + Write-Output "Starting Chrome..." + $chromePath = (Get-Command chrome.exe).Source + Start-Process -FilePath $chromePath -ArgumentList "--remote-debugging-port=9222" + + Write-Output "Running python script to logout..." + $pythonProcess = Start-Process -FilePath "python" -ArgumentList "src/device_code_logout_windows.py" -NoNewWindow -PassThru + Start-Sleep -Seconds 5 + + Bring-SampleAppToForeground + + Write-Output "Running logout test..." + $pytestProcess = Start-Process -FilePath "pytest" -ArgumentList "test/test_mac_device_code_logout.py" -NoNewWindow -PassThru + + $pythonProcess | Wait-Process + + Bring-SampleAppToForeground + + $pytestProcess | Wait-Process + + Stop-Chrome +} + +# Capture the start time +$startTime = Get-Date + +# Start Unity sample app +Start-SampleApp + +# Login +Login "test/test_windows.py::WindowsTest::test_1_device_code_login" + +# Run IMX and zkEVM tests +Run-Pytest "test/test.py" + +# Relogin +Stop-SampleApp +Start-SampleApp +Run-Pytest "test/test_windows.py::WindowsTest::test_3_device_code_relogin" + +# Reconnect +Stop-SampleApp +Start-SampleApp +Run-Pytest "test/test_windows.py::WindowsTest::test_4_device_code_reconnect" + +# Logout +Logout + +# Connect IMX +Stop-SampleApp +Start-SampleApp +Write-Output "Connect to IMX..." +Login "test/test_windows.py::WindowsTest::test_2_device_code_connect_imx" + +# Bring the Unity sample app to the foreground +Bring-SampleAppToForeground + +# Logout +Logout + +# Final stop of Unity sample app +Stop-SampleApp + +# Capture the end time +$endTime = Get-Date + +# Calculate and display the elapsed time +$elapsedTime = $endTime - $startTime +Write-Output "All tests completed." +Write-Output "Elapsed time: $($elapsedTime.TotalMinutes) minutes" \ No newline at end of file