I am new to mobile testing. I want to configure appium for testing android applicaiton on Mac machine. Can someone provide the steps to do. And I want to using with selenium webdriver using Java.
I have started working on mobile test automation and had to do lot of research. I found it really difficult to get resources on BDD (Behavior Driven Development), Cucumber, Appium setup. After slogging for a month and documenting everything I did, I was finally able to start doing automation. I believe other testers could be suffering like me, so here are step by step instructions to set up Appium+Cucumber+Java. Enjoy and let me know in case of any questions
This page gives step by step instructions to set up your Mac/Windows machine with Cucumber+Jave+Appium framework.
TABLE OF CONTENTS
- Components needed for ATDD Automation
- Installation Instructions Mac and Windows
- Android Specific Instructions
- Steps to Ensure Environment is Setup Correctly for ATDD Automation
- Steps for Manual Installation of Cucumber and Appium JAR files
- Cucumber Learning Resources
COMPONENTS NEEDED FOR ATDD AUTOMATION
The following components need to be installed
- Homebrew
- Node.js
- Appium (command line)
- Appium UI application
- Android Studio (With Android SDK)
- Set up ANDROID_HOME
- Android Emulator
- Java JDK
- Set up JAVA_HOME
- Xcode
INSTALLATION INSTRUCTIONS
Step 1- Install HomeBrew from this link – http://brew.sh/index.html. Copy and paste the command under “Install Homebrew” section in the Terminal/Command Line.
Step 2- Install Node.js and Appium Server.
For Mac Users:
Type the following commands in the Terminal/Command Line.
- brew install node
- npm install -g appium
- npm install wd
For Windows Users:
- Go to https://nodejs.org/en/download/
- Download Node.js
- After installation of Node.js type in the below commands
- npm install -g appium
- npm install wd
Step 3- Install Appium UI application from this link – http://appium.io/downloads.html.Click the Desktop Apps based on Mac/Windows machine. Download and Install appium-1.4.13.dmg file or AppiumForWindows_1_4_16_1.zip based on Mac/PC user.
NOTE: Sometimes you have problems when downloading appium through Chrome. So it is recommended you use Safari or Firefox
For Mac Users:
- Ensure you drag the appium folder to the application folder when asked
- Appium will get copied to the Applications folder
For Windows Users:
- Double click on appium_installer.exe from the Download folder as show below
Step 4- Install Android Studio from this link – http://developer.android.com/sdk/index.html.
For Mac Users:
- Click on “Download Android Studio” link and agree to the license.
- After Download and Installation make sure to drag the Android Studio icon to the Application folder
- Open Android Studio and Click on “I Do not…” option in the window and let packages download. Wait till the download is complete
- Minimize Android Studio and go to Step 5
For Windows Users:
- Open Android Studio and Click on “I Do not…” option in the window and let packages download. Wait till the download is complete
- Minimize Android Studio and go to Step 5
Step 5- Install Java JDK form this link – http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html.
- Navigate to “Java SE Development Kit 8u66” and download the necessary file based on Mac/Windows
- Then install it after download by double clicking.
NOTE: Ensure Step 5 is Completed before going to Step 6
Step 6- In Terminal/Command Line type “open .bash_profile“. We do this to set the JAVA_HOME and ANDROID_HOME path. Once the profile opens type paste the following information with the correct path information and save the file.
For Mac Users:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
export ANDROID_HOME=/Users/<YOUR USERNAME>/Library/Android/sdk or
/Users/<YOUR USERNAME>/Library/android-sdks (Based on where the Android SDK is installed)
To ensure the paths are set correctly, please type close the current terminal. Open a new terminal window and type the following
$JAVA_HOME in the terminal. The above JAVA_HOME path set should be displayed
$ANDROID_HOME in terminal. The above ANDROID_HOME path set should be displayed
NOTE: If you cannot find .bash_profile, you need to create one. You can create one by following the below steps
Go to cd /Users/<Username>
Type touch .bash_profile
Type open -a TextEdit.app .bash_profile
For Windows Users:
Go to Start Menu-> Computer->System Properties->Advanced System Properties
Go to Advanced tab->Environment Variables
Set the JAVA_HOME and ANDROID_HOME Path
Usually JAVA_HOME is set to C:Program FilesJava<your jdk version>
ANDROID_HOME is under C:Users<your username>android-sdk-windows
Step 7- (Not required for training but needed to run automation on iPhone simulator) Install Xcode from this link – https://developer.apple.com/xcode/download/. For windows users please go through this video –
https://www.youtube.com/watch?v=sb8BdYH4esQas we need virtual machine to install Xcode unlike Mac Users.
Step 8-Navigate to the below sections based on your machine.
Android Specific Instructions
- Open an android project in Android Studio. Keep clicking on Next button till the project loads up in the editor.
- First time the project is opened and when asked for a SDK, please point it to JDK1.7 or 1.8 based on what JDK version you have.
- The project will indicate missing libraries and may throw errors. Click on the prompt shown by Android Studio to download them automatically on the top right corner of the screen. If you face problems in this please go to last section in this page “Cucumber and Java JAR files and follow the step by step instructions to ensure libraries are installed correctly.
- Go to Android Studio and open “SDK Manager” and ensure you install all the necessary packages
- Go to Terminal/Command Line. Type in the following
- $ANDROID_HOME and press Enter
- Copy the path
- Type cd <path name from above>
- Type cd tools
- Type ./android avd to open the “Android Virtual Device Manager”.
- In the AVD Manager click the “Device Definitions” tab
- Choose “Nexus 4” and select “Create AVD”
NOTE: You need to select “Google API’s Intel Atom (x86)” in the CPU/ABI: field. If you do not see it in the above screen, then go back to the android SDK manager and make sure the package “Intel x86 Atom_64 System Image” and “Intel x86 Atom System Image is installed
- Click “OK” in the window which pops up
- Click on the newly created device and then press “Start”. The emulator should open up showing the default android home page. This ensure that the emulator is set up correctly
- Turning off locking on the emulator
- Ensure locking is turned off on the android emulator. To turn off locking follow the below steps
- Navigate to Settings-> Security->Screen Lock-> Select “None”
- Ensure locking is turned off on the android emulator. To turn off locking follow the below steps
- Go to Android Studio-> Preferences
- Click on Plugins
- Search for “Cucumber for Java” and you should see it checked in the list. If not install it by checking it.
- Search for “Gherkin” and you should see it checked in the list, If not install it by checking it.
- Click on “Apply” and “OK”
- Now the cucumber and appium framework should be configured with Android Studio. If not ensure you follow the JAR installation steps mentioned in the Cucumber and Appium JAR files section of the Wiki which can be found below
TO ENSURE THE ENVIRONMENT IS SET UP CORRECTLY – (PLEASE READ)
To ensure your laptop set up is correct please do the following-
- Check Step– Ensure Appium is setup correctly
For Mac users:
Open the Terminal and type “appium” you should see some prompts. This ensures appium is set up correctly
For Windows Users:
Open the command prompt and type the below commands –
cd C:Program Files (x86)Appiumnode_modulesappiumbin
node appium
This will launch the appium server and this ensures appium is setup correctly
Manual Installation of Cucumber and Appium JAR
Cucumber and Appium JAR files (Files need to get the Cucumber and appium framework in Android Studio)
When Android Studio is opened, you should have automatically got a prompt to import all the dependencies and files. If that did not work properly please import the JAR files manually into Android Studio (NOTE: Download the Cucumber and Appium related JAR Files and save it in a location) . The steps are provided below
- Click on File-> Project Structure
- Navigate to Platform Settings -> SDKs
- Click on the folder “1.8” and click on the “+” sign as shown below
- Navigate to the location where your downloaded the files and click “OK”
- You should see your new JAR files added in the list
- Then click “OK”
- Go to Android Studio-> Preferences
- Click on Plugins
- Search for “Cucumber for Java” and you should see it checked in the list. If not install it by checking it.
- Search for “Gherkin” and you should see it checked in the list, If not install it by checking it.
- Click on “Apply” and “OK”
- Now the cucumber and appium framework should be configured with Android Studio
CUCUMBER LEARNING RESOURCES
The following is a list of possible Selenium capabilities you can use when executing tests across CrossBrowserTesting’s service.
Selenium Capabilities – Desktops
Key | Values* | Capability |
---|---|---|
browserName | chrome, firefox, safari, internet explorer, edge | The name of the browser for your test. REQUIRED |
version | Ex: 60, 60×64, 59, etc. | The browser version for the browser name specified above. Must be a valid version. Can be “latest”, “latest-1”, “latest-2” for one of latest three versions. If not provided will default to “latest”. |
platform | Windows 10, Windows 8.1, Windows 8, Windows 7 64-Bit, Windows 7 Mac OSX 10.12, Mac OSX 10.11, Mac OSX 10.10 | Platform selected for testing. If no platform is selected, we’ll default to an appropriate OS for the browser chosen. Standard selenium platforms are also supported: Windows, XP, Vista, Win7, Win8, Win8.1, Win10 Mac, Mac Os, Os X, macOS, Mountain Lion, Mavericks, Yosemite, El Capitan, Sierra |
screenResolution | Ex: 1024×768, 1600×1200 | The preferred resolution of the OS for the test. The default is 1366×768. |
Appium Capabilities – Mobile Devices
Key | Values* | Capability |
---|---|---|
browserName | chrome, safari | The name of the browser for your test. REQUIRED There is only one version of the browser per device, so no version number can or needs to be specified. |
platformName | iOS, Android | This field is a convention for matching appium-style capabilities but is not required by our system. It is a good idea to include with scripts that may be run against different remote servers. |
platformVersion | Ex: 7.0, 9.3, etc | The version of the mobile OS. This should match the appropriate device below. At this time we only offer one OS version per device so can be safely dropped if you are unsure. |
deviceName | Android Platforms: Nexus 9, Pixel 3, Pixel 2, Galaxy S8, Galaxy S7, Nexus 6 iOS Platforms: iPhone 7 Plus Simulator, iPhone 7 Simulator, iPhone 8, iPhone X, iPhone XR, iPhone 6s Plus Simulator, iPhone 6s Simulator, iPad Pro Simulator, iPad Air 2 Simulator, iPad 6th Gen | The name of the device. Should match the browserName such that Chrome is for Androids, and Safari is for iPads and iPhones. If not provided, the most recent device will be used for the browserName specified. |
deviceOrientation | landscape, portrait | Will default to portrait for phones and landscape for tablets. |
CrossBrowserTesting-Specific Capabilities
Key | Values | Capability |
---|---|---|
name | Ex: Login Form Test | Name of your test. |
build | Ex: 2.4 | Number of the build within your test. |
record_video | true, false | Start a video recording of your screen during the test session. (max length 10 minutes) |
record_network | true, false | Start a recording of your network packets during the test session. |
max_duration | Ex. 1200 | Max test length in seconds. Use to refrain from timing out during long tests. Default is 30 minutes. |
idle_timeout | Ex. 100 | Use to end test if a command is not received in a certain amount of time. Default is 3 minutes. |
timezone | Ex. GMT+06:00 | Timezone set on the browser. A full list of values can be found here. |
Default Selenium Capabilites
Key | Value | Capability |
---|---|---|
javascriptEnabled | true, false | Whether the session supports executing user supplied JavaScript in the context of the current page (only on HTMLUnitDriver). |
databaseEnabled | true, false | Whether the session can interact with database storage. |
locationContextEnabled | true, false | Whether the session can set and query the browser’s location context. |
applicationCacheEnabled | true, false | Whether the session can interact with the application cache. |
browserConnectionEnabled | true, false | Whether the session can query for the browser’s connectivity and disable it if desired. |
webStorageEnabled | true, false | Whether the session supports interactions with storage objects. |
acceptSslCerts | true, false | Whether the session should accept all SSL certs by default. |
rotatable | true, false | Whether the session can rotate the current page’s current layout between portrait and landscape orientations (only applies to mobile platforms). |
nativeEvents | true, false | Whether the session is capable of generating native events when simulating user input. |
proxy | proxy object | Details of any proxy to use. If no proxy is specified, whatever the system’s current or default state is used. The format is specified under Proxy JSON Object. |
unexpectedAlertBehaviour | accept, dismiss, ignore | What the browser should do with an unhandled alert before throwing out the UnhandledAlertException. |
elementScrollBehavior | integer | Allows the user to specify whether elements are scrolled into the viewport for interaction to align with the top (0) or bottom (1) of the viewport. The default value is to align with the top of the viewport. Supported in IE and Firefox (since 2.36) |
Chrome Specific Capabilites
Key | Value | Capability |
---|
Firefox Specific Capabilites
Key | Value | Capability |
---|---|---|
loggingPrefs | LoggingPreferences object | Preferences for logging |
firefox_binary | string | Path to firefox binary file to use. |
pageLoadingStrategy | string | See https://w3c.github.io/webdriver/webdriver-spec.html#the-page-load-strategy |
IE Specific Capabilites
Key | Value | Capability |
---|---|---|
ignoreProtectedModeSettings | true, false | Whether to skip the protected mode check. If set, tests may become flaky, unresponsive, or browsers may hang. If not set, and protected mode settings are not the same for all zones, an exception will be thrown on driver construction. Only “best effort” support is provided when using this capability. |
ignoreZoomSetting | true, false | Indicates whether to skip the check that the browser’s zoom level is set to 100%. Value is set to false by default. |
initialBrowserUrl | string | Allows the user to specify the initial URL loaded when IE starts. Intended to be used with ignoreProtectedModeSettings to allow the user to initialize IE in the proper Protected Mode zone. Using this capability may cause browser instability or flaky and unresponsive code. Only “best effort” support is provided when using this capability. |
enablePersistentHover | true, false | Determines whether persistent hovering is enabled (true by default). Persistent hovering is achieved by continuously firing mouse over events at the last location the mouse cursor has been moved to. |
enableElementCacheCleanup | true, false | Determines whether the driver should attempt to remove obsolete elements from the element cache on page navigation (true by default). This is to help manage the IE driver’s memory footprint, removing references to invalid elements. |
requireWindowFocus | true, false | Determines whether to require that the IE window have focus before performing any user interaction operations (mouse or keyboard events). This capability is false by default, but delivers much more accurate native events interactions. |
browserAttachTimeout | integer | The timeout, in milliseconds, that the driver will attempt to locate and attach to a newly opened instance of Internet Explorer. The default is zero, which indicates waiting indefinitely. |
ie.forceCreateProcessApi | true, false | Forces launching Internet Explorer using the CreateProcess API. If this option is not specified, IE is launched using the IELaunchURL, if it is available. For IE 8 and above, this option requires the TabProcGrowth registry value to be set to 0. |
ie.browserCommandLineSwitches | string | Specifies command-line switches with which to launch Internet Explorer. This is only valid when used with the forceCreateProcess. |
ie.usePerProcessProxy | true, false | When a proxy is specified using the proxy capability, this capability sets the proxy settings on a per-process basis when set to true. The default is false, which means the proxy capability will set the system proxy, which IE will use. |
ie.ensureCleanSession | true, false | When set to true, this capability clears the cache, cookies, history, and saved form data. When using this capability, be aware that this clears the cache for all running instances of Internet Explorer, including those started manually. |
logFile | string | The path to file where server should write log messages to. By default it writes to stdout. |
logLevel | string | The log level used by the server. Valid values are TRACE, DEBUG, INFO, WARN, ERROR, and FATAL. Defaults to FATAL if not specified. |
host | string | The address of the host adapter on which the server will listen for commands. |
extractPath | string | The path to the directory used to extract supporting files used by the server. Defaults to the TEMP directory if not specified. |
silent | true, false | Suppresses diagnostic output when the server is started. |
ie.setProxyByServer | true, false | Defines used proxy setter. False means WindowsProxyManager will be used for setting proxy settings. True means IEDriverServer will be used for setting proxy settings. Currently it’s False by default. In next releases it will be set to True by default and removed. |
Edge Specific Capabilites
Key | Value | Capability |
---|
Safari Specific Capabilites
Key | Value | Capability |
---|---|---|
safari.options | object | A map of configuration options, as enumerated below. |