Skip to content

Appium Tips And Tricks

Mobile Automation Using Appium

How To Launch Virtual Devices Automatically

We can launch virtual devices automatically by using “avd” Capability.

 capabilities.setCapability("avd","EmulatorName");

Add this capability to your script and execute the code. The configured emulator will launch automatically. However, it may take some time to launch the device and cause a timeout issue. To resolve that add the “avdLaunchTimeout” capability.

capabilities.setCapability("avdLaunchTimeout",120000);

Now it will wait 2 Minutes to launch the connected emulator before throwing a Timeout issue.

How To Minimize And Reopen App Again

Appium has a method “runAppInBackground” that Runs the current app as a background app for the time requested.

AndroidDriver.runAppInBackground(Duration.ofSeconds(10));

How To Automate Two Or More Applications In Appium

Is it possible to automate 2 apps in Appium Or in other words How to switch between apps? Suppose we have a scenario where we need to enter a username and password on the login screen and on the click of submit button a code is generated. We need to capture that code and enter it then only the user can proceed.

On Android it is possible to start a second application, however, this is not possible for IOS.

By using the startActivity() method we can provide the app package name and app activity that we want to open at runtime. This method should start arbitrary activity during a test. If the activity belongs to another application, that application is started and the activity is opened.

Scenario To Test:

1)Open the First Application
2)Perform a few operations
3)Start the Second Application
4)Perform a few operations on the second application
5)Terminate the second application and switch to the first application

@Test
public void applicationSwitch() throws Throwable {
AndroidDriver.findElementByClassName("android.widget.EditText").sendKeys("admin"); 
AndroidDriver.findElementByClassName("android.widget.Pass").sendKeys("admin"); // Interaction with First App
AndroidDriver.startActivity(new Activity("appPackage", "AppListActivity"));//Launch Second App
AndroidDriver.findElementByClassName("android.widget.submit").click();//Perform Click Operation In Second App
 AndroidDriver.terminateApp("appPackage"); //Terminate Second app
 AndroidDriver.findElementByClassName("android.widget.EditText").sendKeys("Welcome User");
 }

How To Unlock Pattern On Android Device Using Appium?

Use This Driver.

capabilities.setCapability("unlockType","pattern");
capabilities.setCapability("unlockKey",12345678);

How To Interact with AndroidElements Using AndroidUIAutomator

driver.findElementByAndroidUIAutomator("text(\"ALLOW\")").click();

How To SpeedUp The Appium Script Execution

We can skip the server installation and skip unlock check if we are sure that our device is already unlocked. Add the below-mentioned capacities in your test script and see the difference in test execution time.

capabilities.setCapability("skipUnlock",true);
capabilities.setCapability("skipServerInstallation",true);
Appium Tips And Tricks

How To Adjust Network Connectivity Of Android Emulators

Appium has the ability to adjust the network connectivity of Android Emulators with a simply desired capability:

 capabilities.setCapability("networkSpeed", "lte");