Download as pdf or txt
Download as pdf or txt
You are on page 1of 107

Mobile App Test Automation

With Appium
May, 2019
Agenda
01 Install Appium

02 Understand Capabilities in Appium

03 Finding Mobile Elements

04 Automating Different Apps

05 Automating Mobility
Install Appium
Step 1: Java Installation and Setup
With Appium, you would need to write automation test scripts that interact with the
screens and controls (buttons, text boxes etc) in your mobile app and perform actions
on them. We would use Java to write these automation scripts.

Step 1.1: Download and Install latest version of Java 8 (JDK)


Step 1.2: Setup Java Environment Variables
Install Appium
Step 1.1: Download and Install latest version of Java 8 (JDK)
Follow the steps given below to see if you have the latest version of JDK installed on
your machine
1. Open this link
https://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html

2. Open this link


The top section of the page shows details
about Java 8. Scroll down a bit till you see
Java 8 section. Click on Download button
below JDK label
Install Appium
Step 1.1: Download and Install latest version of Java 8 (JDK)

3. You will be now navigated to JDK Downloads page. On this page,


Accept License Agreement and then download the JDK for Windows based on
whether you have Windows 32-bit or 64-bit operating system
Install Appium
Step 1.1: Download and Install latest version of Java 8 (JDK)

4. Navigate to the folder where you had downloaded JDK. Double click on
the exe file to start the installation process. The installation process would now begin.
Click on Next button on the Setup screen
Install Appium
Step 1.1: Download and Install latest version of Java 8 (JDK)

5. On the Custom Setup screen, leave the installation folder as it is and click on
Next button.
Install Appium
Step 1.1: Download and Install latest version of Java 8 (JDK)

6. Wait for few seconds for Java to install some files. After that, it will ask you to specify
the destination folder of JRE. Leave the default location as it is and click on Next button
Install Appium
Step 1.1: Download and Install latest version of Java 8 (JDK)

7. JDK installation would now begin


Install Appium
Step 1.1: Download and Install latest version of Java 8 (JDK)

8. Once the installation is completed, you would see the window as shown in the
below screenshot. Click on Close button to close the window
Install Appium
Step 1.1: Download and Install latest version of Java 8 (JDK)

9. To verify that the installation is successful, open Java folder in Program files.
You would see that new JRE & JDK folders with the latest version numbers have
been created. Don‟t worry if you see previous versions of JRE or JDK folders in there.
Multiple versions of JDKs & JREs can co-exist.
Install Appium
Step 1.2: Setup Java Environment Variables

1. Now open the JDK folder. If you have multiple JDK folders, then open the one
which represents the latest version, and copy the folder location. As per the below
screenshot, we are copying this folder
location – C:\Program Files\Java\jdk1.8.0_171
Install Appium
Step 1.2: Setup Java Environment Variables

2. You have to now open environment variables window in your machine. To do this,
click on Start menu. Then right click on Computer and
select Properties option
Install Appium
Step 1.2: Setup Java Environment Variables

3. Now click on Advanced System Settings option


Install Appium
Step 1.2: Setup Java Environment Variables

4. This would open the System Properties window as shown below.


Now from the Advanced Tab, click on Environment Variables button
Install Appium
Step 1.2: Setup Java Environment Variables

5. From the Environment Variables window, click on New button from


System variables section
Install Appium
Step 1.2: Setup Java Environment Variables

6. Enter JAVA_HOME in Variable Name field and JDK folder location


(C:\Program Files\Java\jdk1.8.0_171) in Variable value field as shown in below image.
Please enter the correct folder location that you have in your machine
Install Appium
Step 1.2: Setup Java Environment Variables

7. Click on OK button. You will see that JAVA_HOME variable has now been added
in System Variables.

If you already have JAVA_HOME previously set, then you can click on Edit button to
modify its value. You have now successfully setup JAVA_HOME variable. Let us now
check how to setup the Path variable.
Install Appium
Step 1.2: Setup Java Environment Variables

