Skip to content

Commit 319275f

Browse files
authored
Merge pull request #356 from immutable/test/ios-build-ui
[DX-3448] test: ios ui test set up
2 parents f4e260f + c2043a8 commit 319275f

File tree

7 files changed

+77
-71
lines changed

7 files changed

+77
-71
lines changed

.github/workflows/ui-tests.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ jobs:
6969
- targetPlatform: StandaloneWindows64
7070
runs-on: [self-hosted, windows]
7171
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"
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"
7575
concurrency:
7676
group: test-${{ matrix.targetPlatform }}
7777
runs-on: ${{ matrix.runs-on }}
@@ -110,26 +110,26 @@ jobs:
110110
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
111111
working-directory: sample/Tests
112112
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.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"
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/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/src/fetch_otp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from mailslurp_client.api import WaitForControllerApi
44
import re
55

6-
INBOX_ID = "26b067b8-ef3a-4655-955a-19f157b35b6e"
7-
EMAIL = "26b067b8-ef3a-4655-955a-19f157b35b6e@mailslurp.net"
6+
INBOX_ID = "2d8e4d25-91f6-4da5-b613-bf3b807dc5d5"
7+
EMAIL = "2d8e4d25-91f6-4da5-b613-bf3b807dc5d5@mailslurp.net"
88

99
def get_mailslurp_client():
1010
configuration = mailslurp_client.Configuration()

sample/Tests/test/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from alttester import *
88

99
class TestConfig:
10-
EMAIL = "26b067b8-ef3a-4655-955a-19f157b35b6e@mailslurp.net"
11-
PASSPORT_ID="email|673d0795219c150acebff862"
12-
WALLET_ADDRESS = "0x9af9826a83581ddfa0bdd7754de8a741ce64ebe8"
10+
EMAIL = "2d8e4d25-91f6-4da5-b613-bf3b807dc5d5@mailslurp.net"
11+
PASSPORT_ID="email|673eb448219c150aceb417da"
12+
WALLET_ADDRESS = "0x2eaedd0e4c78d44fcb87d7494463360810761c3e"
1313

1414
class UnityTest(unittest.TestCase):
1515

sample/Tests/test/test_ios.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
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'))
16-
from fetch_otp import EMAIL, fetch_code
18+
from fetch_otp import fetch_code
1719

1820
# To run this test on an actual Android device: appium --base-path /wd/hub --allow-insecure chromedriver_autodownload
1921
class TestBase(unittest.TestCase):
@@ -24,9 +26,7 @@ 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"
2829
options.show_xcode_log = True
29-
options.xcode_org_id = "APPLE_TEAM_ID" # Replace with Apple Team ID
3030
options.auto_accept_alerts = True
3131

3232
cls.appium_driver = webdriver.Remote('https://hub-cloud.browserstack.com/wd/hub/', options=options)
@@ -75,14 +75,14 @@ def test_1_pkce_login(self):
7575
# Found email
7676
target_context = context
7777

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

8282
time.sleep(10) # Wait for OTP
8383

84-
code = fetch_gmail_code()
85-
assert code, "Failed to fetch OTP from Gmail"
84+
code = fetch_code()
85+
assert code, "Failed to fetch OTP from MailSlurp"
8686
print(f"Successfully fetched OTP: {code}")
8787

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

sample/build_ios.sh

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/bin/bash
22

3-
PATH_UNITY="/Applications/Unity/Unity.app/Contents/MacOS/Unity"
3+
PATH_UNITY="/Applications/Unity/Hub/Editor/2021.3.26f1/Unity.app/Contents/MacOS/Unity"
44
PATH_TO_UNITY_SDK_SAMPLE_APP="./"
55
BUILD_METHOD="MobileBuilder.BuildForAltTester"
6-
APPLE_TEAM_ID=""
6+
APPLE_TEAM_ID="54XMLXPF98"
77

88
# Define the build paths
99
BUILD_XCODE_PATH="$(pwd)/build/output/iOS/Xcode"
1010
BUILD_ARCHIVE_PATH="$(pwd)/build/output/iOS/Archive"
1111
BUILD_IPA_PATH="$(pwd)/build/output/iOS/IPA"
12+
DERIVED_DATA_PATH="$(pwd)/build/output/iOS/DerivedData"
1213

