Previous Topic, In this tutorial we will learn Appium Mobile Device Commands and its syntex under Android driver.
What are Appium Mobile Device Commands?
Those commands which are written under the script for handling the android device features like keyboard handling, orientation etc are referred to as Appium Device Commands.
Lets discuss the commands in details:
1 ) pressKeyCode(key): As every key in the mobile device is associated with a code in its back-end, and to hit the key we need to call the keycode to perform operation.
If we want to hit the key in mobile device through appium script we call pressKeyCode(Key) method and pass keycode as a parameter. For calling keycode we use method “AndroidKeyCode“.
//Syntex //This syntex will hit the home button of your mobile device adriver.pressKeyCode(AndroidKeyCode.HOME);
2 ) pressKeyCode(AndroidKeyCode.KEYCODE_APP_SWITCH): There are multiple scenarios where we need to switch from on application to another application, so to handle such scenario we can use this method.
This method minimizes the current window and all the application gets displayed on single screen.
How to change the orientation of screen in mobile device?
3 ) rotate(orientation): If we want to change the orientation of the screen of device, it can be performed using the command, this command requires screen orientation as parameter and returns nothing or void.
The orientation is defined by using the ScreenOrientation class followed by its type (ex Landscape, portrait ) etc
//Syntex //Change orientation to landscape driver.rotate(ScreenOrientation.LANDSCAPE);
4 ) getKeyboard(): We can perform any task on the mobile key board only when its enabled or displayed on screen.
To get the keyboard on mobile device we call getKeyboard() method, it takes nothing as parameter or void and return keyboard type object.
//Syntex //Enable the keyboard on mobile device driver.getKeyboard();
5 ) hideKeyboard(): To hide or disable the keyboard from the mobile screen we call the hideKeyboard() method, it take nothing and return nothing or void.
6 ) lockDevice(): Using the lockDevice() method, we can lock mobile device through appium script , it takes no parameter and returns void.
7 ) unlockDevice(): As we can lock mobile device, similarly we have the capability to unlock device through appium script. It takes no parameter and returns void.
8 ) isLocked(): If we want to check whether the mobile device is locked in current session or not, we can get this information using the command. It takes no parameter and return boolean (true or false).
As per the return boolean to the condition we can perform multiple operations.
//Syntex //It check wheter mobile device is locked or not and returns boolean driver.isLocked();
9 ) toggleLocationServices(): Appium provides the capability to toggle the location service through command, it takes no parameter and returns void.
10 ) getSessionId(): Session Id is something which active thoughout the session and provided the connectivity of appium server with mobile application.
To get the session id we use getSessionId().
//Syntex //Will give the session id of the instance driver.getSessionId().toString();
So below are the few basic device command to work on mobile application, in next topic we will learn few more advance topic on Appium.
Please comment us for any query or suggession.