8. Since the JDK folder location is already represented by JAVA_HOME variable, so


we can replace the location of JDK folder with
JAVA_HOME like this – %JAVA_HOME%\bin

In the Environment variables window, check that there is a variable called Path under
System variables. Please note that Path is an existing variable and we would edit it to
add the bin folder location
Install Appium
Step 1.2: Setup Java Environment Variables
9. Select the Path variable and click on Edit button. Path variable window would
be opened. Move over to the end of Variable value text field. There would be already
some value there. Put a semi-colon (;) at the end and then add the JDK folder
location – %JAVA_HOME%\bin, as shown below (Semi-colon is a delimiter which is
used to differentiate between different values in Path variable)
Install Appium
Step 1.2: Setup Java Environment Variables
10. Click on Ok button. bin folder location would now have been added in
the Path variable. Close the Environment variable window by clicking on Ok button.
With this, we have now successfully setup Path variable as well
Install Appium
Step 2: Android Installation and Setup
This is one of the most time consuming process, and the one which is prone to errors
if not done properly. The below articles provide you with the step by step approach to
download and setup the latest version of Android SDK manager. With the latest
version of Android Studio, there are many changes in the way Android needs to be
setup. So we recommend you to use the latest version of Android Studio, so that you
can follow the steps accurately as provided in the below articles.

Step 2.1: Download and Install Android Studio


Step 2.2: Install additional Android SDK tools
Step 2.3: Setup Android Environment Variables
Install Appium
Step 2.1: Download and Install Android Studio

1. Open Android Studio download link –


https://developer.android.com/studio/index.html. You will see Download Android
Studio button as shown below
Install Appium
Step 2.1: Download and Install Android Studio

2. Click on Download Android Studio button. You will see the Terms and
Conditions popup
Install Appium
Step 2.1: Download and Install Android Studio

3. Select the checkbox and click


on DOWNLOAD ANDROID STUDIO FOR
WINDOWS button. The download process
would now begin. Click on Save File to
download the .exe file to your machine
Install Appium
Step 2.1: Download and Install Android Studio

4. Android Studio Bundle would get downloaded to your machine


Install Appium
Step 2.1: Download and Install Android Studio

5. Double click on the downloaded exe file. Android Studio Setup Welcome Screen
would be displayed, as shown below (sometimes it might take a minute or so for the
below screen to load when you try it the first time)
Install Appium
Step 2.1: Download and Install Android Studio

6. Click on Next button. You will see the Choose Components screen. On this
screen, let both check boxes remain selected. You would observe that Android SDK
(which you need for Appium Scripts) is not displayed here. But once you install
Android Studio, and open it for the first time then you will see the option to download
Android SDK as well.
Install Appium
Step 2.1: Download and Install Android Studio

7. Click on Next button. You will now be taken to the License Agreement screen
Install Appium
Step 2.1: Download and Install Android Studio

8. Click on I Agree on the License Agreement screen. You will now see Configuration
Settings screen. Let the default installation location remain same.
Install Appium
Step 2.1: Download and Install Android Studio

9. Click on Next button. You will be taken to the Choose Start Menu Folder screen
Install Appium
Step 2.1: Download and Install Android Studio

10. Click on Install button to start the installation process.


Install Appium
Step 2.1: Download and Install Android Studio

11. Once the installation is complete, you will see the Installation Complete window as
shown below. Click on Next button. You will see Completing Android Studio Setup
screen. Uncheck Start Android Studio checkbox and then click on Finish button to
close the screen.
Install Appium
Step 2.2: Install additional Android SDK tools

1. Go to Start > All Programs > Android Studio folder and then open Android
Studio. Android Studio Welcome screen will be displayed as shown below
Install Appium
Step 2.2: Install additional Android SDK tools

2. Click on Next button. You will be taken to Install Type screen


Install Appium
Step 2.2: Install additional Android SDK tools

