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