
How to setup appium in Android Studio
Tuesday, March 26, 2019
1 Comment
Appium is widely used automation testing tool for testing any kind of Mobile Applications it including Native, Hybrid and WebView applications also. This post will help you to setup Appium with Android Studio including how to write and test your first basic android application using Appium. If you are new with an android studio then don't worry about this. In this post, you will learn everything about setup Appium in your android studio. I hope after reading this post you will learn everything about the process of setup testing environment quickly. If you face any issue just comment your bugs below. Lets started with step by step guide mentioned below.
Step 1: Download Required Tools:
Step 2: Install Java, Android Studio and Appium desktop client
Step 3: After installing all essential software open Android Studio and Create a new project with your project name
Step 4: Add the Appium Jar file into your project
- Click on Project Section > Click on App >
- Change Project Structure From Android to Project by clicking on spinner available in left-hand side
READ ALSO
Step 6: Click on build.gradle in the app you will see all the libs added into the gradle file after that you need to rebuild the entire project after that you are ready to write and run your first test cases.
Step 7: Now its time write your first test case for android application. Now go to your directory structure shown below
Step 8: Right Click on Package and create new Java Class with the following code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.answerdone.MyAppiumProject; | |
import java.net.MalformedURLException; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.concurrent.TimeUnit; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.remote.CapabilityType; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.openqa.selenium.support.ui.ExpectedConditions; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
public class FirstTest { | |
WebDriver driver; | |
@Before | |
public void setUp() throws MalformedURLException { | |
// Created object of DesiredCapabilities class. | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
// Set android deviceName desired capability. Set your device name. | |
capabilities.setCapability("deviceName", "XT1562"); | |
// Set BROWSER_NAME desired capability. It's Android in our case here. | |
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android"); | |
// Set android VERSION desired capability. Set your mobile device's OS version. | |
capabilities.setCapability(CapabilityType.VERSION, "6.0.1"); | |
// Set android platformName desired capability. It's Android in our case here. | |
capabilities.setCapability("platformName", "Android"); | |
// Set android appPackage desired capability. It is | |
// com.answerdone.MyAppiumProject for Demo application. | |
// Set your application's appPackage if you are using any other app. | |
capabilities.setCapability("appPackage", "com.answerdone.MyAppiumProject"); | |
// Set android appActivity desired capability. It is | |
// com.answerdone.MainActivity for Demo application. | |
// Set your application's appPackage if you are using any other app. | |
capabilities.setCapability("appActivity", "com.answerdone.MainActivity"); | |
// Created object of RemoteWebDriver will all set capabilities. | |
// Set appium server address and port number in URL string. | |
// It will launch Demo app in android device. | |
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); | |
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); | |
} | |
@Test | |
public void testFirstButton() { | |
// Click on DELETE/CLR button to clear result text box before running test. | |
driver.findElements(By.xpath("//android.widget.Button")).get(0).click(); | |
// Click on number 2 button. | |
driver.findElement(By.name("7")).click(); | |
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); | |
} | |
@After | |
public void End() { | |
driver.quit(); | |
} | |
} |
Step 9: Open Your Appium Server and configure accordingly and run FirstTest.java Testcase
Best Book for Entrepreneur ==> Strategies To Build Successful Web Agency
trabzon
ReplyDeleteedirne
van
bingöl
yalova
3JFX