1314
# Function to clear a directory
1415
clear_directory() {
@@ -25,9 +26,15 @@ clear_directory() {
2526
clear_directory "$BUILD_XCODE_PATH"
2627
clear_directory "$BUILD_ARCHIVE_PATH"
2728
clear_directory "$BUILD_IPA_PATH"
29+
clear_directory "$DERIVED_DATA_PATH"
30+
31+
mkdir -p "$BUILD_XCODE_PATH"
32+
mkdir -p "$BUILD_ARCHIVE_PATH"
33+
mkdir -p "$BUILD_IPA_PATH"
34+
mkdir -p "$DERIVED_DATA_PATH"
2835

2936
# Unity build command
30-
UNITY_COMMAND="$PATH_UNITY -projectPath \"$PATH_TO_UNITY_SDK_SAMPLE_APP\" -executeMethod $BUILD_METHOD -logFile logFile.log -quit -batchmode --buildPath \"$BUILD_XCODE_PATH\" --platform iOS"
37+
UNITY_COMMAND="$PATH_UNITY -projectPath \"$PATH_TO_UNITY_SDK_SAMPLE_APP\" -executeMethod $BUILD_METHOD -logFile logFile.log -quit -batchmode --buildPath \"$BUILD_XCODE_PATH\" --platform iOS --bundleIdentifier com.immutable.Immutable-Sample-GameSDK"
3138
echo "Running command: $UNITY_COMMAND"
3239

3340
# Execute the Unity build command
@@ -39,39 +46,19 @@ if [ $? -ne 0 ]; then
3946
exit 1
4047
fi
4148

42-
# Build and archive project
43-
xcodebuild -project "$(pwd)/build/output/iOS/Xcode/Unity-iPhone.xcodeproj" \
49+
echo "Building app..."
50+
xcodebuild clean build \
51+
-project "$(pwd)/build/output/iOS/Xcode/Unity-iPhone.xcodeproj" \
4452
-scheme Unity-iPhone \
45-
-archivePath "$(pwd)/build/output/iOS/Archive/Unity-iPhone.xcarchive" \
46-
-configuration Release \
53+
-destination "generic/platform=iOS" \
4754
DEVELOPMENT_TEAM="$APPLE_TEAM_ID" \
48-
CODE_SIGN_STYLE=Automatic \
49-
archive
55+
-allowProvisioningUpdates \
56+
-derivedDataPath "$(pwd)/build/output/iOS/DerivedData"
57+
58+
mkdir -p "$(pwd)/build/output/iOS/IPA/Payload"
5059

51-
# Create ExportOptions.plist with the correct APPLE_TEAM_ID
52-
EXPORT_OPTIONS_PATH="$(pwd)/build/output/iOS/Archive/ExportOptions.plist"
60+
mv "$(pwd)/build/output/iOS/DerivedData/Build/Products/ReleaseForRunning-iphoneos/ImmutableSample.app" "$(pwd)/build/output/iOS/IPA/Payload"
5361

54-
cat <<EOF > "$EXPORT_OPTIONS_PATH"
55-
<?xml version="1.0" encoding="UTF-8"?>
56-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
57-
<plist version="1.0">
58-
<dict>
59-
<key>method</key>
60-
<string>development</string> <!-- Use 'ad-hoc' or 'app-store' as needed -->
61-
<key>teamID</key>
62-
<string>$APPLE_TEAM_ID</string>
63-
<key>signingStyle</key>
64-
<string>automatic</string> <!-- Use automatic signing -->
65-
<key>compileBitcode</key>
66-
<false/>
67-
<key>thinning</key>
68-
<string>&lt;none&gt;</string>
69-
</dict>
70-
</plist>
71-
EOF
62+
pushd "$(pwd)/build/output/iOS/IPA" && zip -r Payload.zip Payload && popd
7263

73-
# Generate .ipa file
74-
xcodebuild -exportArchive \
75-
-archivePath "$(pwd)/build/output/iOS/Archive/Unity-iPhone.xcarchive" \
76-
-exportPath "$(pwd)/build/output/iOS/IPA" \
77-
-exportOptionsPlist "$EXPORT_OPTIONS_PATH"
64+
mv "$(pwd)/build/output/iOS/IPA/Payload.zip" "$(pwd)/Tests/Payload.ipa"

0 commit comments

Comments
 (0)