3. In the Install Type screen, let Standard


option remain selected and then click on
Next button. You will now be taken to
the Select UI Theme screen.
Select any theme here and click on Next
button. Verify Settings screen would now
be displayed. This is where Android SDK
Tools will be installed.
Install Appium
Step 2.2: Install additional Android SDK tools

4. Click on Finish button. Android Studio will now start downloading these
components
Install Appium
Step 2.2: Install additional Android SDK tools

5. When downloading is complete then click on Finish button. You will now
see Welcome to Android Studio screen
Install Appium
Step 2.2: Install additional Android SDK tools

6. Once your Android Studio project is opened, go to Tools > SDK Manager(in older
versions of Android Studio, this option was Tools > Android > SDK Manager)
Install Appium
Step 2.2: Install additional Android SDK tools

6. Once you select SDK Manager


option, Default Settings screen would
be opened with Android SDK option
selected by default, as shown in the
below image. Also, please note that
there are 3 main tabs in this screen –
SDK Platform, SDK Tools and SDK
Update Sites. We will be checking
only the first two tabs – SDK Platform
and SDK Tools
Install Appium
Step 2.2: Install additional Android SDK tools

7. In SDK Platform tab,


check that the latest version
of Android is installed. Even if
it shows Update available, it
means that the version is
installed. It‟s just that a new
update is also available.
Install Appium
Step 2.2: Install additional Android SDK tools

8. Click on SDK Tools tab.


Verify that the components
highlighted in the red boxes
in the below image are
already installed.
Install Appium
Step 2.3: Setup Android Environment Variables

1. Setup Android Environment Variables – Setup ANDROID_HOME

1.1 Click on Start menu. Then right click on Computer and select Properties option
Install Appium
Step 2.3: Setup Android Environment Variables

1. Setup Android Environment Variables – Setup ANDROID_HOME

1.2 This would open the System Properties window as shown below. Now from
the Advanced Tab, click on Environment Variables button
Install Appium
Step 2.3: Setup Android Environment Variables

1. Setup Android Environment Variables – Setup ANDROID_HOME

1.3 From the Environment Variables window, click on New button from System
variables section
Install Appium
Step 2.3: Setup Android Environment Variables

1. Setup Android Environment Variables – Setup ANDROID_HOME

1.3 Enter ANDROID_HOME in Variable Name field and SDK folder location
(C:\Users\Anish\AppData\Local\Android\sdk) in Variable value field as shown in
below image (Please enter the correct folder location that you have in your machine)
Install Appium
Step 2.3: Setup Android Environment Variables

1. Setup Android Environment Variables – Setup ANDROID_HOME

1.3 Click on OK button. ANDROID_HOME variable will now be added to System


variables
Install Appium
Step 2.3: Setup Android Environment Variables

2. Folder locations to be added to Path variable

In Android SDK folder, there are three specific folders that you need to add to the
Path variable. These folders are –

 platforms-tools folder which has path –


C:\Users\Anish\AppData\Local\Android\sdk\platform-tools

 tools folder which has path – C:\Users\Anish\AppData\Local\Android\sdk\tools

 bin folder inside tools folder with path –


C:\Users\Anish\AppData\Local\Android\sdk\tools\bin
Install Appium
Step 2.3: Setup Android Environment Variables

2. Folder locations to be added to Path variable


Install Appium
Step 2.3: Setup Android Environment Variables

2. Folder locations to be added to Path variable

Since we have already added ANDROID_HOME in System variables and its


represented by – C:\Users\Anish\AppData\Local\Android\sdk, hence all these above
three folder locations can be written as:

 %ANDROID_HOME%\platform-tools

 %ANDROID_HOME%\tools

 %ANDROID_HOME%\tools\bin
Install Appium
Step 2.3: Setup Android Environment Variables
To verify that all the Android Environment Variables are correctly setup, open
command prompt and run this command: sdkmanager – -list
Install Appium
Step 3: Appium tool setup
With the prerequisites completed, this section covers the Appium related content.
This mainly involves setting up the latest version of Appium, and setting up your
mobile device for test automation.

