Interacting with another app

Most of the time, when we test a mobile application, it requires interaction with another app. For example, an app might need integration with the Contacts app or the SMS app. Sometimes, while testing, we might need to simulate the geo location, which can be done via an external app installed on the device/emulator (or it can even be done using Android adb commands).

When we start an Appium session for testing, generally it is tied to an app as we are passing the app parameter in the desired capabilities, so we can't really pass two apps in the desired capabilities. If we recall our code, we are using this line:

capabilities.setCapability("app", "/Users/nishant/Development/HelloAppium/app/quikr.apk");

One way to switch between the apps is when we know the target app's package name and activity name. Android driver exposes a method, startActivity(Activity activity), which basically takes an activity as input and starts it. So, a sample code snippet to start the Contacts app on a device will look like this:

Activity activity = new Activity("com.android.contacts", ".ContactsListActivity");
androidDriver.startActivity(activity);

Once we are done with the test steps we want on this app, we can use the BACK key to traverse back to the application under test:

androidDriver.pressKeyCode(AndroidKeyCode.BACK);

The StartActivity() method is available only for androidDriver and not for AppiumDriver. On iOS devices/simulators we can't automate two apps in one session due to a limitation from the Apple itself. The only way we can do this:

  • Initiate a session 1
  • Run through the steps for app 1
  • Close session 1
  • Start another session 2
  • Run through the steps for app 2
  • Close the session 2.

One thing we need to keep in mind is to set the Desired Capability noReset to be true while creating the driver instance.

Let's take a look at how we can run the test in parallel.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.171.51