-
Notifications
You must be signed in to change notification settings - Fork 2
Setup ‐ Android
This page contains information for setting up local Android environment for running automated tests against Android Emulators. You will find information for setting up latest appium with AVD Emulator / Genymotion Emulator.
The example below will be done for windows machine but it is almost the same for other OS.
- Download and install latest jdk for your OS - Download Link
- Download & Install latest node distribution for your OS - [Download Link] (https://nodejs.org/en/download/)
- Add npm and nodejs paths in your PATH environment variable.
- Set JAVA_HOME to be your JDK path. The bin in that directory should be added to your PATH variable.
- Install the Android SDK.
- Set the ANDROID_HOME environment variable to be your Android SDK path and add the tools and platform-tools folders to your PATH variable.
If you have existing emulator you can skip the next section and proceed to Install Appium.
- Go to your AndroidSDK folder
- Start SDK Manager.exe
- Download & Install needed APIs (for example android 6 is API 23 / android 7.0 is API 24 / android 7.1.1 is API 25). You can download
- Start AVD Manager.exe
- Create an emulator based on default templates or you can create an emulator with custom settings. If you want a custom emulator then you can do it on the fly - just get the values. An example for creating Samsung Emulator can be found here
- If you use Google APIs Intel Atom for CPU emulation then the emulator will have Chrome browser installed by default. However, there is a chance when you start Chrome to see Welcome To Chrome screen which might break the tests. In this case you can create an emulator via ARM and to manually install Chrome browser via Drag&Drop. Then you will be able to run the tests against latest chrome version.
Genymotion Emulator is free for personal use but if you want to use it for any other purpose you need to buy a license. Genymotion Pricing Information can be found here
The steps below provides information about setting up Genymotion Emulator:
- Create an account here
- Download the application with / without virtual box (depends whether you have or not have virtual box on your machine)
- Install the downloaded app.
- Once you start Genymotion application you will have to sign in with your account
- Select Settings -> ADB and put the path to your AndroidSDK folder
- Click on Add button and download emulator that you want
- Once the emulator is downloaded it will be available for you to play with it.
Note - Genymotion emulators comes without Google Api which means that you need to install it manually. In order to do that you can check here
Once you do the steps above in order to install Google API you should install Chrome browser. Here you have two options:
- Install latest Chrome browser version via google play
- Install specific Chrome browser version manually. This can happen with the steps below:
- Open http://www.apkmirror.com/apk/google-inc/chrome/
- Find the version you want and download the variant for x86 architecture
- Drag&Drop the apk on the emulator
- Wait to install and restart the android emulator
- Stop all auto updates on the emulator
- Restart the emulator
- Emulator is ready
If you need other applications with specific version you can check here.
Note: If you install Google Play + Chrome then you will have a problem with starting the browser if Chrome is higher than version 48. If you want to run against latest Chrome browser you can do the following:
- Download Genymotion Emulator
- Install Genymotion-ARM-Translation via Drag&Drop - Download Link
- Install Chrome browser manually via Drag&Drop Then you will be able to run the tests against the latest Chrome Browser Version
Installing appium is really easy. You can find few examples below which could be useful in different situations
- Installing latest appium version in npm.
# Open command prompt as admin user.
npm install -g appium
- Install specific appium version from npm.
# Open command prompt as admin user.
npm install -g appium@1.6.3
Once appium is installed we have to install other dependencies which are needed in order to run the tests:
- Install appium-doctor
npm install -g appium-doctor
- Execute appium-doctor
appium-doctor --android
It is recommended to run appium-doctor once it is installed in order to see what is left in terms of environment setup!
In order to start appium you can run the command below. It will start appium and it will listen for request on http://0.0.0.0:4723/wd/hub url. Basically it will start appium with all default options / configs.
appium
As you can see from the examples above the minimim capabilities that you need to provide are:
- PLATFORM_NAME - it should be Android
- PLATFORM_VERSION - this is the Android Emulator OS version that you want to execute.
- DEVICE_NAME - this is the name of the device that you want to start.
- Genymotion Emulator - you should set the name of the emulator Samsung Galaxy S7
- AVD emulator - you should set Android Emulator
- Chrome - it is used to start chrome browser on the emulator. If Chrome is not installed on the emulator it will fail
- Browser - it is used to start native android browser. If it is not installed (for example 7.* versions) it will fail
Below you can see two examples with Genymotion emulator and AVD emulator.
If you want to run it against native android browser just change the commented lines from the examples below
// capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
and comment chrome options
// ChromeOptions options = new ChromeOptions();
// options.addArguments("ignore-certificate-errors");
// options.addArguments("disable-translate");
// capabilities.setCapability(ChromeOptions.CAPABILITY, options);
private DesiredCapabilities getGenymotionCapabilities(){
DesiredCapabilities capabilities = new DesiredCapabilities().android();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Samsung Galaxy S7");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
// capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
capabilities.setCapability(MobileCapabilityType.PLATFORM, Platform.ANDROID);
capabilities.setCapability("fastReset", true);
ChromeOptions options = new ChromeOptions();
options.addArguments("ignore-certificate-errors");
options.addArguments("disable-translate");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return capabilities;
}
If you want to run a test you can do this (be sure that emulator is started and loaded properly before starting the test):
public void appiumGenymotionExample() throws Exception {
DesiredCapabilities capabilities = getGenymotionCapabilities();
WebDriver webDriver = new IOSDriver(new URL("http://localhost:4723/wd/hub"),
capabilities);
webDriver.get("http://detectmybrowser.com/");
}
private DesiredCapabilities getAVDCapabilities(){
DesiredCapabilities capabilities = new DesiredCapabilities().android();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "6.0");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
// capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
capabilities.setCapability(MobileCapabilityType.PLATFORM, Platform.ANDROID);
capabilities.setCapability("fastReset", true);
ChromeOptions options = new ChromeOptions();
options.addArguments("ignore-certificate-errors");
options.addArguments("disable-translate");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return capabilities;
}
If you want to run a test you can do this(be sure that emulator is started and loaded properly before starting the test):
public void appiumAVDExample() throws Exception {
DesiredCapabilities capabilities = getAVDCapabilities();
WebDriver webDriver = new IOSDriver(new URL("http://localhost:4723/wd/hub"),
capabilities);
webDriver.get("http://detectmybrowser.com/");
}
WIKI
How To - Local