Step 3.1: Download and Install Appium Desktop App


Step 3.2: Download and Install Eclipse IDE for Java
Step 3.3: Turn On USB Debugging on your Android Device
Step 3.4: Download Appium Jars for Eclipse
Step 3.5: Create new project in Eclipse for Appium
Step 3.6: Find appPackage and appActivity name of your app
Step 3.7: First Appium test script to launch app on Android Device
Step 3.8: Learn more about Appium Desktop Client
Install Appium
Step 3.1: Download and Install Appium Desktop App
Appium Desktop in the new open-source GUI app that helps you access the Appium
Server using a graphical interface.

1. Open Appium Desktop‟s GitHub


page –
https://github.com/appium/appium-
desktop/releases
Install Appium
Step 3.1: Download and Install Appium Desktop App
2. Click on the windows version to download and save it on your machine
Install Appium
Step 3.1: Download and Install Appium Desktop App
3. Open the folder location where you have downloaded Appium Desktop and double
click on the exe to start the installation process. Appium will first ask you Installation
Options. Leave the already selected option as it is and then click on Install button
Install Appium
Step 3.1: Download and Install Appium Desktop App
4. Once the installation process starts, you will see the Appium Setup window as
displayed below
Install Appium
Step 3.1: Download and Install Appium Desktop App
5. Once installation is complete, you will see the below Appium Desktop window
Install Appium
Step 3.1: Download and Install Appium Desktop App
6. Now, leave the Run Appium checkbox selected and click on Finish button.
Appium Desktop Start screen will be displayed
Install Appium
Step 3.1: Download and Install Appium Desktop App
7. To verify that the installation and setup is successful, click on Start Server button.
This would start the Appium server and you would see „The server is
running‟ message in Appium window
Install Appium
Step 3.2: Eclipse IDE – Download and Install
Open this link – https://www.eclipse.org/downloads/eclipse-packages/
Install Appium
Step 3.3: Enable USB Debugging on Android Phone
Appium is not just limited to opening your app and performing some actions on it. It
provides many more functionalities in the way you interact with your app. One such
feature is that you can use Appium to install the app on your mobile phone using its
.apk file. To use this feature, it would be necessary to enable USB Debugging on
your device.

1. Take your Android device -> go


