From e7f369e2784f1f6b18cacd5848a5d791c72190a3 Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Wed, 21 Feb 2024 13:51:38 +0100 Subject: [PATCH] Refine instructions --- 8.0/UITesting/BasicAppiumNunitSample/README.md | 8 +++++++- .../BasicAppiumNunitSample/UITests.Android/AppiumSetup.cs | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/8.0/UITesting/BasicAppiumNunitSample/README.md b/8.0/UITesting/BasicAppiumNunitSample/README.md index e8371da1a..0334479cd 100644 --- a/8.0/UITesting/BasicAppiumNunitSample/README.md +++ b/8.0/UITesting/BasicAppiumNunitSample/README.md @@ -111,7 +111,7 @@ Each method is adorned with a `[Test]` attribute. This marks the method as a tes Tests can be ran from the Visual Studio Test Explorer or by running `dotnet test` from the command-line. -To run the tests, an Appium server needs to be available and running, and that in turn should be able to reach the emulators, Simulator or physical devices as needed. +To run the tests, an Appium server needs to be available and running, and that in turn should be able to reach the emulators, Simulator or physical devices as needed. For Android, make sure to either specify the emulator to be used in the configuration, or have an emulator already running/device already connected. If no emulator/device is detected, the tests will not run and throw an exception specifying that no connected Android device could be found. > [!NOTE] > For all platforms apart from macOS, you typically want to have your app deployed on the device that you want to test on. Make sure you have the latest app version is deployed to your device. Tests will be ran against that app. The way this sample is set up, it will **not** deploy the app for you as part of the test run. @@ -121,3 +121,9 @@ This sample does automatically start and stop the Appium server for you as part If you want to start the Appium server manually, go into each `AppiumSetup.cs` file in each of the platform projects and comment out the lines that call `AppiumServerHelper`. There are two: one to start the server and one to stop it. You will have to make sure the Appium server is started before running the tests and optionally configure the Appium drivers used in code to be able to reach your own server. + +### Android Debug vs Release Build + +On Android there is the concept of [Fast Deployment](https://learn.microsoft.com/xamarin/android/deploy-test/building-apps/build-process#fast-deployment) and because of that needs some special configuration when running with Appium. + +In the `AppiumSetup.cs` of the `UITest.Android` project there are inline comments with instructions. However, this part of the configuration is very much dependent on how you setup your testing. If you use a Debug configuration build, evertyhing is setup as it should. When you want to test your resulting apk/aab binary file (or the Release configuration build), you will want to comment out the Debug configuration code and uncomment the Release configuration code and make sure the path to your app binary is correct. diff --git a/8.0/UITesting/BasicAppiumNunitSample/UITests.Android/AppiumSetup.cs b/8.0/UITesting/BasicAppiumNunitSample/UITests.Android/AppiumSetup.cs index 067add426..737dfb273 100644 --- a/8.0/UITesting/BasicAppiumNunitSample/UITests.Android/AppiumSetup.cs +++ b/8.0/UITesting/BasicAppiumNunitSample/UITests.Android/AppiumSetup.cs @@ -20,7 +20,6 @@ public void RunBeforeAnyTests() // This line starts a local Appium server for you as part of the test run AppiumServerHelper.StartAppiumLocalServer(); - var androidOptions = new AppiumOptions { // Specify UIAutomator2 as the driver, typically don't need to change this @@ -28,11 +27,12 @@ public void RunBeforeAnyTests() // Always Android for Android PlatformName = "Android", - // RELEASE BUILDS + // RELEASE BUILD SETUP // The full path to the .apk file // This only works with release builds because debug builds have fast deployment enabled // and Appium isn't compatible with fast deployment // App = Path.Join(TestContext.CurrentContext.TestDirectory, "../../../../MauiApp/bin/Release/net8.0-android/com.companyname.basicappiumsample-Signed.apk"), + // END RELEASE BUILD SETUP }; // DEBUG BUILD SETUP