Skip to content

Commit e3423f0

Browse files
committed
test: fix ios build and ui test script
1 parent 8e58151 commit e3423f0

File tree

6 files changed

+197
-151
lines changed

6 files changed

+197
-151
lines changed

.github/workflows/ui-tests.yml

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -11,125 +11,125 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14-
build:
15-
name: Build ${{ matrix.targetPlatform }} for AltTester 🛠️
16-
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: sample/Builds/MacOS
24-
- targetPlatform: StandaloneWindows64
25-
buildMethod: WindowsBuilder.BuildForAltTester
26-
buildPath: sample/Builds/Windows64
27-
- targetPlatform: Android
28-
buildMethod: MobileBuilder.BuildForAltTester
29-
buildPath: sample/Builds/Android
30-
steps:
31-
- uses: actions/checkout@v3
32-
with:
33-
lfs: true
34-
- uses: actions/cache@v3
35-
with:
36-
path: Library
37-
key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }}
38-
restore-keys: |
39-
Library-${{ matrix.targetPlatform }}
40-
Library-
41-
- name: Build project
42-
uses: game-ci/unity-builder@v4
43-
env:
44-
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
45-
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
46-
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
47-
with:
48-
targetPlatform: ${{ matrix.targetPlatform }}
49-
projectPath: sample
50-
buildMethod: ${{ matrix.buildMethod }}
51-
customParameters: -logFile logFile.log -quit -batchmode
52-
- name: List build directory
53-
run: ls -R ./
54-
- name: Upload artifact
55-
uses: actions/upload-artifact@v4
56-
if: always()
57-
with:
58-
name: Build-${{ matrix.targetPlatform }}
59-
path: ${{ matrix.buildPath }}
60-
test:
61-
name: Run ${{ matrix.targetPlatform }} UI tests 🧪
62-
needs: build
63-
strategy:
64-
matrix:
65-
include:
66-
- targetPlatform: StandaloneOSX
67-
runs-on: [self-hosted, macOS]
68-
test_script: pytest -xs test/test_mac.py::MacTest
69-
- targetPlatform: StandaloneWindows64
70-
runs-on: [self-hosted, windows]
71-
test_script: pytest -xs test/test_windows.py::WindowsTest
14+
# build:
15+
# name: Build ${{ matrix.targetPlatform }} for AltTester 🛠️
16+
# 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: sample/Builds/MacOS
24+
# - targetPlatform: StandaloneWindows64
25+
# buildMethod: WindowsBuilder.BuildForAltTester
26+
# buildPath: sample/Builds/Windows64
7227
# - targetPlatform: Android
73-
# runs-on: [ self-hosted, macOS ]
74-
# test_script: browserstack-sdk pytest -s ./test/test_android.py --browserstack.config "browserstack.android.yml"
75-
concurrency:
76-
group: test-${{ matrix.targetPlatform }}
77-
runs-on: ${{ matrix.runs-on }}
78-
steps:
79-
- uses: actions/checkout@v3
80-
with:
81-
lfs: true
82-
- uses: actions/download-artifact@v4
83-
with:
84-
name: Build-${{ matrix.targetPlatform }}
85-
path: sample/Tests
86-
- name: Make macOS artifact executable
87-
if: ${{ matrix.targetPlatform == 'StandaloneOSX' }}
88-
run: chmod +x sample/Tests/SampleApp.app/Contents/MacOS/*
89-
- uses: actions/setup-python@v4
90-
with:
91-
python-version: "3.10"
92-
- name: Install dependencies (Windows)
93-
if: ${{ matrix.targetPlatform == 'StandaloneWindows64' }}
94-
run: pip install -r "sample/Tests/requirements-desktop.txt"
95-
- name: Install dependencies (Mac)
96-
if: ${{ matrix.targetPlatform != 'StandaloneWindows64' }}
97-
run: |
98-
if [[ "${{ matrix.targetPlatform }}" == "StandaloneOSX" ]]; then
99-
pip uninstall -y browserstack-sdk || true
100-
pip install -r "sample/Tests/requirements-desktop.txt"
101-
else
102-
pip install -r "sample/Tests/requirements-mobile.txt"
103-
fi
104-
- name: Run UI tests
105-
env:
106-
UNITY_APP_PATH: SampleApp.app
107-
UNITY_APP_NAME: SampleApp
108-
MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
109-
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
110-
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
111-
working-directory: sample/Tests
112-
run: ${{ matrix.test_script }}
113-
# test-ios:
114-
# name: Run iOS UI tests 🧪
115-
# runs-on: [ self-hosted, macOS ]
28+
# buildMethod: MobileBuilder.BuildForAltTester
29+
# buildPath: sample/Builds/Android
30+
# steps:
31+
# - uses: actions/checkout@v3
32+
# with:
33+
# lfs: true
34+
# - uses: actions/cache@v3
35+
# with:
36+
# path: Library
37+
# key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('sample/Assets/**', 'sample/Packages/**', 'sample/ProjectSettings/**') }}
38+
# restore-keys: |
39+
# Library-${{ matrix.targetPlatform }}
40+
# Library-
41+
# - name: Build project
42+
# uses: game-ci/unity-builder@v4
43+
# env:
44+
# UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
45+
# UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
46+
# UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
47+
# with:
48+
# targetPlatform: ${{ matrix.targetPlatform }}
49+
# projectPath: sample
50+
# buildMethod: ${{ matrix.buildMethod }}
51+
# customParameters: -logFile logFile.log -quit -batchmode
52+
# - name: List build directory
53+
# run: ls -R ./
54+
# - name: Upload artifact
55+
# uses: actions/upload-artifact@v4
56+
# if: always()
57+
# with:
58+
# name: Build-${{ matrix.targetPlatform }}
59+
# path: ${{ matrix.buildPath }}
60+
# test:
61+
# name: Run ${{ matrix.targetPlatform }} UI tests 🧪
62+
# needs: build
63+
# strategy:
64+
# matrix:
65+
# include:
66+
# # - targetPlatform: StandaloneOSX
67+
# # runs-on: [self-hosted, macOS]
68+
# # test_script: pytest -xs test/test_mac.py::MacTest
69+
# # - targetPlatform: StandaloneWindows64
70+
# # runs-on: [self-hosted, windows]
71+
# # test_script: pytest -xs test/test_windows.py::WindowsTest
72+
# # - targetPlatform: Android
73+
# # runs-on: [ self-hosted, macOS ]
74+
# # test_script: browserstack-sdk pytest -s ./test/test_android.py --browserstack.config "browserstack.android.yml"
75+
# concurrency:
76+
# group: test-${{ matrix.targetPlatform }}
77+
# runs-on: ${{ matrix.runs-on }}
11678
# steps:
11779
# - uses: actions/checkout@v3
11880
# with:
11981
# lfs: true
120-
# - name: build iOS app
121-
# working-directory: sample
122-
# run: ./build_ios.sh
82+
# - uses: actions/download-artifact@v4
83+
# with:
84+
# name: Build-${{ matrix.targetPlatform }}
85+
# path: sample/Tests
86+
# - name: Make macOS artifact executable
87+
# if: ${{ matrix.targetPlatform == 'StandaloneOSX' }}
88+
# run: chmod +x sample/Tests/SampleApp.app/Contents/MacOS/*
12389
# - uses: actions/setup-python@v4
12490
# with:
12591
# python-version: "3.10"
126-
# - name: Install dependencies
127-
# run: pip install -r "sample/Tests/requirements.txt"
92+
# - name: Install dependencies (Windows)
93+
# if: ${{ matrix.targetPlatform == 'StandaloneWindows64' }}
94+
# run: pip install -r "sample/Tests/requirements-desktop.txt"
95+
# - name: Install dependencies (Mac)
96+
# if: ${{ matrix.targetPlatform != 'StandaloneWindows64' }}
97+
# run: |
98+
# if [[ "${{ matrix.targetPlatform }}" == "StandaloneOSX" ]]; then
99+
# pip uninstall -y browserstack-sdk || true
100+
# pip install -r "sample/Tests/requirements-desktop.txt"
101+
# else
102+
# pip install -r "sample/Tests/requirements-mobile.txt"
103+
# fi
128104
# - name: Run UI tests
129105
# env:
106+
# UNITY_APP_PATH: SampleApp.app
107+
# UNITY_APP_NAME: SampleApp
130108
# MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
131109
# BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
132110
# BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
133111
# working-directory: sample/Tests
134-
# run: browserstack-sdk pytest -s ./test/test_ios.py --browserstack.config "browserstack.ios.yml"
112+
# run: ${{ matrix.test_script }}
113+
test-ios:
114+
name: Run iOS UI tests 🧪
115+
runs-on: [ self-hosted, macOS ]
116+
steps:
117+
- uses: actions/checkout@v3
118+
with:
119+
lfs: true
120+
- name: Build iOS app
121+
working-directory: sample
122+
run: ./build_ios.sh
123+
- uses: actions/setup-python@v4
124+
with:
125+
python-version: "3.10"
126+
- name: Install dependencies
127+
run: pip install -r "sample/Tests/requirements-mobile.txt"
128+
- name: Run UI tests
129+
env:
130+
MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
131+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
132+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
133+
working-directory: sample/Tests
134+
run: browserstack-sdk pytest -s ./test/test_ios.py --browserstack.config "browserstack.ios.yml"
135135

sample/Assets/Editor/MobileBuilder.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ private static void BuildPlayer(string defaultBuildPath, BuildOptions buildOptio
3131
{
3232
string buildPath = GetBuildPathFromArgs(defaultBuildPath);
3333

34+
if (platform == BuildTarget.iOS)
35+
{
36+
string bundleIdentifier = GetBundleIdentifierFromArgs();
37+
PlayerSettings.applicationIdentifier = bundleIdentifier;
38+
}
39+
3440
BuildPlayerOptions buildPlayerOptions = CreateBuildPlayerOptions(buildPath, buildOptions, platform);
3541

3642
if (setupForAltTester)
@@ -79,6 +85,19 @@ private static BuildTarget GetPlatformFromArgs()
7985
return BuildTarget.Android; // Default to Android if no platform is specified
8086
}
8187

88+
private static string GetBundleIdentifierFromArgs()
89+
{
90+
string[] args = Environment.GetCommandLineArgs();
91+
for (int i = 0; i < args.Length; i++)
92+
{
93+
if (args[i] == "--bundleIdentifier" && i + 1 < args.Length)
94+
{
95+
return args[i + 1];
96+
}
97+
}
98+
return "com.immutable.Immutable-Sample";
99+
}
100+
82101
private static string GetAltTesterHostFromArgs()
83102
{
84103
string[] args = Environment.GetCommandLineArgs();

sample/ProjectSettings/ProjectSettings.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ PlayerSettings:
157157
applicationIdentifier:
158158
Android: com.immutable.ImmutableSample
159159
Standalone: com.immutable.unitysample
160-
iPhone: com.immutable.Immutable-Sample
160+
iPhone: com.immutable.Immutable-Sample-GameSDK
161161
buildNumber:
162162
Standalone: 0
163163
VisionOS: 0
164164
iPhone: 0
165165
tvOS: 0
166-
overrideDefaultApplicationIdentifier: 0
166+
overrideDefaultApplicationIdentifier: 1
167167
AndroidBundleVersionCode: 1
168168
AndroidMinSdkVersion: 26
169169
AndroidTargetSdkVersion: 33

sample/Tests/browserstack.ios.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ source: pytest-browserstack:sample-sdk:v1.0
2626
# Set `app` to define the app that is to be used for testing.
2727
# It can either take the id of any uploaded app or the path of the app directly.
2828
#app: ./WikipediaSample.apk
29-
app: ../build/output/iOS/IPA/Payload.ipa #For running local tests
29+
app: ./Payload.ipa #For running local tests
3030

3131
# =======================================
3232
# Platforms (Browsers / Devices to test)

sample/Tests/test/test_ios.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
from alttester import AltDriver, By
1414

15+
from test import TestConfig
16+
1517
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'src'))
1618
from fetch_otp import EMAIL, fetch_code
1719

@@ -24,9 +26,10 @@ class TestBase(unittest.TestCase):
2426
def setUpClass(cls):
2527
# https://appium.github.io/appium-xcuitest-driver/latest/preparation/real-device-config/
2628
options = XCUITestOptions()
27-
options.app = "./Payload.ipa"
29+
# options.app = "./Payload.ipa"
30+
# options.app = "com.immutable.Immutable-Sample-GameSDK"
2831
options.show_xcode_log = True
29-
options.xcode_org_id = "APPLE_TEAM_ID" # Replace with Apple Team ID
32+
# options.xcode_org_id = "54XMLXPF98" # Replace with Apple Team ID
3033
options.auto_accept_alerts = True
3134

3235
cls.appium_driver = webdriver.Remote('https://hub-cloud.browserstack.com/wd/hub/', options=options)
@@ -75,14 +78,14 @@ def test_1_pkce_login(self):
7578
# Found email
7679
target_context = context
7780

78-
email_field.send_keys("[email protected]")
81+
email_field.send_keys(TestConfig.EMAIL)
7982
submit_button = driver.find_element(by=AppiumBy.XPATH, value="//form/div/div/div[2]/button")
8083
submit_button.click()
8184

8285
time.sleep(10) # Wait for OTP
8386

8487
code = fetch_gmail_code()
85-
assert code, "Failed to fetch OTP from Gmail"
88+
assert code, "Failed to fetch OTP from MailSlurp"
8689
print(f"Successfully fetched OTP: {code}")
8790

8891
# Unlike on Android, each digit must be entered into a separate input field on iOS.

0 commit comments

Comments
 (0)