How to handle redirects from one app to another

I’m creating a test script for an Android app using Java and I am stuck in automating the scenario below which involves redirection from 1 app to another.

  1. Press a button in App1 which will redirect the user to App2
  2. Validate fields in App2 and press a button that will return user to App1
  3. Perform some more tests in App1

My script is failing in Step 2 since the android driver does not recognize the UI elements in App2. Can someone help me in how to handle this?

Thanks a lot!

we do not have problem with Android when we want send email from client using e.g. Gmail client. What is your scenario?

This is my current code:

//Click on the button that will redirect user to App #2
driver.findElement(By.id(appButton1)).click();

//User is now in App #2
//Make Asserts
Assert.assertEquals(driver.findElement(By.id(sometext)).getText(), “Test”);
//Click on the button that will return the user to App #1
driver.findElement(By.id(appButton2)).click();

//User in now back in App #1
//Make Asserts
Assert.assertEquals(driver.findElement(By.id(Parameters.SCC_LINE2)).getText(), “Test”);

The problem is that the script does not recognize the UI elements in App #2. Should I have in my code a line that will switch to the other app?

Thanks.

make sure that you use FULL id with package name when you calling another app.

e.g. with Gmail client need to call like:

    @AndroidFindBy(id = "com.google.android.gm:id/subject")
    private List<AndroidElement> gmail_SubjectInput;

Adding the package name to the id worked perfectly. Thanks so much!

Hi, do you have an idea on how to do the same in iOS? I already have the package name but the elements do not have an ID. I can only use the xpath.

package name in IOS? seriously?

I believe the Bundle ID in iOS is same as the Package name in Android.

Any idea how to refer to a UI element in another app for iOS? I tried using the same format as Android but it didn’t work. See format below:

com.google.android.gm:xpath/