Mobile automation framework using appium - BDD
- Install Java JDK8 and IntelliJ IDEA
- Install NodeJS
- Install Android studio
- Install Appium Server (v2.x) using npm (CLI) command
npm install -g appium@next
Appium server version 2.0.0-beta.55
This will install the Appium server only, but no drivers. Install the latest versions of the XCUITest and UiAutomator2 drivers, after installing Appium you would run the following commands:
appium driver install uiautomator2
appium driver install xcuitest
Command to check the installed appium version: `appium --version`
- Add below Android SDK path in the environment variable
- ANDROID_HOME = <path to Sdk folder>
- %ANDROID_HOME%\tools
- %ANDROID_HOME%\tools\bin
- %ANDROID_HOME%\platform-tools
- Install Appium desktop
- Install Appium Inspector
- Install Homebrew
- Install NodeJS
- Install Java JDK8 and IntelliJ IDEA
- Install Appium server using npm (CLI) or Appium desktop client
- Install Android studio
- Install Appium Inspector
- Set JAVA_HOME and ANDROID_HOME environment variables
- Install appium-doctor using command
npm install -g appium-doctor
- To view the list of available options
appium-doctor --help
To check Android set up `appium-doctor --android`
To check ios set up `appium-doctor --ios`
- Open Android Studio.
- Click on Tools -> AVD Manager -> Create Virtual Device -> Select the device and OS version -> Finish.
- Once Virtual device is created, click on Launch this AVD in the emulator.
- Command to view the list of devices attached
adb devices
- Connect Android real device to the machine(Desktop/Laptop)
- Turn on the developer options in android mobile
- Enable USB debugging
- Run command
adb devices
in cmd prompt to check whether the device is recognised
- Download Vysor
- Open command prompt, go to
<sdk emulator path>
Command to stard AVD: `emulator -avd <avd_name>`
Command to stop/kill AVD: `adb -e emu kill`
- Copy the .apk file and paste it in the path -
<path to sdk platform-tools>
- Open the cmd terminal from the directory where APK file is placed and enter command
adb install <apk filename>
If the app is already installed on your device then we can make use of appPackage and appActivity to launch the app
Option 1 :
- Open the app on the device, for which appPackage and appActivity is required.
- Open powershell and enter command
adb shell dumpsys window | grep -E 'mCurrentFocus|mFocusedApp'
NOTE: This command may not work for newer Android OS (10 or 11). In that case, use command:adb shell "dumpsys activity activities | grep mResumedActivity"
Option 2 : Install APK info app to retrieve appPackage and appActivity for the app installed in your device
- Go to the path -
<path to sdk folder>\tools\bin\
- click on
uiautomatorviewer
- On the UI Automator Viewer, click on Device Screenshot (uiautomator dump). Ui automator will capture the screenshot of current open screen in the device.
- Start the Appium Server and connect with Real device/Emulator.
- Open Appium Inspector app and provide the appium server details and Desired Capabilities.
- Click on Start session which will start the appium inspector with layout shown below.
Type url `chrome://inspect/#devices` in the desktop chrome browser and start inspecting element
Add below lines in the Desired capabilities
capability.setCapability(AndroidMobileCapabilityType.AVD, "Pixel_3a");
capability.setCapability(AndroidMobileCapabilityType.AVD_LAUNCH_TIMEOUT, "180000");
Start appium server using command appium --allow-insecure chromedriver_autodownload
Add below line in the AppiumServiceBuilder
AppiumServiceBuilder builder = new AppiumServiceBuilder();
builder.withArgument(GeneralServerFlag.ALLOW_INSECURE, "chromedriver_autodownload");
Use AppiumServiceBuilder
and AppiumDriverLocalService
to start the server programmatically Set environment
variable APPIUM_HOME = <path to npm folder>\node_modules\appium\build\lib
where main.js
file is present
👉 Run RunCucumberTest
in the
path appium-mobile-automation-framework-bdd\src\test\java\org\example\runner\RunCucumberTest.java
👉 Run test using following command
mvn clean test -DplatformName=<platform name> -DdeviceName=<device name> -Dudid=<udid> -DsystemPort=<system port number> -DchromedriverPort=<chromedriver port>
Example:
mvn clean test -DplatformName=android -DdeviceName=Pixel_4 -Dudid=emulator-5554 -DsystemPort=7070 -DchromedriverPort=7071