Introduction to SeeTest Automation Commands:
In our previous tutorial, we learned about some basic commands that can perform simple actions like click, send a text to a text box, wait for an element etc.
This tutorial is part of SeeTest Mobile Test Automation series.
When we are about to work with mobile apps that require complex actions to be performed, we need to explore more advanced SeeTest commands. Here, we will discuss all the SeeTest commands including advanced ones to perform complex actions on the app, commands to perform actions on the OS and at the hardware level.
This tutorial gives you a complete overview of the various types of SeeTest Automation Commands along with real-life examples and a brief explanation of each command for your easy understanding.
Table of Contents:
SeeTest Automation Commands
SeeTest Automation provides commands for almost all of the actions that can be performed on a mobile device.
If one action is missing, the same can be achieved by using some workarounds. We will discuss some useful commands that might help while testing mobile apps.
Object Related Commands
This section describes SeeTest Automation commands that are related to actions performed on Objects in the mobile apps.
#1) Basic Commands
Given below is a list of all the basic commands along with their usage.
Command | Use |
---|---|
Click | Click on an object |
IsElementFound | Check for the presence of an element |
VerifyElementFound | Verify presence of an element |
ElementGetProperty | Get value of an element’s property |
ElementSendText | Send text to textbox without clicking on it |
GetElementCount | Get count of the element matching a given xpath |
VerifyElementNotFound | Verify the invisibility of an element |
WaitForElement | Wait for the presence of an element for a specified time period |
WaitForElementToVanish | Wait for the invisibility of an element for a specified time period |
#2) Advanced Commands
Given below is a list of all the advanced commands along with their usage.
Command | Use |
---|---|
Click (Offset) | Click on an object at a specified offset |
ClickCoordinate | Click on the specified coordiantes |
ClickIn | Click inside an element |
Drag | Perform Drag operation |
ElementListSelect | Select an element from a list |
ElementSetProperty | Set value of a property of an element |
ElementSwipe | Perform swipe on an element |
WaitForElementToVanish | Wait for the invisibility of an element for a specified time period |
VerifyIn | Verify for the presence of an element inside another element |
GetCoordinateColor | Get RGB color value at a coordinate |
DragDrop | Perform drag and drop operation |
LongClick | Perform touch and hold |
Both these Basic and Advanced commands are explained one by one in detail below.
#1) Click
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Click count | Number of clicks | int | 0 |
Default zone is selected for identifying the objects in the ‘default’ object repository. If Text is specified as Zone, then SeeTest Automation searches for the text specified for Element (2nd argument) in the UI and clicks on it.
Throws an exception if the element is not found.
Example: client.click(“NATIVE”, “text=Close”, 0, 1);
#2) IsElementFound
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Default zone is selected for identifying the objects in the ‘default’ object repository. If Text is specified as Zone, then SeeTest Automation searches for the text specified for Element (2nd argument) in the UI.
This command does not throw an exception if the desired element is not found, instead, it returns false.
Example: boolean found = client.isElementFound(“NATIVE”, “id=loginButton”, 0);
#3) VerifyElementFound
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
This is similar to IsElementFound, but throws an exception if the desired element is not found.
#4) ElementGetProperty
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Property | Property of the element whose value is to be retrieved | String | “id” |
This command throws an exception if the desired element is not found.
Example: String text = client.elementGetProperty(“NATIVE”, “text=Login”, 0, “text”);
#5) ElementSendText
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Text | Property of the element whose value is to be retrieved | String | “admin” |
This command throws an exception if the desired element is not found.
Example: client.elementSendText(“NATIVE”, “hint=Password”, 0, “admin”);
#6) GetElementCount
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | String |
This command throws an exception if the desired element is not found.
Example: client.getElementCount(“NATIVE”, “text=Login”);
#7) VerifyElementNotFound
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
This command throws an exception if the desired element is found.
Example: client.verifyElementNotFound(“NATIVE”, “text=Login1”, 0);
#8) WaitForElement
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Timeout | Wait timeout in milliseconds | long | 10000 |
This command returns false if the element is not found within the specified time limit. No exception is thrown.
Example: boolean found = client.waitForElement(“NATIVE”, “text=Login”, 0, 10000);
#9) WaitForElementToVanish
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Timeout | Wait timeout in milliseconds | long | 10000 |
This command returns false if the element does not vanish within the specified time limit.
Example: boolean vanished = client.waitForElementToVanish(“NATIVE”, “text=Login1”, 0, 10000);
#10) Click (Offset)
Parameter | Description | Type | Possible values |
---|---|---|---|
X | X coordinate of the click location | int | 300 |
Y | Y coordinate of the click location | int | 500 |
Click count | Number of clicks | int | 1 |
Example: client.click(“NATIVE”, “text=Login”, 0, 1, 300, 500);
#11) ClickCoordinate
Parameter | Description | Type | Possible values |
---|---|---|---|
X | X coordinate of the click location | int | 300 |
Y | Y coordinate of the click location | int | 500 |
Click count | Number of clicks | int | 1 |
Example: client.clickCoordinate(300, 500, 1);
#12) ClickIn
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Element type | String | NATIVE/WEB/TEXT/default |
Search Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index | int | 1 |
Direction | Search direction | String | Left/Right/Up/Down/Inside |
ClickElementZone | Type of the element to be clicked | String | “TEXT” |
ClickElement | Representation of the element to be clicked | String | “Login” |
ClickElementIndex | Index of the element to be clicked | int | 0 |
Width | Width of the search | int | 0 |
Height | Height of the search | int | 0 |
Click count | Number of clicks | int | 1 |
This command is useful if we need to click on an element inside another element. Width and Height as 0 indicates searching from the start to the end.
The below example is to click on the text ‘Login’ inside the Login button.
Example: client.clickIn(“NATIVE”, “text=Login”, 0, “inside”, “TEXT”, “Login”, 0, 0, 0, 1);
#13) Drag
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Element type | String | NATIVE/WEB/TEXT/default |
Search Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | index | int | 1 |
XOffset | X Offset | int | 0 |
YOffset | Y Offset | int | 100 |
If XOffset is set to 0, then this command will drag vertically and if YOffset is set to 0 then it drags horizontally.
Example: client.drag(“NATIVE”, “text=Login”, 0, 0, 100);
#14) ElementListSelect
Parameter | Description | Type | Possible values |
---|---|---|---|
List Locator | Element type | String | Id=countryList |
Element Locator | Element representation | String | text=USA or //*[@text=’USA’] |
Index | Number of clicks | int | 1 |
Click | Whether to click or not | boolean | true |
Example: client.elementListSelect(“id=countryList”, “text=USA”, 0, true);
#15) ElementSetProperty
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Property | Property name | String | “id” |
Value | Value to be set for the property | String | “loginButton” |
Not all the apps allow changing the properties set by the developer.
Example: client.elementSetProperty(“NATIVE”, “text=Login”, 0, “id”, “loginButton”);
#16) ElementSwipe
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Direction | Direction to swipe | String | Up/Down/Left/Right |
Offset | Swipe offset | int | 300 |
Time | Swipe overall time | int | 300 |
If the time is minimized, the swipe intensity will be more and the swipe will be done quickly.
Example: client.elementSwipe(“NATIVE”, “text=Login”, 0, “Right”, 300, 300);
#17) WaitForElementToVanish
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Timeout | Vanish timeout | long | 10000 |
Example: client.waitForElementToVanish(“NATIVE”, “text=Close”, 0, 10000);
#18) GetCoordinateColor
Parameter | Description | Type | Possible values |
---|---|---|---|
X | X coordinate | int | 400 |
Y | Y coordinate | int | 500 |
This command returns coordinate color as RGB value. We need to extract Red, Green and Blue color information from it to find the actual color.
Example: int rgbColor = client.getCoordinateColor(300, 300);
#19) LongClick
Parameter | Description | Type | Possible values |
---|---|---|---|
Zone | Type of the element | String | NATIVE/WEB/TEXT/default |
Element | Element representation | String | Id=loginButton or //*[@id=’loginButton’] |
Index | Index of the element | int | 0 |
Click count | Number of clicks | int | 1 |
X | X offset from element | int | 100 |
Y | Y offset from element | int | 100 |
Example: client.longClick(“NATIVE”, “text=Login”, 0, 1, 100, 100);
There are still many more commands to perform complex actions. You can check SeeTest Automation’s command window to explore more such commands.
Device Related Commands
This section describes SeeTest Automation commands that are related to the actions performed on the mobile device itself.
#1) SendText
This is to perform the actions such as navigating back, pressing the home button, changing orientation etc. This can also send texts to the text box if the text box is selected.
Example: client.sendText(“{ESC}”);
The code given in the above example simulates the action of Android’s back button functionality. SeeTest supports a number of such phrases enclosed in { and } that can be included in the SendText command to perform special actions.
Those are listed in the below table.
Text | Use |
---|---|
{HOME} | Simulates pressing Home button |
{BKSP} | Press back space |
{PORTRAIT} | Change orientation to Portrait mode |
{LANDSCAPE} | Change orientation to Landscape mode |
{ENTER} | Simulate operation of Enter button |
{WAKE} | Wake screen |
{UNLOCK} | Unlock device |
{CLOSEKEYBOARD} | Close opened keyboard |
#2) Swipe
This is to perform the swipe operation on the device level instead of swiping on an object.
The command is similar to ElementSwipe except it is missing Zone and Element.
#3) Flick
The flick is a fast swipe performed on the device. This is useful when we need to scroll up/down more.
Using swipe, in this case, will consume more time.
Example: client.flick(“DOWN”, 400);
#4) CloseKeyboard
This is to close the device keyboard.
Example: client.closeKeyboard();
#5) Reboot
This command is used to reboot the device.
A wait timeout is passed as the argument indicating the timeout wait for rebooting the device. If 0 is passed, the device will perform an instant reboot.
Example: client.reboot(1000);
#6) GetVisualDump
This is used for getting the Xml (of Native elements) and HTML (of Web Elements) representation into a String.
If this is used in a web page, it will return the HTML source of that webpage.
#7) Pinch
This is used to perform the pinch operation.
#8) Shake
This command simulates the shake operation.
#9) Run
This command is used in the Android devices to run adb commands.
We can make use of this command to run adb commands for functionalities outside the scope of SeeTest Automation such as getting package name of an application, to check whether an application is installed on the device or not, etc.
It can also be used to activate and deactivate the Airplane mode via adb command.
#10) 2Cx
This command is used to retrieve the horizontal pixel value corresponding to a percentage passed with the command.
A percentage 100 will return the maximum width of the device in pixels.
#11) P2Cy
This command is similar to the above command except that it calculates a vertical pixel value for a percentage passed with the command.
A percentage 100 will return the maximum height of the device in pixels.
Application Related Commands
This section describes the SeeTest Automation commands that are related to the actions performed on the mobile applications.
#1) Install
This command is used to install applications on the device.
Arguments of this command are as follows:
- App path: Application name if the application is available in the SeeTest package manager, otherwise path of the application. For Android apps, Activity Name is the application name.
- Instrumented: Boolean value indicates whether to install the application as instrumented or not. Setting true will install the application as instrumented.
- Keep data: Boolean value indicates whether to keep the application data or not. Setting true will keep the app data.
#2) Uninstall
This command performs uninstallation of an application. It takes only one argument that is the app path.
If the application that needs to be removed is available in the SeeTest package manager, then just the app name is enough. Otherwise, the app path is required.
#3) Launch
This is used to launch an application on the device.
Its arguments are:
- Activity: App name or activity name.
- Instrumented: Boolean value indicates whether to launch the app in the instrumented mode or not. Only apps that are installed as instrumented can be launched in the instrumented mode. Setting true will launch the app in instrumented mode.
- Stop if running: Boolean value indicates whether to close the app if it is already running. Setting true will close the app and re-launch it.
#4) ApplicationClearData
This is applicable for Android devices to clear the app data.
#5) SimulateCapture
This command simulates the operation of the device camera by taking pictures by using the device camera and stores in a file whose path is specified in the argument.
Utility Commands
Given below is a lost of various Utility commands along with a brief explanation.
#1) SetDevice
This command is used to set the test device. The device name is displayed in the SeeTest Automation and after connecting, it needs to be passed as the parameter.
#2) WaitForDevice
This command waits for a device with a specified query for a period.
The query should be any of the following:
- Device added: If a device is available on the SeeTest device list.
- Manufacture
- Model
- Name
- OS: Operating system
- Remote: If a device is connected through SeeTestCloud or not (values are true/false).
- Serial number: S/N of the device.
- Version: OS version (KitKat, Lollypop etc.)
- Version number: OS version number (4.4.0 – 4.4.4 for KitKat)
Examples:
client.waitForDevice(“@os=ios”, 3000); – Wait for iOS device 3 seconds
client.waitForDevice(“@versionNumber=5.1.1”, 3000); – Wait for Android device with OS version as 5.1.1
This command is very useful during parallel execution in which we do not have to explicitly set the device name by SetDevice command. SeeTest will choose appropriate devices dynamically to the appropriate ports.
#3) GetDevicesInformation
Get necessary information of connected devices.
#4) GetConnectedDevices
Get connected device names.
#5) GetInstalledApplications
Get a list of applications installed on the device.
#6) AddDevice
Add a device to its serial number and the device name.
Conclusion
In this tutorial, we learned about the various types of commands provided by SeeTest Automation to perform a series of actions on the mobile device or app.
By using the above commands, we can perform automation of some real-time applications on our own mobile device. But in some cases, when an application does not have enough properties to be recognized during Object Spy, we need to seek alternatives to get it recognized.
The alternatives provided by SeeTest Automation is image and text identification. Same as this situation, we may also face other challenges like inconsistent device notifications during automation test execution, parallel execution, automation of web components etc.
In our next 4th and last tutorial, we will address these situations and possible ways or workarounds to overcome these challenges in detail using a real-time mobile app.