Appium Tutorial 2019 Edition is ready to all testers! I wrote a very comprehensive Appium Start Guide on 6t May 2016 and now it is time to write an updated Appium Tutorial. I will use Appium Desktop and Android Studio to create a sample mobile test automation project for you. After that, we will continue for Advance Appium Tutorial series. First, we need to do a proper Appium Installation. Alright, Let’s start!
Appium Tutorial Prerequisites: JAVA and Maven Installation
Download JAVA JDK first. Here is the Link: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Installation steps and configuration settings have described in this article at step-4 and step-5.
For MACOS users please visit the below article for all installation needs.
https://www.swtestacademy.com/how-to-install-appium-on-mac/
Windows users will go on with below installation steps. 😉
Android Studio Installation
You need to go to https://developer.android.com/studio/index.html and install Android Studio. After that, apply the following steps. Click the “Next” icons and finally click “Finish“.
Click “Download Android Studio For Windows“.
Click the next button.
Select all options and click the next button.
Select your directory or keep the default and click next.
and click install to start the installation process.
It is my first time to install Android Studio and I selected “Do not import settings” option and clicked the OK button.
Click next to continue.
I installed the Android Studio with standard settings and configurations.
Select your UI Theme. I prefer Darcula because it is better for the eyes.
Click “Finish” button and install the required tools.
Wait until all libraries download and installation finish.
After all these steps, click the finish button.
After clicking the “Finish” button. Go to “Configure” > “SDK Manager” to get SDK information. It is required for Android SDK path settings.
Select your device’s or emulator’s Android API level (Version).
And select the required tools as shown below and click “OK.
Click OK one more time, please. 😉
Click the finish button and continue.
After the installation of required tools, go to SDK Manager page and copy SDK path as shown below.
Download RapidEE tool and install it and open as administrator.
And then add ANDROID_HOME variable and its path should be Android SDK’s path. Also, check your JAVA_HOME variable. JAVA_HOME should equal to JAVA SDK’s path.
Then, you need to add required Android tools and JAVA JRE paths to your system path as shown below.
After that, check your settings and installations. Open a command prompt window and type “sdkmanager –list” command as shown below.
and type “uiautomatorviewer” to check uiautomatorviewer is working properly.
Then, create a sample project in Android Studio and then click the link as shown below to install missing libraries.
After installation, click the Finish button.
After installing missing libraries you will see the device and little and sweet android icon. 🙂 When you click this icon, you will open android virtual device manager.
Let’s create a virtual device. I will also explain how to do mobile automation with a real device too. Don’t worry. 😉 Click to “+ Create a Virtual Device” button.
Then, select a virtual device in the device list.
In this example, I selected Android 7.0. I have also a test device and its version is also 7.0 but you can select any of them. Click the download link and download the required libraries for the selected version.
After downloading the required libraries, click “next” to continue.
Check the latest settings and give a name to your Android Virtual Device (AVD) and click Finish button.
Then, click the run icon and launch your device.
You will see the selected AVD on your screen as shown below.
Until now, we installed JAVA and Android related libraries and did their settings and configurations. Now, it is time to download Appium.
Appium Desktop Installation and Configurations
Go to http://appium.io/downloads.html and click “Appium-Desktop for OSX, Windows and Linux” link.
On below page, click “appium-desktop-Setup-1.11.1.exe” file. (I am writing this article on 12.03.2019. The latest release is 1.11.1 now.)
When the installation file downloaded, click run and start to install appium desktop.
When installation finished, double-click the appium icon and open the appium server as shown below.
Let’s click the “Advanced” tab and change the Server Address as “127.0.0.1” and click Allow Session Override for override session when there will be problems and click “Start Server”. If you will use a real device and then use “0.0.0.0” for “Server Adress”.
Give the required permission to Appium Server.
You will see the server up and running.
Android Virtual Device and Pre-Test Settings
Let’s go to your android virtual device’s security page and give permission to install unknown sources as shown below.
Download a sample .apk file from APKPure. In this article, I will use our blue-collar recruitment app “İsin Olsun” as shown below.
When the .apk file is downloaded, drag and drop it into your AVD as shown below.
Then, you will see that it is installing. 😉
And yeap! it is installed. 🙂
When you click the app icon, you will see that it is opening as expected. 🙂
Normally, below command will give you the information about app package info and app activity info
1 | dumpsys window windows | grep -E 'mCurrentFocus' |
But for our application, our starting activity is splash activity and it is not easy to catch it. So I need to find another way to get the first app activity. I downloaded APK Info app and dragged-dropped to AVD and installed it.
Then, I opened the app and find our application “İşin Olsun“. When I pressed long to app icon, I saw a menu and clicked “Detailed Information“.
Then I saw all the information about our app. When I looked at the Activities section, I saw that our application is starting with “com.isinolsun.app.activities.SplashActivity“. I will use this info in automation code’s desired capabilities section. Also, I will use app package info which is “com.isinolsun.com”
Note: You can also install APK Anaylzer if APK info app did not work. You can easily find activities and all details with this application.
Then, open a command prompt and write “adb devices” command to see connected devices and get the device ID as shown below.
Go to your AVD’s setting tab and check your AVD’s Android Version as shown below. We will use these settings in our test project.
Then, open IntelliJ IDE and create a new project as shown below. First, select Maven and click Next.
Then, write your project’s GroupId and ArtifactId. You can write the same this as shown below. It does not affect anything, just naming.
Then, give a name to your project.
Then, click “Enable Auto-Import” at right bottom corner.
Go to mvnrepository.com website and get all frameworks lastest dependency information. We will use TestNG, Appium, Selenium.
Our POM.xml will look like as below. You can see appium’s, selenium’s, and TestNG’s dependencies.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>io-appium</groupId> <artifactId>io-appium</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <!-- https://mvnrepository.com/artifact/io.appium/java-client --> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>7.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> <!-- https://mvnrepository.com/artifact/org.testng/testng --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.14.3</version> <scope>test</scope> </dependency> </dependencies> </project> |
Create a new Java Class as shown below and give a name to your class.
Then get your device’s information from the android studio as shown below.
Then, go to the server and click the magnifier icon to open the inspector.
Then, start to enter the capabilities of your device as shown below in the inspector.
Also, you can save these settings and use them later.
and click “Start Session” to start the inspector session to get your mobile elements ids.
Get a mobile element’s id’s as shown below. We will use them for our first mobile automation project.
After all of these steps, we need to write our test automation code.
How to Use Real Device instead of Emulator
In emulators, you may face some problems. When I tried to run my test on emulator XPath locators did not work. Normally, I did not want to use XPath but in our app some for some elements I did not have other options. Then, I tried the same test on a real device, my test worked flawlessly and very fast. Thus, I suggest you use real devices instead of emulators. In order to use the real device we should do the followings:
- Connect your real device to your laptop via USB port.
- Go to Settings > Developer Settings and enable USB Debugging option.
- Open command prompt and type “adb devices” command and get your device ID.
Mobile Test Automation Project by Using Appium and TestNG
It is time to write some code for our Appium Tutorial. The test code of the project is shown below. I added inline comments. The most critical part is DesiredCapabilities, the rest of the code is very similar to Selenium & TestNG test automation codes. Also, you can find this project on GitHub.
Project’s GitHub URL: https://github.com/swtestacademy/appium-sample-test
Below code opens İsinOlsun app, skips splash screen, clicks “job search” button, then accepts notifications and then clicks the second job on the main screen and that’s all. 🙂 It is easy because it is our first test case.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; public class ioSampleTest { public AndroidDriver<MobileElement> driver; public WebDriverWait wait; //Elements String secondNewJob = "//android.widget.FrameLayout[2]/android.widget.LinearLayout/" + "android.widget.RelativeLayout/android.widget.ImageView"; @BeforeMethod public void setup () throws MalformedURLException { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("deviceName", "Galaxy Nexus API 24"); caps.setCapability("udid", "emulator-5554"); //DeviceId from "adb devices" command caps.setCapability("platformName", "Android"); caps.setCapability("platformVersion", "7.0"); caps.setCapability("skipUnlock","true"); caps.setCapability("appPackage", "com.isinolsun.app"); caps.setCapability("appActivity","com.isinolsun.app.activities.SplashActivity"); caps.setCapability("noReset","false"); driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"),caps); wait = new WebDriverWait(driver, 10); } @Test public void basicTest () throws InterruptedException { //Click and pass Splash wait.until(ExpectedConditions.visibilityOfElementLocated (By.id("com.isinolsun.app:id/animation_view"))).click(); //Click I am searching a job wait.until(ExpectedConditions.visibilityOfElementLocated (By.id("com.isinolsun.app:id/bluecollar_type_button"))).click(); //Notification Allow if (driver.findElements(By.id("com.android.packageinstaller:id/permission_allow_button")).size()>0) { driver.findElements(By.id("com.android.packageinstaller:id/permission_allow_button")).get(0).click(); } wait.until(ExpectedConditions.visibilityOfElementLocated (By.xpath(secondNewJob))); } @AfterMethod public void teardown(){ driver.quit(); } } |
That’s all for this Appium Tutorial. I hope you successfully installed and configured all settings and run your mobile automation code.
If you have any question please write a comment, me or another expert will help you.
Now, you can learn Appium Parallel Testing and How to Setup your Own Wireless Mobile Device Farm!
Appium Parallel Testing
Do you want to learn Appium Actions such as Tab, MultiTouch, Press, Swipe?
Appium Mobile Actions
Thanks.
-Onur
Hey Onur…such a great tutorial by u…very well described and easy to understand. Can u make a tutorial on how to setup appium(not desktop) on mac with latest release. a step by step guide to install appium and run sample code. it would help me or might other people who are working on mac a lot. Thanks in advance
Hi Mayur, I would like to but I don’t have MAC. 🙁 When I have one, I will do it. But it is not so hard. You can install appium with npm and use it with below command. Please also check this article. http://www.swtestacademy.com/appium-parallel-tests/ and go to “Alternative Way | Appium with Node.js”
Thanks Onur for your quick response…i will check and let u know. And i am very excited to perform http://www.swtestacademy.com/appium-parallel-tests this article at my end.
Welcome 🙂 and Good Luck! 😉
Hey Onur,
i was able to perform successfully the article “http://www.swtestacademy.com/appium-parallel-tests” on Windows but not on MAC. can u help me out
On MAC what kind of problem did you face? CAnberk Akduygu has MAC, I do not have. He may help you. 😉
Great article, we’re waiting more Turkish versions for other articles 🙂
Thanks Ufuk. I hope I can but it really takes too much time. I am trying to create a global software testing blog from our country. But also some new blogs are coming with Turkish content. I am happy for that. 🙂
Hi Onur,
As appium going to release Java client 6, can you please share the codes for gesture handling like scroll,swipe,zoom,pinch,page scroll, swipe without using objects etc?
Waiting for your response.
I am super busy Siddharth but I am so happy that Ahmet Samet Baltaci will prepare a document and we will share it on swtestacademy.com. 🙂 Thanks Ahmet.
Here is the article: http://www.swtestacademy.com/appium-mobile-actions-swipe-tap-press/
Hi Onur:
I have some issues trying to do the drag and drop.
I’m not able to do that.
Could you please help me?
Would you please try below code snippet?
TouchAction action = new TouchAction(driver);
action.longPress(elem1).waitAction(3000).moveTo(elem2).perform().release();
http://www.swtestacademy.com/appium-mobile-actions-swipe-tap-press/
Hi Mr. Onur,
While installing Android Studio, when I reached the “Verify Settings” step, the screenshot appears as below:
Current Settings
Setup Type
Standard
SDK Folder:
C:\Users\automation\AppData\Local\Android\Sdk
However, the “Verify Settings” page in your blog appears as follows:
Current Settings
C:\Users\onurb\AppData\Local\Android\Sdk
Total Download Size: 1.07 GB
SDK Components to Download:
Android Emulator 239MB
Android SDK Building –Tools 27.0.3 52.03MB
Android SDK Platform 27 62.7MB
Android SDK Platform Tools 4.52MB
Android SDK Tools 149 MB
Android Support Repository 339MB
Google Repository 205MB
Could you please explain if I may be doing something incorrectly causing this difference and if so, could you also please let me now what I need to do get the same information as in your document?
Thanks in advance,
Regards
Sai
I also noticed that “Android API 28” is “Partially Installed”
Hi Onur,
I just noticed that the 2 comments I left have been removed by moderator. Since the queries I posted are related to issues I am facing while installing the Android Studio following the instructions in your blog, would you please let me know if you want me to post them again?
Thanks and Regards
Satyasai
Hello Satyasai, I was sleeping, we did not remove them. I will check your problem and get back to you. Note: Comments are passing under moderation before publishing. That’s why you did not see your comments. 😉
Please check here: https://stackoverflow.com/questions/4771895/android-sdk-manager-not-installing-components
Your problem looks like a bit configurational and device related. Try to do a setup with administrative rights.
Hi Onur,
I think I resolved the issue by clearing the contents of the directory “C:\Users\automation\AppData\Local\Android\Sdk” and reinstalling.
Regards
Satyasai
Hi Onur,
Thank you so much for replying patiently to my queries. It is 1st time that I have seen blog authors take time to respond and that too so fast. Thanks also for pointing me to the stackoverflow site. Currently I am continuing with installing the 2 SDKs that did not get installed in the original, which I am doing individually – each taking hours. Thanks for sharing very clear and easy to follow instructions.
Regards
Satyasai
You are very welcome Satyasai.
Hello Onur,
There is a small typo. The “-list” in the command “sdkmanager -list” needs to be “–list” with 2 dashes instead of 1 dash as in “sdkmanager –list”. I noticed the 2 dashes when I viewed the screenshot from close.
Regards
Satyasai
Great! I hope you did all the steps. Good luck!
Thank you for your helpful tutorial, I have an error at the end of step-4 when I start a session, I see this message :
An unknown serverside message…cannot the app package.
I see the app in emulator close or somehow crashed!
how can I solve this issue? thank you again
please check here: https://github.com/appium/appium-desktop/issues/327