Académique Documents
Professionnel Documents
Culture Documents
Unique features:
1. You need not have to recompile the App or modify it in any way, due to use
of standard automation APIs on all platforms
2. You can use any testing framework (Junit, TestNG etc.,)
3. You can write the code in any language supported by Webdrvier
4. If you use Apples UI Automation library without Appium you can only write
tests using JavaScript and you can only run through the instruments
application. Similarly with Googles UIAutomator you can only write tests in
Java. Appium opens up the possibility of true cross-platform native mobile
automation. (Apples UI Automation API Library and Googles UIAutomator
API Library)
1
5. Common methods can be used in both Andriod and IOS this is cross-
platform feature
We can write test code and rely on a cloud service like Sause Labs to receive
and interpret commands.
Session:
2
Desired Capabilities:
Desired Capabilities are a set of keys and values. ( i.e., map or hash) sent to
the Appium server to tell the server what kind of automation session were
interested in standing up. There are various capabilities which can modify
the behavior of the server during automation. For example, we might set
the platformname capability to ios to tell Appium that we want an IOS
Session, rather than an Andriod one OR we might set the safariAllPopups
capability to true in order to ensure that during a Safari automation
session, were allowed to use JavaScript to open up new windows.
Appium Server:
Appium Clients:
There are client libraries (in Java Ruby, Python, PHP, JavaScript, and C#)
which support Appiums extensions to the WebDriver protocol when using
Appium, you want to these client libraries instead of your regular
WebDriver Client
There exist GUI wrappers around the Appium server that can be
downloaded. These come bundled with everything required to run the
Appium Server.
3
JSON wire protocol (commands pass through)
Appium Sever
Editor (Write Code)
Commands
Mobile
You can write appium code in any languag - Java, Python, Ruby, PHP, C#, Perl
Appium server act as a Proxy between the mobile you are testing and client
where you actually running the code.
Appium Server have the capabilities of Andriod Framework and IOS Framwork
They have inbuild capabilities
4
UI Automator frame work
3. https://developer.android.com/studio/index.html
8. Download Node.js
9. https://nodejs.org/en/download/
To open the AVD Emulator you can directly to it from command prompt.
5
Npm Node package manager it is an online repository for the publishing of
open-source Node.js projects; second, it is a command-line utility for interacting
with said repository that aids in package installation, version management, and
dependency management.
-g means globally
Once the Appium server installed start the server using the Appium
To uninstall Appium
Using npm you can download any node module Appium is one node module,
Angular JS is one node module and Protractor is one node module.
1. Appium Client Appium Java Client Jar You can write code in any
language Java, C#, Ruby, Python etc.,
2. Appium Server Is a unique and listens to client code. Common across any
client.
Appium client communicates with the Appium Server and executed the test cases.
6
2. Project can be treated as a Test Suite
You are ready to start the Appium code for mobile app testing using java
language.
Appium on MAC:
Installing XCode A set of development software tools Its an IDE. You Can
write and develop Apps. Xcode you can get it from AppStore
Installing Java
Installing Eclipse
Prerequisites:
7
First Appium Program:
You can test an app in emulator. Install the app in emulator and has to be
tested.
1. Open emulator
2. Invoke App
3. Connect to server
Android application package file (APK) is the file format used to distribute and
install application software and middleware onto Google's Android operating
system. APK files are ZIP file formatted packages based on the JAR file format,
with .apk file extensions.
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
8
public class Ribase {
capbs.setCapability(MobileCapabilityType.DEVICE_NAME,
"Demo");
capbs.setCapability(MobileCapabilityType.APP,
fil.getAbsolutePath());
9
Connection and Session:
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
AndroidDriver<AndroidElement> driver;
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,
"Rahulemulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
return driver;
}
10
}
Andriod UI Automater:
Using these tools we can get the objects and the properties.
C:\Users\sravana\AppData\Local\Android\sdk\tools\bin
Xpath Syntax:
//tagname[@attribute=value]
1. Index
2. text
3. resource-id
4. class
5. package
driver.getContext() This gives whether you are in Hybrid App, Native App or
11
driver.isLocked Check the mobile is locked or not
driver.pressKeyCode(AndroidKeyCode.BACK)
driver.pressKeyCode(AndriodKeyCode.HOME)
Interview Question:
Using pressKeyCode
Example
First you need to know the package name of that App. Every App has
unique package name.
Second you need to know the Main Activity. Each page has an activity and
defined as an activity.
The first page is the main launch activity.
12
Real Device Testing
According to industry experts like Gartner, you will get the most out of your
testing automation if you include a healthy mix of emulators, simulators, and real
devices as your mobile testing platforms. Why? Because there are aspects of the
mobile experience that you can't test on an emulator or simulator, like location-
based applications that use manufacture specific device sensors, memory
consumption, and CPU usage. There are a variety of use cases to consider when
you're deciding on the mix of emulators/simulators/real devices that you want to
use in your testing.
13
Need pixel perfect display testing Require extremely low error rates
Need to test hardware dependencies like for your test environment
CPU, memory, display, GPS, etc.
Need to test native ARM Libraries
Need to test on a custom OS (for example,
Samsung TouchWiz, OnePlus OxygenOS,
etc.)
Need to test on a native frameworks like
Espresso and Robotium
Code:
cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDR
OID);
14
// For real devices you need to change the Emulator Text to Device(check below)
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 100);
How do you cross check the anroid devices are connected to our system or not?
System.out.println(driver.findElementsByAndroidUIAutomator("new
UiSelector().clickable(true)").size());
Another feature that you wanted to verify the properties and the values
like Clickable, Checked, Enabled, Focused, Checkable etc., to check their
values for all the objects at a time, you can use new UiSelector()
15
System.out.println(driver.findElementsByAndroidUIAutomator("new
UiSelector().clickable(true)").size());
Android Gestures:
To capture the actions of android gestures like zoom in, zoom out, tap, drag etc.,
The important gestures in Android and Appium are Tap, Press, Release, Swipe,
drag and drop.
Note:
In x-path tag ifable to it contains any special characters like $ or @ or & it will not
consider and not able to identify the object or element. So you have to use the
regular expression in order to use the Xpath.
If you see the above tag, it contains $ symbol. So xpath is not valid.
Here you have to use the xpath as, means use * as a regular expression.
//*[@text=View]
16
To Scroll in emulator you have to use the below method:
driver.findElementsByAndroidUIAutomator("new UiScrollable(new
UiSelector()).scrollIntoView(text(\"WebView\"));");
17