Appium Test Script to Launch Android Application

 Pre requisites:

  • Eclipse IDE
  • Android SDK
  • Java
  • Appium Desktop
Refer: Appium Setup

Create Maven Project in eclipse:


Click on File -> New -> Other-> Maven
Click Next

Check create sample project and click Next


Enter Group Id, Artifact Id  and Click Finish
Maven Project AndroidDemo created.

Add Appium-Java client dependencies in pom.xml file

Create package and java class to write test script to launch Android app.

Check the device connected to your PC or not using adb devices:

Desired capabilities:

Desired Capabilities are keys and values encoded in a JSON object, sent by Appium clients to the server when a new automation session is requested. They tell the Appium drivers all kinds of important things about how you want your test to work
Refer:  Appium Desired capabilities doc.
Required capabilities:
// To create an object of Desired Capabilities
DesiredCapabilities dc = new DesiredCapabilities();
// Device name:  – I am using Redmi6
dc.setCapability("deviceName", "Redmi");
// Name of the OS: Android, iOS or FirefoxOS
dc.setCapability("platformName", "Android");
// Mobile OS version –  My device is running Android 9
dc.setCapability("platformVersion", "9");
// Java package of the tested Android app
dc.setCapability("appPackage", "com.android.settings");
// An activity name for the Android activity you want to run from your package.
dc.setCapability("appActivity", "com.android.settings.MainSettings");
dc.setCapability("noReset", true);
dc.setCapability("autoAcceptAlerts", true);
dc.setCapability("autoGrantPermissions", true);
dc.setCapability("automationName", "UiAutomator2");
// Constructor to initialize driver object with new Url and Capabilities
//URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), dc);


To find app package and Activity of installed app open cmd and type
adb shell dumpsys window | find "mCurrentFocus" 


 
Code snippet:



Now Open Appium desktop:

Start the server to run test scripts

To run your scripts Right click on Java class-> Run as Java application




No comments:

Post a Comment

Scroll iOS application using Appium

When creating test scripts for iOS native app we need to perform scroll to perform any other action on particular element  Here we will get ...