Appium Configuration
Don't have any text to check? Don’t have any text to check?
Click "Select Samples”.
We will use Eclipse and TestNG framework to run
Appium automatic take a look at on automaton device/emulator. Let’s consider
conditions of this setup method.
Prerequisites:
1. Android SDK put in in system.
2. Appium (You will get this from official Appium
site)
3. ..NET Framework 4.5
4.
Eclipse / IntelliJ plan
5.
TestNG and Se a pair of JARs
We will begin set
up for Appium Android configuration. Follow below steps for the same.
- Install
JAVA 1.7 and above in your system.
- Set
the environmental variable JAVA_HOME to JDK home directory (Ex. C:\Program
Files\Java\jdk1.8.0_25)
- Append
%JAVA_HOME%\bin in PATH variable
- Install
Android SDK in your system.
- Set ANDROID_HOME environment variable
which points to your SDK directory’s \sdk folder.
- Append
%ANDROID_HOME%\tools; %ANDROID_HOME%\platform-tools; %ANDROID_HOME%\platforms;
value to your PATH environment variable.
- Start
your Android emulator or connect your Android device to your system (Make
sure you have Android Debugging option enabled in your Android device).
- Open
Command Prompt and navigate to your Android SDK’s \platform-tools\
directory (Eg. D:\adt-bundle-windows-x86_64-20130514\sdk\platform-tools).
- Run ‘adb devices’ command. You should
see your connected devices listed in Command Prompt window.
- Run ‘adb start-server’ command. It will
start ADB server which will be used by Appium to send commands to your
Android device.
- Now,
navigate to Appium directory in your system and begin Appium by clicking
Appium.exe file.
- Click
Launch button. Your Appium console ought to be displayed as below.
Appium Console
Starting Node Server
> Info: Welcome to Appium
v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
> Info: Appium REST http
interface listener started on 127.0.0.1:4723
- Create
a Java project in your Eclipse and reference Selenium 2 and TestNG JARs.
Create a new Java class in your project and enter below
code.
package com.appiumproj.test;
import
java.net.MalformedURLException;
import java.net.URL;
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.testng.annotations.AfterClass;
import
org.testng.annotations.BeforeClass;
import
org.testng.annotations.Test;
public class Appium {
WebDriver
driver;
@BeforeClass
public
void setUp () throws MalformedURLException {
DesiredCapabilities
capabilities = new DesiredCapabilities ();
capabilities.setCapability
("device", "Android");
capabilities.setCapability
(CapabilityType.BROWSER_NAME, "");
// Name of mobile web browser to
automate. Should be an empty string if automating an app instead.
capabilities.setCapability
(CapabilityType.VERSION, "4.4");
capabilities.setCapability
(CapabilityType.PLATFORM, "Windows");
capabilities.setCapability
("app-package", "APP PACKAGE"); //Replace with your app's
package
capabilities.setCapability
("app-activity", "APP PACKAGE.ANDROID ACTIVITY"); //Replace
with app's Activity
driver
= new RemoteWebDriver (new URL ("http://127.0.0.1:4723/wd/hub"),
capabilities);
}
@Test
public
void Cal () {
driver.findElement
(By.name ("Weather")).click ();
}
@AfterClass
public
void tearDown () {
driver.quit
();
}
}
- Run
your test using TestNG.
Troubleshooting -
Common Errors
1.
Error: A new session could not be created.
(Original error: 'java -version' failed. Error: spawn ENOENT)
Fix: Remove the spaces between SDK and ADT
paths.
Check adt is up and working using command
prompt type ‘adb-help’
2.
Error: No app set; either start appium with
--app or pass in an 'app' value in desired capabilities, or set androidPackage
to launch pre-existing app on device
Fix: The app-Package, platform desired capabilities provided were not
recognized by appium.
Check your desired capabilities: [caps]
platformName = "Android"
platformVersion = "4.4"
deviceName = "Galaxy S4"
appPackage = "com.example.android.sample1"
appActivity =
"com.example.android.learn.launch.activity.LaunchActivity"
app = "apps/android-learn-debug.apk"
you need at a minimum either the app or the
appPackage/appActivity. If you google aapt, you'll figure out how to get those.
3.
Error: Failed to start an Appium session, err
was: Error: Bad app: /Users/data/app/ /Facebook.apk.
Fix: App paths need to be absolute, or
relative to the appium server install dir, or a URL to compressed file, or a
special app name.
4.
Error: A session is either terminated or not
started (Original error: Could not find adb; do you have the Android SDK
installed and the tools + platform-tools folders added to your PATH?
Fix: you need to add the path to sdk folder
to the PATH variable and check again that the path to your .apk is the correct
one.
5.
If you
started the emulator, but the “ ./adb devices “ command returns no result, try
running:
Fix:
Sometimes there are issues connecting to the emulator, so you would need to
restart adb by performing the below instructions
“adb kill-server “
“adb start-server “
6.
IOS/Android
Driver casting on a shared test code base
Fix: You can declare AppiumDriver field in
the test code. It will be correct because Android Driver and IOS Driver both
extend AppiumDriver which is abstract now.
Sample Example
//it is parameterized test
public class AppiumJUnitTest {
//this is set up by given parameters before test is started
private AppiumDriver driver;
@Test
public void test () throws Exception {
//code which works against Android and iOS
}
}
7.
Prerequisites: Download Links