In iOS App is not closing properly between each test cases

SujathaSujatha Member ✭✭

After upgrading xamarin ui test, while running automation in iOS - app is not closing properly between each test cases.
Scenario
we have single app, with different content page - each case will check different content page.

For example, Test step of Test Case -1 has been done on content page-1. without closing content page-1 , test case - 2 operations are done on the same content page(content page-1). but i need the simulator to close the app(content page-1) and open the content page-2 to do test step of Test case-2. Due to this expect first test case, rest of the test cases are getting failed :( . any solution please. Thanks in advance.

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    @Sujatha said:
    After upgrading xamarin ui test, while running automation in iOS - app is not closing properly between each test cases.
    Scenario
    we have single app, with different content page - each case will check different content page.

    For example, Test step of Test Case -1 has been done on content page-1. without closing content page-1 , test case - 2 operations are done on the same content page(content page-1). but i need the simulator to close the app(content page-1) and open the content page-2 to do test step of Test case-2. Due to this expect first test case, rest of the test cases are getting failed :( . any solution please. Thanks in advance.

    If you need to terminate the app between test cases, have your UITest invoke a backdoor method in the app that is only present during testing.

    In your test code:

    _app?.Invoke("TestingBackdoorToKillApp");
    

    Then, in AppDelegate.cs of your iOS project:

    #if DEBUG // or however you identify your test build
            // definitely doesn't want to make it to the AppStore!
            [Export("TestingBackdoorToKillApp")]
            public void TestingBackdoorToKillApp()
            {
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            }
    #endif
    

    and in MainActivity.cs of your Android project:

    #if DEBUG // or however you identify your test build
            // definitely doesn't want to make it to any app stores!
            [Java.Interop.Export("TestingBackdoorToKillApp")]
            public void TestingBackdoorToKillApp()
            {
                this.FinishAffinity();
                JavaSystem.Exit(0);
            }
    #endif
    
  • SujathaSujatha Member ✭✭

    I tried the code as given in previous update, but while executing the test - we are facing an error as "Error while performing invoke".

    can you please provide me some suggestions.

  • JohnHardmanJohnHardman GBUniversity mod

    @Sujatha said:
    I tried the code as given in previous update, but while executing the test - we are facing an error as "Error while performing invoke".

    Do you get the error every time?

  • SujathaSujatha Member ✭✭
    Yes. Every time as we execute the test we face this error.
  • SujathaSujatha Member ✭✭
    Actually app is closing using provided code and we get this error in test result tab.
  • JohnHardmanJohnHardman GBUniversity mod

    @Sujatha said:
    Actually app is closing using provided code and we get this error in test result tab.

    If the app is closing, that answered your original question. I would suspect then that the message you are seeing in the test result tab is the test runner reporting that between the point when the runner invoked TestingBackdoorToKillApp and the point when it expected TestingBackdoorToKillApp to complete, the app terminated. There's not much (if anything) that can be done about that - you'd need to consider it as information rather than an error. To confirm that this is the case, simply comment out the code within TestingBackdoorToKillApp temporarily and run a single test that calls it. I would expect the message to not appear. Then put the code back in and re-run that single test. I would now expect the message to appear again if that is the case.

  • SujathaSujatha Member ✭✭
    As you mentioned, in the case if we comment the code withtin TestingBackdoorToKillApp - we don't get the error message. but our original issue is reproducing. If we include the code withtin TestingBackdoorToKillApp- we get a message as "Error while performing invoke" and in this case in Test result tab - failure count is increasing.
  • JohnHardmanJohnHardman GBUniversity mod

    @Sujatha - When responding, don't forget to tag me @JohnHardman . If you don't do that, I don't get notified of your response and so may miss your message.

    Regarding the failure count - this is odd. I don't actively use UITest any more, but when I did I used to use this code even within tests, not just as cleanup after each test. I didn't see the error that you are getting. However, all of my testing was done on physical devices linked to my Mac (for iOS) or to my PC (for Android). Have you tried running the tests on locally connected physical devices, rather than on remove devices in App Center? I wonder if what you are seeing is a consequence of terminating an app when running UITest in App Center.

Sign In or Register to comment.