Skip to content

Commit 826663f

Browse files
authored
NewsReader/UITest: Simplify local dev support (#92)
* NR/UITest: For local Android dev use release folder and build sets env variable for the APK * Build: Simplify yml file
1 parent 0f8dfb7 commit 826663f

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

.github/workflows/NewsReader.UITestAndroid.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
types:
77
- completed
88

9-
# Allows you to run this workflow manually from the Actions tab
109
workflow_dispatch:
1110

1211
jobs:
@@ -37,10 +36,6 @@ jobs:
3736
run: |
3837
gh run download ${{ steps.get_run.outputs.run_id }} --name="NewsReaderAndroid" --dir=./NewsReaderAndroid
3938
40-
- shell: bash
41-
run: |
42-
ls ./NewsReaderAndroid
43-
4439
- name: ⚙️ Enable KVM
4540
run: |
4641
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
@@ -64,10 +59,6 @@ jobs:
6459
emulator -avd test_emulator -no-audio -no-boot-anim -no-window -no-snapshot &
6560
adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
6661
67-
- name: ⚙️ List Android Devices
68-
run: |
69-
$ANDROID_SDK_ROOT/platform-tools/adb devices
70-
7162
- name: ⚙️ Install Appium Server
7263
run: |
7364
npm install appium -g
@@ -80,7 +71,7 @@ jobs:
8071
- name: 🖥️ UI Test
8172
run: |
8273
echo "## 🕵️ Test Results - NewsReader.UITest.sln" >> $Env:GITHUB_STEP_SUMMARY
83-
dotnet test ./src/NewsReader.UITest/NewsReader.UITest.sln --filter DevicePlatform=Android --logger GitHubActions
74+
dotnet test ./src/NewsReader.UITest/NewsReader.UITest.sln --filter DevicePlatform=Android --logger GitHubActions -e UITestApkFile=NewsReaderAndroid/src/NewsReader/NewsReader.MauiSystem/bin/Release/net9.0-android/publish/Waf.NewsReader-Signed.apk
8475
8576
- name: 📦 Upload UI Test results
8677
uses: actions/upload-artifact@v4

src/NewsReader.UITest/NewsReader.UITest/UITest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace UITest.NewsReader;
44

5-
public class UITest() : UITestBase("Waf.NewsReader",
6-
androidApkFile: "NewsReaderAndroid/src/NewsReader/NewsReader.MauiSystem/bin/Release/net9.0-android/publish/Waf.NewsReader-Signed.apk",
5+
public class UITest() : UITestBase("Waf.NewsReader",
6+
androidApkFile: Environment.GetEnvironmentVariable("UITestApkFile") ?? "src/NewsReader/NewsReader.MauiSystem/bin/Release/net9.0-android/Waf.NewsReader-Signed.apk",
77
androidAppActivity: "Waf.NewsReader.MainActivity",
88
windowsAppId: "Waf.NewsReader_a8txtqew917ny!App",
99
Environment.GetEnvironmentVariable("UITestOutputPath") ?? "out/NewsReader.UITest/")

src/NewsReader.UITest/UITest.Core/UITestBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public abstract class UITestBase : IDisposable
1212
private readonly string appId;
1313
private readonly string app;
1414
private readonly string androidAppActivity;
15+
private readonly string rootPath;
1516
private readonly string testOutPath;
1617

1718
protected UITestBase(string appId, string androidApkFile, string androidAppActivity, string windowsAppId, string testOutputPath)
@@ -21,7 +22,7 @@ protected UITestBase(string appId, string androidApkFile, string androidAppActiv
2122
this.appId = appId;
2223
this.androidAppActivity = androidAppActivity;
2324
var assemblyPath = Assembly.GetAssembly(typeof(UITestBase))!.Location;
24-
var rootPath = Path.GetFullPath(Path.Combine(assemblyPath, "../../../../../../../"));
25+
rootPath = Path.GetFullPath(Path.Combine(assemblyPath, "../../../../../../../"));
2526
testOutPath = Path.GetFullPath(Path.IsPathFullyQualified(testOutputPath) ? testOutputPath : Path.Combine(rootPath, testOutputPath));
2627
Directory.CreateDirectory(testOutPath);
2728
app = devicePlatform switch
@@ -59,12 +60,14 @@ protected UITestBase(string appId, string androidApkFile, string androidAppActiv
5960

6061
private AndroidDriver SetupAndroid(Uri serverUri)
6162
{
63+
var apk = Path.GetFullPath(Path.IsPathFullyQualified(app) ? app : Path.Combine(rootPath, app));
64+
6265
// See: https://github.com/appium/appium-uiautomator2-driver
6366
var driverOptions = new AppiumOptions()
6467
{
6568
AutomationName = AutomationName.AndroidUIAutomator2,
6669
PlatformName = MobilePlatform.Android,
67-
App = app,
70+
App = apk,
6871
};
6972
// TODO: Use this instead of App for local dev
7073
//driverOptions.AddAdditionalAppiumOption("appPackage", appId);

0 commit comments

Comments
 (0)