SlideShare a Scribd company logo
Appium
Getting started with Appium
&
Setup first Project.
Outline What is Appium?
Install Appium and other Tools
Setup the Project
Import my Project
What is Appium?
➔ APPIUM is a freely distributed open source mobile
application UI Testing framework. It is used to test
the UI of mobile application.
➔ Appium allows native, hybrid and web application
testing and supports automation test on physical
devices as well as on emulator or simulator both.
➔ It offers cross-platform application testing i.e. single
API works for both Android and iOS platform test
scripts.
How it works?
➔ It has NO dependency on Mobile device OS. Because, APPIUM has framework or wrapper
that translate Selenium Webdriver commands into UIAutomation (iOS) or UIAutomator
(Android) commands depending on the device type not any OS type.
➔ Appium supports all languages that have Selenium client libraries like- Java, Objective-C,
JavaScript with node.js, PHP, Ruby, Python, C# etc.
Appium architecture For more info. | http://appium.io/introduction.html
Install Appium
&
Other Tools
Installation of Appium differs on:
● Mac / Linux
● Windows
Note: We mainly focus on Windows Installation for
Android
STEPS(for Mac) :
> brew install node # get node.js
> npm install -g appium # get appium
> npm install wd # get appium client
> appium & # start appium
> node your-appium-test.js
Prerequisites: ANDROID_HOME variable must be saved and pointed to
Android SDK
NOTE: Here test written on JavaScript
Installation on
MAC / Linux
It is bit easy to install appium on Mac/Linux
compared to Windows
Installation on
Windows
We will be focused on Windows
Installation
Tools Needed
● Java
● Gradle
● Android SDK (Android Studio)
● Node.js
● Appium Desktop Server
● Intellij Idea
➔ Install Java from here
➔ Please check JAVA_HOME variable is saved and pointed to jdk
◆ You can check it by ‘java -version’ command on command prompt.
JAVA
➔ Gradle is an open-source build automation system that builds upon the concepts of Apache Ant
and Apache Maven. It is a JVM based build system
➔ Install the binary files from here
➔ Create a new directory ‘C:Gradle’ with File Explorer.
➔ Under System Variablesselect Path, then click Edit. Add an entry for C:Gradlegradle-X.Y.Zbin.
Click OK to save.
➔ Open a Windows command prompt and run gradle -vto run gradle and display the version
◆ $ gradle -v
------------------------------------------------------------
Gradle 4.5.1
------------------------------------------------------------
Gradle (Build Tool)
➔ Install Android Studio from here
➔ Install & Open Android Studio then download the needed Android SDK files from Tools > Android
> SDK Manager
➔ Under User Variablesthen click New. Add an entry for Variable: ANDROID_HOME and set Value:
Pathtosdk. Click OK to save.
➔ Verify it on Command prompt using echo %ANDROID_HOME% command, it must display the SDK path
Android SDK (Android Studio)
➔ Install Node.js from here
➔ You can verify installation by entering npm -v command on command prompt, it will display the
version
Node.js
➔ Download and Install Appium Desktop from here
➔ Open Android Desktop exe file and Start the server
➔ A Terminal should appear saying ‘The server is running’
Appium Desktop Server
➔ Download and Install IntelliJ Idea from here.
➔ Make sure TestNG plugin is installed and enabled
➔ This is the IDE we will be using for writing the Test Cases
Intellij Idea
Setup the
Project
IDE : IntelliJ Idea
Platform : Windows
Mobile OS : Android
Build System : Gradle
Prog. Lang. : Java
Create New
Project
1. Open IntelliJ Idea
2. Create New Project with Gradle and Java
3. Specify the GroupId and ArtifactId and
click on Next
4. Just make sure ‘Use default gradle
wrapper(recommanded)’ option must be
selected and Gradle JVM is specified. Then click
Next
5. Verify project name, location then click on
Finish
- It will build the project and IDE is ready to
use
1. You need to specify the
dependencies in build.gradle file
- Just open this link and copy paste
- You can learn more about gradle
here
Create Appium
Test Cases
In build.gradle file we have specified the dependencies, when build.gradle file executed by gradle daemon
it will download all the dependencies files from relevant server and import it to project. Below mentioned
files must be needed in order to run the appium test case.
1. TestNG: We are using this dependency although there is inbuilt support of it intelliJ
2. Selenium(Java): Appium is wrapper around Selenium, So it must be installed and imported
3. Appium Client(Java): This is the Java language binding for writing Appium Tests, conforms to
Mobile JSON Wire Protocol
View dependencies in build.gradle file here
Gradle Dependencies
2. Create Java Class for Appium Test case
- Right click on Java folder
- Create New > Java Class
1. Set location of the application to test in the desired capabilities of the test script.
2. Create an Appium driver instance which points to a running Appium server
3. Locate an element within the native application.
4. Perform an action on the element.
5. Anticipate the application response to the action.
6. Run tests and record test results using a test framework.
7. Conclude the test.
7 basic steps to create Appium test script
They tell the Appium drivers all kinds of important things about how you want your test to work. Desired
Capabilities are keys and values encoded in a JSON object.
{
"platformName": "Android",
"platformVersion": "8.0",
"deviceName": "devicename",
"appWaitPackage": "com.abc.xyz",
"appActivity": "com.abc.xyz.MainActivity",
"app": "/path/to/my.apk"
}
More about DesiredCapabilities: https://appium.io/docs/en/writing-running-appium/caps/
1) Desired Capabilities
In Java file you can set capabilities like below:
@Before
public void setUp() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“deviceName”, “devicename”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“platformVersion”, “8.0”);
capabilities.setCapability(“appPackage”, “com.abc.xyz”);
capabilities.setCapability(“appActivity”, “com.abc.xyz.MainActivity”);
}
Generally capabilities must be set at BeforeClass level, so when test execution get stareted capabilities set at
first.
In order to execute Appium Test Cases we need to start Appium Server first.
1. Just open Appium Desktop exe file and Start the Server
2. After setting the Desired Capabilities you need to create Appium driver instance, you can achieve this
using:
protected AppiumDriver<MobileElement> driver;
String appiumServerUrl = “http://localhost:4723/wd/hub”;
driver = new AppiumDriver<MobileElement>(new URL(appiumServerUrl), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
3. Driver is the main object for appium, you will extract the elements using it
2) Appium Server
There are various strategies to locate the element by css, name, id, class name, xpath, linkText etc.
But mostly used strategy in case of Android is resource-id
There are mainly 2 ways to find the locators for Mobile App.
1) Appium Inspector Session
2) Android SDK’s uiautomatorviewer
3) Locate an Element
1) Appium Inspector Session
● Start Appium Server
● Start Appium Inspector Session by
clocking on SearchBox icon
● Fill all needed Desired Capabilities
● Start Session
● Click on Any UI element you want the locator for and find the id on right side panel, you can use that
id on code for finding that element. You need to use driver instance for that.
● MobileElement el = driver.findElementById("com.google.android.apps.messaging:id/next")
2) uiautomatorviewer
● Move to Android_SDK/tools/bin, and
open uiautomatorviewer
● Click on any UI element you want
locator for and you will find all details,
pick the resource-id text
● You can use el instance perform various actions like click, type etc.
● el.click(); will click on element
● el.sendKeys("Test"); will type ‘Test’ on field
● el.getText()will return the text of element.
You can learn about webelement class here.
4) Perform an action on the Element
While using Appium(Selenium) for automated testing of web/mobile applications, we need to add validations
in our tests to report them as pass or fail. And assertions can let us do that within a single line of code.
Main goal of Test Case is to compare Actual value with Expected Value. We Call this Assertions.
For Assertions we need to use external libraries like TestNG or JUnit
There are primarily 2 types of Assertions we can make on Element(For UI Testing)
1) Compare the Text values of elements and verify the result
2) Verify whether expected element is present on UI
If you are using TestNG then there are two types of assertions. Hard and Soft assert, you can learn it here.
5) Anticipate the Application response
6) Run Tests
● Make Test cases using @Test
annotation
● Write the test case code and put
assertions
● Select Test case name and do right
click then do click on option Run ‘test
case name’
● It will execute the test case and
meantime you can see the logs for
details. You can also put debug points
between your code.
● At last build result and report will be
generated.
After test case execution build results and log will be generated, using it you will get to know that which test
cases have been passed or failed.
If your test case has failed then there can be 2 reason:
1) Problem with the code of Test Case
2) New changes introduced in app
From the analysis of the log and deep debugging you will get to know the exact root cause of failure and you
should fix that.
7) Conclude the test
Import my
Project
There is a sample project on Github, you can import it,
change some configuration and run:
◆ Download Project
◆ Connect Android device with PC properly
◆ Import project in IntelliJ
● Click on Import Project
● Select build.gradle file and click Next
● Make sure ‘Use default gradle wrapper’ &
Gradle JVM is selected properly.
● Change platform.android.version &
device.name in configuration.properties
file(according to connected device)
● Run test cases from TestCases.java file
Other similar project
Why Appium is Best?
As you can see, Appium has far more advantages
than do the other tools available on the market.
However, it’s definitely not perfect.
Any given instrument has its strong and weak sides,
let’s see it in brief in next slides.
Pros
● Appium supports Android and iOS platforms. Code, programming languages and user experience
remains the same for both.
● Appium doesn’t require any in-app modifications for testing. An application can be tested right
after it’s been downloaded and installed on the device.
● SauceLabs, the guys in charge of Appium, specify in creating various well-known open source
automation and manual testing solutions. As a result, Appium is frequently updated and each new
release includes new useful features and bug fixes.
● This tool allows automating web, native and hybrid applications, while also offering support for
various hardware actions.
● Appium supports all Webdriver-compatible programming languages: Java, Objective-C, JavaScript
with Node.js, PHP, Python, Ruby, C#, Clojure and Perl.
Cons
● Appium doesn’t support image recognition.
● Such hardware actions as swipe and gestures work only in native applications.
● It is impossible to execute parallel iOS tests. If you want to run tests on multiple devices at once,
you’d have to do so on the corresponding number of Mac OS PCs, as Macs only allow executing one
instance per device. This limitation may cause a lot of problems with Continuous Integration.
However, you could easily fix it by executing tests in the SauceLabs’ mobile cloud, which allows
running tests on multiple iOS simulators at once.
● It takes a long time to install and setup Appium for both iOS and Android.
● Appium’s got a very weak sort of documentation, which can be a pain for some engineers.
`
Assumptions
Viewer must have basic knowledge of:
● Testing
● Java
● Programming
Viewer must have(In order to execute the testcase)
● Connected Android working device with PC
Questions?
References
Appium Getting Started
Selenium
Gradle
TestNG
My Github Project
THANK YOU!
- PRATIK PATEL

More Related Content

Getting started with appium

  • 1. Appium Getting started with Appium & Setup first Project.
  • 2. Outline What is Appium? Install Appium and other Tools Setup the Project Import my Project
  • 3. What is Appium? ➔ APPIUM is a freely distributed open source mobile application UI Testing framework. It is used to test the UI of mobile application. ➔ Appium allows native, hybrid and web application testing and supports automation test on physical devices as well as on emulator or simulator both. ➔ It offers cross-platform application testing i.e. single API works for both Android and iOS platform test scripts.
  • 4. How it works? ➔ It has NO dependency on Mobile device OS. Because, APPIUM has framework or wrapper that translate Selenium Webdriver commands into UIAutomation (iOS) or UIAutomator (Android) commands depending on the device type not any OS type. ➔ Appium supports all languages that have Selenium client libraries like- Java, Objective-C, JavaScript with node.js, PHP, Ruby, Python, C# etc.
  • 5. Appium architecture For more info. | http://appium.io/introduction.html
  • 6. Install Appium & Other Tools Installation of Appium differs on: ● Mac / Linux ● Windows Note: We mainly focus on Windows Installation for Android
  • 7. STEPS(for Mac) : > brew install node # get node.js > npm install -g appium # get appium > npm install wd # get appium client > appium & # start appium > node your-appium-test.js Prerequisites: ANDROID_HOME variable must be saved and pointed to Android SDK NOTE: Here test written on JavaScript Installation on MAC / Linux It is bit easy to install appium on Mac/Linux compared to Windows
  • 8. Installation on Windows We will be focused on Windows Installation Tools Needed ● Java ● Gradle ● Android SDK (Android Studio) ● Node.js ● Appium Desktop Server ● Intellij Idea
  • 9. ➔ Install Java from here ➔ Please check JAVA_HOME variable is saved and pointed to jdk ◆ You can check it by ‘java -version’ command on command prompt. JAVA
  • 10. ➔ Gradle is an open-source build automation system that builds upon the concepts of Apache Ant and Apache Maven. It is a JVM based build system ➔ Install the binary files from here ➔ Create a new directory ‘C:Gradle’ with File Explorer. ➔ Under System Variablesselect Path, then click Edit. Add an entry for C:Gradlegradle-X.Y.Zbin. Click OK to save. ➔ Open a Windows command prompt and run gradle -vto run gradle and display the version ◆ $ gradle -v ------------------------------------------------------------ Gradle 4.5.1 ------------------------------------------------------------ Gradle (Build Tool)
  • 11. ➔ Install Android Studio from here ➔ Install & Open Android Studio then download the needed Android SDK files from Tools > Android > SDK Manager ➔ Under User Variablesthen click New. Add an entry for Variable: ANDROID_HOME and set Value: Pathtosdk. Click OK to save. ➔ Verify it on Command prompt using echo %ANDROID_HOME% command, it must display the SDK path Android SDK (Android Studio)
  • 12. ➔ Install Node.js from here ➔ You can verify installation by entering npm -v command on command prompt, it will display the version Node.js
  • 13. ➔ Download and Install Appium Desktop from here ➔ Open Android Desktop exe file and Start the server ➔ A Terminal should appear saying ‘The server is running’ Appium Desktop Server
  • 14. ➔ Download and Install IntelliJ Idea from here. ➔ Make sure TestNG plugin is installed and enabled ➔ This is the IDE we will be using for writing the Test Cases Intellij Idea
  • 15. Setup the Project IDE : IntelliJ Idea Platform : Windows Mobile OS : Android Build System : Gradle Prog. Lang. : Java
  • 16. Create New Project 1. Open IntelliJ Idea 2. Create New Project with Gradle and Java
  • 17. 3. Specify the GroupId and ArtifactId and click on Next 4. Just make sure ‘Use default gradle wrapper(recommanded)’ option must be selected and Gradle JVM is specified. Then click Next
  • 18. 5. Verify project name, location then click on Finish - It will build the project and IDE is ready to use
  • 19. 1. You need to specify the dependencies in build.gradle file - Just open this link and copy paste - You can learn more about gradle here Create Appium Test Cases
  • 20. In build.gradle file we have specified the dependencies, when build.gradle file executed by gradle daemon it will download all the dependencies files from relevant server and import it to project. Below mentioned files must be needed in order to run the appium test case. 1. TestNG: We are using this dependency although there is inbuilt support of it intelliJ 2. Selenium(Java): Appium is wrapper around Selenium, So it must be installed and imported 3. Appium Client(Java): This is the Java language binding for writing Appium Tests, conforms to Mobile JSON Wire Protocol View dependencies in build.gradle file here Gradle Dependencies
  • 21. 2. Create Java Class for Appium Test case - Right click on Java folder - Create New > Java Class
  • 22. 1. Set location of the application to test in the desired capabilities of the test script. 2. Create an Appium driver instance which points to a running Appium server 3. Locate an element within the native application. 4. Perform an action on the element. 5. Anticipate the application response to the action. 6. Run tests and record test results using a test framework. 7. Conclude the test. 7 basic steps to create Appium test script
  • 23. They tell the Appium drivers all kinds of important things about how you want your test to work. Desired Capabilities are keys and values encoded in a JSON object. { "platformName": "Android", "platformVersion": "8.0", "deviceName": "devicename", "appWaitPackage": "com.abc.xyz", "appActivity": "com.abc.xyz.MainActivity", "app": "/path/to/my.apk" } More about DesiredCapabilities: https://appium.io/docs/en/writing-running-appium/caps/ 1) Desired Capabilities
  • 24. In Java file you can set capabilities like below: @Before public void setUp() throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(“deviceName”, “devicename”); capabilities.setCapability(“platformName”, “Android”); capabilities.setCapability(“platformVersion”, “8.0”); capabilities.setCapability(“appPackage”, “com.abc.xyz”); capabilities.setCapability(“appActivity”, “com.abc.xyz.MainActivity”); } Generally capabilities must be set at BeforeClass level, so when test execution get stareted capabilities set at first.
  • 25. In order to execute Appium Test Cases we need to start Appium Server first. 1. Just open Appium Desktop exe file and Start the Server 2. After setting the Desired Capabilities you need to create Appium driver instance, you can achieve this using: protected AppiumDriver<MobileElement> driver; String appiumServerUrl = “http://localhost:4723/wd/hub”; driver = new AppiumDriver<MobileElement>(new URL(appiumServerUrl), capabilities); driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); 3. Driver is the main object for appium, you will extract the elements using it 2) Appium Server
  • 26. There are various strategies to locate the element by css, name, id, class name, xpath, linkText etc. But mostly used strategy in case of Android is resource-id There are mainly 2 ways to find the locators for Mobile App. 1) Appium Inspector Session 2) Android SDK’s uiautomatorviewer 3) Locate an Element
  • 27. 1) Appium Inspector Session ● Start Appium Server ● Start Appium Inspector Session by clocking on SearchBox icon ● Fill all needed Desired Capabilities ● Start Session
  • 28. ● Click on Any UI element you want the locator for and find the id on right side panel, you can use that id on code for finding that element. You need to use driver instance for that. ● MobileElement el = driver.findElementById("com.google.android.apps.messaging:id/next")
  • 29. 2) uiautomatorviewer ● Move to Android_SDK/tools/bin, and open uiautomatorviewer ● Click on any UI element you want locator for and you will find all details, pick the resource-id text
  • 30. ● You can use el instance perform various actions like click, type etc. ● el.click(); will click on element ● el.sendKeys("Test"); will type ‘Test’ on field ● el.getText()will return the text of element. You can learn about webelement class here. 4) Perform an action on the Element
  • 31. While using Appium(Selenium) for automated testing of web/mobile applications, we need to add validations in our tests to report them as pass or fail. And assertions can let us do that within a single line of code. Main goal of Test Case is to compare Actual value with Expected Value. We Call this Assertions. For Assertions we need to use external libraries like TestNG or JUnit There are primarily 2 types of Assertions we can make on Element(For UI Testing) 1) Compare the Text values of elements and verify the result 2) Verify whether expected element is present on UI If you are using TestNG then there are two types of assertions. Hard and Soft assert, you can learn it here. 5) Anticipate the Application response
  • 32. 6) Run Tests ● Make Test cases using @Test annotation ● Write the test case code and put assertions ● Select Test case name and do right click then do click on option Run ‘test case name’ ● It will execute the test case and meantime you can see the logs for details. You can also put debug points between your code. ● At last build result and report will be generated.
  • 33. After test case execution build results and log will be generated, using it you will get to know that which test cases have been passed or failed. If your test case has failed then there can be 2 reason: 1) Problem with the code of Test Case 2) New changes introduced in app From the analysis of the log and deep debugging you will get to know the exact root cause of failure and you should fix that. 7) Conclude the test
  • 34. Import my Project There is a sample project on Github, you can import it, change some configuration and run: ◆ Download Project ◆ Connect Android device with PC properly ◆ Import project in IntelliJ ● Click on Import Project ● Select build.gradle file and click Next ● Make sure ‘Use default gradle wrapper’ & Gradle JVM is selected properly. ● Change platform.android.version & device.name in configuration.properties file(according to connected device) ● Run test cases from TestCases.java file Other similar project
  • 35. Why Appium is Best? As you can see, Appium has far more advantages than do the other tools available on the market. However, it’s definitely not perfect. Any given instrument has its strong and weak sides, let’s see it in brief in next slides.
  • 36. Pros ● Appium supports Android and iOS platforms. Code, programming languages and user experience remains the same for both. ● Appium doesn’t require any in-app modifications for testing. An application can be tested right after it’s been downloaded and installed on the device. ● SauceLabs, the guys in charge of Appium, specify in creating various well-known open source automation and manual testing solutions. As a result, Appium is frequently updated and each new release includes new useful features and bug fixes. ● This tool allows automating web, native and hybrid applications, while also offering support for various hardware actions. ● Appium supports all Webdriver-compatible programming languages: Java, Objective-C, JavaScript with Node.js, PHP, Python, Ruby, C#, Clojure and Perl.
  • 37. Cons ● Appium doesn’t support image recognition. ● Such hardware actions as swipe and gestures work only in native applications. ● It is impossible to execute parallel iOS tests. If you want to run tests on multiple devices at once, you’d have to do so on the corresponding number of Mac OS PCs, as Macs only allow executing one instance per device. This limitation may cause a lot of problems with Continuous Integration. However, you could easily fix it by executing tests in the SauceLabs’ mobile cloud, which allows running tests on multiple iOS simulators at once. ● It takes a long time to install and setup Appium for both iOS and Android. ● Appium’s got a very weak sort of documentation, which can be a pain for some engineers. `
  • 38. Assumptions Viewer must have basic knowledge of: ● Testing ● Java ● Programming Viewer must have(In order to execute the testcase) ● Connected Android working device with PC