to Menu/Home -> search for the
Icon named “Settings”
Install Appium
Step 3.3: Enable USB Debugging on Android Phone
2. Click on the “Settings” Icon and scroll down through the list.
Under the sub-title “SYSTEM” check for an option named “Developer options”. If
you can see “Developer options” listed there, it means Developer options is already
enabled on your Android device.
Install Appium
Step 3.3: Enable USB Debugging on Android Phone
3. Click on the “About phone” option listed under the “SYSTEM”section at the end
of the list . When you click on the “About phone” option, you can see the list of
options as shown in the below image
Install Appium
Step 3.3: Enable USB Debugging on Android Phone
4. Click the “Build Number” option multiple times, till one of these messages
appear –
“You are now 2 steps away from being a developer”
“You are now 1 steps away from being a developer”
Install Appium
Step 3.3: Enable USB Debugging on Android Phone
5. Go to the “Settings” option of your phone and verify again, if you can see the
“Developer options” listed under the “SYSTEM” section as shown below
Install Appium
Step 3.3: Enable USB Debugging on Android Phone
6. Click the “Developer options” and check if “USB Debugging”checkbox is listed
under the sub-title “Debugging” as shown below:
Install Appium
Step 3.3: Enable USB Debugging on Android Phone
7. Tick the “USB Debugging” checkbox and click “OK” in the popup message. You
can see that “USB Debugging” has been enabled now as shown in the below image:
Install Appium
Step 3.4: Download Appium Java Client Jar
1. Open the official website for Appium – http://appium.io/. Click the “Downloads” tab
as highlighted in the below image.
Install Appium
Step 3.5: Create new project for Appium in Eclipse
1. Open the path where you have the unzipped Eclipse folder. Double click
on eclipse.exe to open it
Install Appium
Step 3.5: Create new project for Appium in Eclipse
1. Open the path where you have the unzipped Eclipse folder. Double click
on eclipse.exe to open it
Install Appium
Step 3.5: Create new project for Appium in Eclipse
2. Select File -> New -> Other… option from Eclipse IDE
Install Appium
Step 3.5: Create new project for Appium in Eclipse
3. In the New popup box, select Maven Project and then click on Next button
Install Appium
Step 3.5: Create new project for Appium in Eclipse
4. In the New Maven Project popup box, select Create a simple project and click
Next
Install Appium
Step 3.5: Create new project for Appium in Eclipse
5. In the New Maven Project popup box, input Group Id : “com.appium” and input
Artifact Id: “AppiumSetup” and then click Finish button.
Install Appium
Step 3.5: Create new project for Appium in Eclipse
6. Eclipse IDE should now look like something as shown below. It would display
your newly created project in the left side pane. If there are some additional
panes on the right side (Tasks List, Welcome screen etc), then you can close those
so that Eclipse IDE looks uncluttered
Install Appium
Step 3.5: Create new project for Appium in Eclipse
7. In the same project, click over pom.xml from left explorer menu. All dependencies
will be visible by default in 'pom.xml' tab. Refer to the Image below:
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.1.0</version>
</dependency>
Install Appium
Step 3.5: Create new project for Appium in Eclipse
8. To start with Appium script. Right click on 'src/main/java' from left side
explorer window. Then select New >> class. Write the Appium code inside the
selected class.
Understand Capabilities in Appium
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. Each Appium client builds capabilities in a way specific to the client's
language, but at the end of the day, they are sent over to Appium as JSON objects.
Understand Capabilities in Appium
deviceName: You need to set device name, so that the user agent would be your
device name. To know your device name, type „adb devices‟ in Terminal. Now set
the key as „deviceName‟ as „Samsung s5‟ as value. If you‟re using emulator just set
emulator name as value.

caps.setCapability(“deviceName”, “Samsung s5”);

platformName: It is used to set the mobile OS platform in which we‟re about to start
our session. You need to set „platformName‟ as key and „Android‟ as a value.

caps.setCapability(“platformName”,”Android”);
Understand Capabilities in Appium
platformVersion: It is used to set the mobile OS version. Each Android API has a
version. So you need to set „platformVersion‟ as key and „4.4.2‟ as value.

caps.setCapability(“platformVersion”,”4.4.2″);

appActivity: This is to set the Android activity that you want to launch from your
package. You need to set „appActivity‟ as key and „com.android.contacts‟ as value.

caps.setCapability(“appActivity”, “com.android.calculator2.Calculator”);

appPackage: This capability is for the Java package of the Android app that you want
to run. You need to set „appPackage‟ as key and your package name as value.

caps.setCapability(“appPackage”, “com.android.calculator2”);
Understand Capabilities in Appium
browserName: You need to invoke a browser to automate Mobile web apps. For
that you need to set „browserName‟ as key and your desired browser (chrome,
safari..) as value.
caps.setCapability(“browserName”, “Chrome”);

udid: Unique device identifier of the connected physical device.

caps.setCapability(“udid”, “121111sad”);

app: Appium will install the app binary on the appropriate device. You don‟t need this
capability, if you‟re using appPackage & appActivity. You need to pass „app‟ as key
and your local path(/home/test.apk) as value to set the capability”

caps.setCapability(“app”,”/Localpath/Your.apk”);
Understand Capabilities in Appium

Extracting Packages and Activities Android information

Adb shell

dumpsys window windows | grep -E „mCurrentFocus‟


Understand Capabilities in Appium

