Xamarin.UITest - Handle (tap/verify) notification

Hello experts,

I'm doing a PoC for automation project using Xamarin.UITest, and stuck at handling (verify_content or tap) on the notification.

I did searching for a while but don't see any guideline for this case. It's very important feature for our app and we want to automate these cases.

If you guys know that, please shed a light.

Thank you in advance.

Answers

  • Moses_SundayMoses_Sunday Member ✭✭

    To start, you need to create an UI Test project. Next, add to it the following NuGet packages:

    1. Xamarin.UITest
    2. NUnit
    3. NUnitTestAdapter3

    In this project, we’ve decided to follow the concept of “page helpers”. Basically, it abstracts at level page the interactions you can get with a certain page. This level of abstractions aims for a cleaner codebase, because when you’re writing the real test, you use the methods you’ve previously defined on the page. For example, in the Login Page, we’ve set the interactions “Enter credentials” and “Sign in”. Here is the code:

    public LogInPage EnterCredentials(string username, string password) { App.WaitForElement(emailField); App.Tap(emailField); App.EnterText(username); App.DismissKeyboard(); App.Tap(passwordField); App.EnterText(password); App.DismissKeyboard(); App.Screenshot("Credentials Entered"); return this; } public void SignIn() { App.Tap(signInButton); }

    As you can see, this avoids going to “control level” when you’re writing the actual tests. So, for a successful sign-in test, you can write a test as simple as:

    [Test] public void SuccessSignInTest() { […] new LogInPage() .EnterCredentials(TestSettings.TestUsername, TestSettings.TestPassword) .SignIn(); new HomePage(); […] }

    In this case, we’re using Android and iOS, and, although the test code is the same, you can establish different set-ups for different platforms. For example, the way to install the app to test.

    if (Platform == Platform.Android) { app = ConfigureApp .Android .WaitTimes(new WaitTimes()) // Used to run a .apk file: .ApkFile("../../../SmartHotel.Clients/SmartHotel.Clients.Android/bin/UI Test/com.microsoft.smarthotel.apk") .StartApp(); } if (Platform == Platform.iOS) { app = ConfigureApp .iOS .WaitTimes(new WaitTimes()) // Used to run a .app file on an ios simulator: //.AppBundle("path/to/file.app") // Used to run a .ipa file on a physical ios device: .InstalledApp("com.microsoft.SmartHotel360-df") .StartApp(); }

Sign In or Register to comment.