1. Appium Testing API
Lecturer: Nguyễn Ngọc Tú
Members: Dư Nghĩa Hiệp
Phan Ngọc Thiện
Lưu Tấn Nguyên
Lê Thanh Tùng
Reviewer: Member of b4usolution
2. Agenda
Appium Philosophy and Design
Appium Philosophy
Appium Design
Appium Client-Server Architecture
Appium Session
Appium Desired Capabilities
Appium Server - Appium Client - Appium Desktop
Advantages of the CSA
Setup Android Project
3. Appium Philosophy and Design
1/25/20183
What is Appium ?
Appium is an open-source tool for
automating native, mobile web, and hybrid
applications on iOS and Android platforms
4. You shouldn’t have to recompile your app or
modify it in any way in order to automate it.
1/25/20184
Appium Philosophy
6. A mobile automation framework shouldn’t
reinvent the wheel when it comes to automation
APIs.
1/25/20186
Appium Philosophy
7. Appium Philosophy
A mobile automation framework should be open
source, in spirit and practice as well as in name!
1/25/20187
8. Appium Design
How does Appium implement these philosophies into the
architecture ?
• First point : the real work engine of Appium is actually a
third-party automation framework
• Second point, we encapsulate these third-party
frameworks into a set of APIs
1/25/20188
10. Appium Session
1/25/201810
• Automation is always performed in the
context of a session
• Send it by JSON object called “desired
capabilities” with POST method
11. Appium Desired Capabilities
1/25/201811
• Are a set of keys and values (like a
map/hash) send to the Appium server that
what kind of automation session we are
starting up.
• Example:
– Set platformName by iOS: it is an iOS
session.
– Then, set safariAllowPopups by true: to allow
safari open a windows by javascript
14. Appium Desktop
1/25/201814
• We don’t need to worry about Node
• Come in handy when writing tests.
• Note that Appium Desktop is not the same
thing as Appium.
• It is a graphical frontend to Appium with
additional tools.
15. Advantages of the CSA
• Write test code in any language that has a
http client API
1/25/201815
16. Advantages of the CSA
• Put the server on a different machine than
the one our tests are running on
1/25/201816
17. Advantages of the CSA
• Write test code and rely on a cloud service to
receive and interpret the commands.
1/25/201817
18. Compare
Apprium vs
1/25/201818
Robotium: a open source to automate UI
test case
UIAutomator: a UI testing framework suitable for
cross-app functional UI testing across system and
installed apps.
Expresso: provide api to simulate user
interaction
Calabash: execute automated acceptance
tests of mobile apps
27. Setup
1/25/201827
• platformName: Android
• platformVersion: Plug your android device,
then get its version
• deviceName: Your device name
• appPackage: Get it from your
Mainifest.xml
28. Setup
1/25/201828
• appActivity: It must be an activity you want
to test with. Simply, I pick up the first
activity. (MainActivity is default, but I
changed LoginActivity)
• automationName: In android, just use
UIautomator2
• noReset: Set true
• Save all.
29. Setup
1/25/201829
• Step 3: Configure Enviroment variables
• Open file .bash_profile by TextEdit
• Paste this:
31. Setup
1/25/201831
• JAVA_HOME: Your default java path, but we
must change the version based on your
current version
• Go to Terminal, type: java –version. My
version is 1.8
32. Setup
1/25/201832
• Step 4: Configure ADB
• In MAC OS, adb in terminal not show
when pluged Android Device into
computer
• Check it by open Terminal, type “adb
devices”, if you see “adb command not
found”. Continue typing:
brew cask install android-platform-tools
33. Setup
1/25/201833
• Step 4: Configure ADB
• Once finished, check again by typing “adb
devices”. As below is successfully
35. Setup
1/25/201835
• This help us find out element name, or
using recorder to record all our handles.
• It will generate our action by code, so we
can easier to write testscript.
36. Setup Android Project
1/25/201836
• In Android Studio, we need to write test
and run its automatically
• So we should download 2 library and
insert it in gradle by two method:
• Method 1: Download and add library
manually
– Selenium Webdrive Jar:
http://docs.seleniumhq.org/download/
41. Setup Android Project
1/25/201841
• Now, we continue to add AssertJ and
TestNG in gradle dependencies, then sync
it.
• Method 2: We also can add Selenium &
Java client via this way
44. Write Test Script
1/25/201844
• In this test, we have 3 annotations:
• @BeforeTest: Declare things before test,
such as connection data, wait for View,
Event,…
• @Test: All function having this annotation
mean doing in testing moment
• @AfterTest: After testing, what we will do
next? Quit, or nothing.
45. Write Test Script
1/25/201845
• From previous demo, I generated login
script. Now I embed it into java code
MobileElement el2 = (MobileElement)
driver.findElementById("restaurant.com.hsu.management:id/tvUsername");
el2.sendKeys("admin");
MobileElement el3 = (MobileElement)
driver.findElementById("restaurant.com.hsu.management:id/tvPassWord");
el3.sendKeys("123456");
MobileElement el4 = (MobileElement)
driver.findElementById("restaurant.com.hsu.management:id/btnLogin");
el4.click();
46. Write Test Script
1/25/201846
• LoginTestCase: Once I type username and
password correctly, my expected is the
screen moving the control panel screen.
49. Reference
1/25/201849
• Appium http://appium.io/introduction.html
• First Appium test script
http://www.automationtestinghub.com/first-appium-
test-script/
• Kiểm thử tự động ứng dụng trên Android P1
https://viblo.asia/p/su-dung-appium-trong-kiem-
thu-tu-dong-ung-dung-tren-android-p1-
L4x5xQWwKBM
• Kiểm thử tự động ứng dụng trên Android P2
https://viblo.asia/p/su-dung-appium-trong-kiem-
thu-tu-dong-ung-dung-tren-android-p2-
E375zbMR5GW
We meet requirement #1 by using vendor-provided automation frameworks under the hood. That way, we don’t need to compile in any Appium-specific or third-party code or frameworks to your app. This means you’re testing the same app you’re shipping. The vendor-provided frameworks we use are:
iOS 9.3+: Apple’s XCTest
Android 4.2+: Google’s UiAutomator
Android 2.3+: Google’s Instrumentation. (Instrumentation support is provided by bundling a separate project, Selendroid)
Windows: Microsoft’s WinAppDriver
We meet requirement #2 by wrapping the vendor-provided frameworks in one API, the WebDriver API. WebDriver (aka “Selenium WebDriver”) specifies a client-server protocol (known as the JSON Wire Protocol). Given this client-server architecture, a client written in any language can be used to send the appropriate HTTP requests to the server. There are already clients written in every popular programming language. This also means that you’re free to use whatever test runner and test framework you want; the client libraries are simply HTTP clients and can be mixed into your code any way you please. In other words, Appium & WebDriver clients are not technically “test frameworks” – they are “automation libraries”. You can manage your test environment any way you like!
We meet requirement #3 in the same way: WebDriver has become the de facto standard for automating web browsers, and is a W3C Working Draft. Why do something totally different for mobile? Instead we have extended the protocol with extra API methods useful for mobile automation.
It should be obvious that requirement #4 is a given – you’re reading this because Appium is open source. – From Appium website
There are client libraries (in Java, Ruby, Python, PHP, JavaScript, and C#) which support Appium’s extensions to the WebDriver protocol. When using Appium, you want to use these client libraries instead of your regular WebDriver client.