More Capabilities :
http://appium.io/docs/en/writing-running-appium/caps
Finding Mobile Elements
1. Locate Element using UIAutomatorViewer

2. Finding elements by ID

3. Finding elements by name

4. Finding elements by className

5. Finding elements by Xpath


Finding Mobile Elements
1. Locate Element using UIAutomatorViewer
We can find the UIAutomatorviewer in the Android SDK folder C:\android-
sdk\tools\bin; you can find the
same in Mac as well under the tools folder, as shown in the following screenshot:
Finding Mobile Elements
1. Locate Element using UIAutomatorViewer
To open uiautomatorviewer, you need to double-click on it. You will get the following
screen:
Finding Mobile Elements
1. Locate Element using UIAutomatorViewer
Now, we are going to take an example of finding
an element of the Android app calculator. We
need to perform the following steps:
1. Open the Android emulator or real device (For
a real device, we need to enable USB
debugging).
2. Open the calculator app.
3. Now, click on the device‟s screenshot icon
from the UI Automator Viewer window (The
progress information box will be visible.). If
more than one device is running, then
UIAutomatorviewer will ask you to select the
device to capture the screenshot. The
following is the screenshot of the calculator.
Finding Mobile Elements
2. Finding elements by ID
The method signature will be the same as the one we saw earlier to find an element
by ID for web apps:
findElement(By.id(String id));

We need to pass the ID of the element we want


to interact with. Here, we are going to find the
digit 5 from the calculator app using UI
Automator Viewer. We need to perform the
following steps:
 Click on the digit 5 from UI Automator
Viewer.
 Under Node Details, you will get resource-
id as
com.android.calculator2:id/digit5
Finding Mobile Elements
2. Finding elements by ID
The method signature will be the same as the one we saw earlier to find an element
by ID for web apps:
findElement(By.id(String id));

 We can use resource-id as an ID to


