Escolar Documentos
Profissional Documentos
Cultura Documentos
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.
Mobile
Appium Sever
Editor (Write Code) Commands 3
App
1. Client will send the commands as sessions objects which is headless
2. It send the commands through JSON wire protocol
3. Appium server acts as a proxy between Editor and Mobile App
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
Appium Installation and Set Up:
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
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
1. Download Appium jar file Go to the site http://appium.io/downloads.html
and click on Client Libraries Lets say in our case Java
2. It will navigate to the site: https://search.maven.org/#search%7Cga
%7C1%7Cg%3Aio.appium%20a%3 Ajava-client
3. Click on jar under download column
4. Then go to http://www.seleniumhq.org/download/ and download the
Selenium Client & Webdriver language bindings for Java language
5. Open eclipse right click on Project folder and go to properties go to Java
build path and libraries and get the jars for Appium and Selenium.
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
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
// TODO Auto-generated method stub
capbs.setCapability(MobileCapabilityType.DEVICE_NAME,
"Demo");
capbs.setCapability(MobileCapabilityType.APP,
fil.getAbsolutePath());
import java.io.File;
import java.net.MalformedURLException;
9
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;
}
Andriod UI Automater:
Using these tools we can get the objects and the properties.
C:\Users\sravana\AppData\Local\Android\sdk\tools\bin
10
Go to this path, you find the UI Automator and click on UI Automator
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
To go back to Home page or to go back to the previous page in Android Mobile,
we need to use the below code:
driver.pressKeyCode(AndroidKeyCode.BACK)
driver.pressKeyCode(AndriodKeyCode.HOME)
Interview Question:
Using pressKeyCode
2. If you know the app package and main activity of the app. With the help of
these two we can invoke the app without need of .apk file
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.
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 to replicate an issue to match Want to save costs
exact model as reported Need immediate availability
Need pixel perfect display testing Require extremely low error
Need to test hardware rates for your test environment
dependencies like 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.)
Code:
cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDR
OID);
14
cap.setCapability(MobileCapabilityType.DEVICE_NAME, Android Emulator);
// 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
//Validate clickable features for all options
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.
16
//*[@text=View]
driver.findElementsByAndroidUIAutomator("new UiScrollable(new
UiSelector()).scrollIntoView(text(\"WebView\"));");
17