Appium Commands


Every automation tester should be familiar with Appium commands to create a robust mobile apps automated test scripts. However, knowing all the methods/commands is a challenge. A quick reference material/cheat sheet will be helpful for mobile app automation testers. In this blog article, we will see most important Appium commands.

DesiredCapabalities

DesiredCapabalities for launching an application (Android):

//Setting desiredcapabilities for particular device and application

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Lenovo");
caps.setCapability("version", "6.0");
caps.setCapability("platformName", "Android");

caps.setCapability("appActivity", "com.android.vending.AssetBrowserActivity");
caps.setCapability("appPackage", "com.android.vending");
caps.setCapability("appWaitActivity", "2000");
caps.setCapability("noReset", "true");
caps.setCapability("autoGrantPermissions", "true");
caps.setCapability("automationName" ,"UiAutomator2");
caps.setCapability("appWaitActivity", "SplashActivity, SplashActivity,OtherActivity, *, *.SplashActivity");
caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,"6000");
caps.setCapability("unicodeKeyboard", "true");

Launching an application

//Launching the application using appium server

AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);

Find Element By Accessibility Id

//Finding element using accessibilityId

driver.findElementByAccessibilityId("Play Store");

Press KeyCode

//Performing key press action

driver.pressKeyCode(AndroidKeyCode.HOME); 

Or

driver.pressKeyCode(3);

Lock Device

//Locking the device

driver.lockDevice();

Is Locked

//Verify the device is locked

driver.isLocked();

Unlock Device

//Unlock the device

driver.unLockDevice();

Get Keyboard

//To display the device keyboard

driver.getKeyboard();

Hide Keyboard

//To hide the device keyboard

driver.hideKeyboard();

Is Keyboard Shown

//To verify the keyboard is displayed

driver.isKeyboardShown();

Open Notification

//To open the notification

driver.openNotification();

Get Device Time

//Get the device current time

driver.getDeviceTime();

Location

//get current location of the device

driver.Location();

Set Location

//setting the device location
Location location = new Location(77.59974003, 12.91024781, 909);

driver.setLocation(location);

Get Orientation

//get the orientation of the device

driver.getOrientation();

Rotate

//change the orientation of the device to Landscape
driver.rotate(ScreenOrientation.LANDSCAPE);

//change the orientation of the device to Potrait
driver.rotate(ScreenOrientation.POTRAIT);

Activate App

//activate a new application in real device

driver.activateApp(“app package or bundle id”);

Install App

//install a new application in a real device

driver.installApp(“Location of the apk”);

Is App Installed

//verify the application is installed

driver.isAppInstalled(“app package or bundle id”);

Single Tap

//Tap on an element in the application

TouchActions action = new TouchActions(driver);
action.singleTap(Element element);
action.perform();

Double Tap

//Double tap on an element in the application

TouchActions action = new TouchActions(driver);
action.doubleTap(Element element);
action.perform();

Long Press

//Long press on a selected element

driver.longPress(WebElement element);

Scroll

//Scroll the displayed screen

TouchActions action=new TouchActions(driver);
action.scroll(xOffset, yOffset).perform();

Terminate App

// close the current application

driver.terminateApp();

Remove & Reset App

// remove an App from the device
driver.removeApp();


//reset the App for current session
driver.resetApp();

Get Capabilities

//To retrieve the full capabilities associated with the driver 

driver.getCapabilities();

Get Session Id

//Use this call to retrieve a SessionID

driver.getSessionId

Get Setting

//Retrieve the current settings of the device

Map settings = driver.getSettings();

Leave a Reply

Your email address will not be published. Required fields are marked *