perform an action on the digit 5. This is
how the command will look:
WebElement
digit_5=driver.findElement(By.id("com
.android.calculator2:id/digit5"));
 To click on the digit 5, we can use the
following command:
digit_5.click();
Finding Mobile Elements
3. Finding elements by name
The method signature will be the same as the one we saw earlier to find an element
by name for web apps:
findElement(By.name(String Name));

 Click on DELETE from UI Automator Viewer.


 Under Node Details, you will get the text as DELETE. We
can use the DELETE text to locate the DELETE button as
Name. This is how
the command will look:
WebElement
delete=driver.findElement(By.name("DELETE"));

 To click on the DELETE button, we can use the following


command: delete.click();
Finding Mobile Elements
4. Finding elements by className
We can find an element using the className locator as well. This is how the method
signature looks:
findElement(By.className(String ClassName));
 Click on TextView from UI Automator Viewer
 Under Node Detail, you will get the class as
android.widget. TextView:
 We can use class as className to perform an
action on TextView. This is how the command will
look:
WebElement
textView=driver.findElement(By.className("an
droid.widget.TextView"));
 To get the value from the TextView, we can use
the following command: textView.getText();
Finding Mobile Elements
5. Finding elements by Xpath
Xpath is bit slower than the ID and name methods, but it is a very useful approach to
find an element. The method signature will look like this:
findElement(By.xpath(String XPath));

We need to pass the Xpath of the element we want to look for. It will return a
WebElement object that we can perform actions on. We are going to use the Xpath
of the digit 9; this is how the command will look:
WebElement
digit_9=driver.findElement(By.xpath("//android.widget.LinearLayout[1]/
android.widget.FrameLayout[1]/ android.widget.LinearLayout[1]/
android.support.v4.view.viewPager[1]/ android.widget.LinearLayout[1]/
android.widget.LinearLayout[1]/ android.widget.Button[3]"));
Automating Different Apps
1. The automation of Android native apps.

2. The Automated of Mobile Web app.

3. The Automated of Hybrid apps.


Automating Different Apps
1. The automation of Android native apps.
Step 1: Config appium desired capabilities

DesiredCapabilities cap = new DesiredCapabilities();


cap.setCapability("deviceName", "Samsung");
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "8.1.0");
cap.setCapability("appPackage", "com.sec.android.app.popupcalculator");
cap.setCapability("appActivity",
"com.sec.android.app.popupcalculator.Calculator");driver = new
AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Automating Different Apps
1. The automation of Android native apps.
Step 2: Implement action

MobileElement plus = (MobileElement)


driver.findElement(By.id("com.sec.android.app.popupcalculator:id/bt_add"));

plus.click();
Now, we need to perform click on the
element:
five.click();
plus.click();
four.click();
equalTo.click();
Automating Different Apps
1. The automation of Android native apps.
Automating Different Apps
2. The Automated of Mobile Web app.
Step 1: Config appium desired capabilities

DesiredCapabilities cap = new DesiredCapabilities();


cap.setCapability("deviceName", "Samsung");
cap.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "8.1.0");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), cap);
driver.manage().timeouts().implicitlyWait(80,
TimeUnit.SECONDS);
Automating Different Apps
2. The Automated of Mobile Web app.
Step 2: Implement action

Open http://google.com Input Search Keywork Search

driver.get("https://www.google.com");
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("Appium for mobile automation");
WebElement searchButton =
driver.findElement(By.xpath("//button[@jsname='Tg7LZd']"));
searchButton.click();
Automating Different Apps
2. The Automated of Mobile Web app.
You will automate https://google.com/ on Chrome on the Android
Automating Different Apps
3. The Automated of Hybrid apps.
Step 1: Config appium desired capabilities

DesiredCapabilities capabilities = new DesiredCapabilities();


capabilities.setCapability("deviceName", "Samsung");
capabilities.setCapability("platformVersion", “8.1.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.example.hybridtestapp");
capabilities.setCapability("appActivity", "com.example.hybridtestapp.MainActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Automating Different Apps
3. The Automated of Hybrid apps.
Step 2: We need to switch on the web view to take action on the registration form.
We can have the list of contexts using the following command:

Set<String> contexts = driver.getContextHandles();

Step 3: Now, switch on the web view using this command:

driver.context((String) contexts.toArray()[1]);
Automating Different Apps
3. The Automated of Hybrid apps.
Step 4: Implement action

WebElement firstName = driver.findElement(By.name("fname"));


firstName.sendKeys("test");
WebElement lastName = driver.findElement(By.name("lname"));
lastName.sendKeys("test");
WebElement age = driver.findElement(By.name("age"));
age.sendKeys("26");
WebElement username = driver.findElement(By.name("username"));
username.sendKeys("appiumTester");
WebElement password = driver.findElement(By.id("psw"));
password.sendKeys("appium@123");
WebElement registerButton = driver.findElement(By.id("register"));
registerButton.click();
Automating Different Apps
3. The Automated of Hybrid apps.
Practice with Appium

Given a sample test case with the following steps:

1. Open Startbucks app and tap Sign In item.


2. Verify Email textbox, Password textbox and Sign in button should be displayed.
3. Input Email, Password and get Error Message with conditions as bellows:
 Case 1:
Email: input blank value
Password: input “abcd”
 Case 2:
Email: input “abcd”
Password: input blank value
Practice with Appium

Given a sample test case with the following steps:

1. Open Tiki app and scroll to Tiki Deal.


2. Click the first product.
3. Click “Chon Mua” button.
4. Click “Xem Gio Hang” button.
5. Verify the name of product in Cart.
Practice with Appium

Given a sample test case with the following steps:

1. Open Tiki app and click to “Danh Muc”.


2. Scroll to the “Laptop – May vi tinh”
3. Click the “PC- May Tinh Bo”
4. Click the first product in “Ban Chay Nhat”
5. Verify the product name and price must be displayed.
Automation Test
Q&A

You might also like