Appium Basic (P3) – Manipulate some common items Drop-down list, Set date time, Switch button, Handle alert dia-log

Tram Ho

Continuing the Appium introduction series, in this part 3, we will continue to manipulate some common items Drop-down list, Set date time, Switch button, Handle alert dia-log.

Refer to the previous parts of the series:

Appium Basic (P1) – Run First Android Automation Test

Appium Basic (P2) – Work with Textbox, Check box, Radio button

The test app is still a Demos API, you can get the download link and the BeforeTest setup code in Part 2

1. Drop-down list

The drop-down list is one of the items that appears frequently on web applications, as well as mobile apps. Let’s look at some operations with the Drop-down list.

Open the Drop-down list from the Demos API app: Home -> Views -> Controls -> 2. Dark Theme. -> Tap on Drop Down .

Select an option in the Drop-down list

Open Drop-down list: driver.findElement(By.id("android:id/text1")).click();

Select the “Mars” option in the Drop-down list: driver.findElement(By.name("Mars")).click();

Get the drop-down list of options

Open Drop-down list: driver.findElement(By.id("android:id/text1")).click();

Locate the drop-down list’s options, enter a list:

List dropList = driver.findElements(By.id("android:id/text1"));

Take out the options one after another:

2. Set date time

The date time picker in the Android app can be displayed directly on the screen or displayed via the Dialog. Let’s look at a simple example of how to set Date time with Appium. The Date time format may differ depending on your app, but basically the set method remains unchanged.

Open the Drop-down list from the Demos API app: Home -> Views -> Date Widgets -> 1. Dialog .

Set Date = 25 Aug 2009

Set time = 1:25 pm

3. Switch button

Switch button can easily ON / OFF by clicking (). However, we need to check the status of the Switch button is ON or OFF so after the operation to get the desired status.

Open the Switches screen from the Demos API app: App Home -> Views -> Switches

Check the current status of the Switch button:

ON Switch button:

OFF Switch button:

4. Handle alert dia-log

Open the Alert Dialogs screen from the API Demos app: Home -> App -> Alert Dialogs

Get message from Dialogs:

Click OK: driver.findElement(By.name("OK")).click();

Click Cancel: driver.findElement(By.name("Cancel")).click();

— End of part 3 —

References:

http://www.software-testing-tutorials-automation.com/2015/10/appium-tutorials.html

Share the news now

Source : Viblo