Setup Project and Configuration (Android)

  • Create & Initialize a new directory

    • mkdir <project-name>

    • cd <project-name>

    • npm init -y

  • Install WebdriverIO CLI

    • npm i @wdio/cli

  • Setup config

    • npx wdio config

      Select the ff:

      • Where is your automation backend located: On my local machine

      • Which framework do you want to use: mocha/cucumber

      • Do you want to use a compiler? : No

      • Where are your test specs located: select default

      • Do you want WebdriverIO to autogenerate some test files?: Yes

      • Which reporter do you want to user: spec

      • Do you want to add a service to your test setup?: select appium

      • What is the base url: select default

      Then it will install all the relevant packages.

      Make sure you install npm i appium@2.0.0-beta.35

WebdriverIO config (Android)

  • Walkthrough

    wdio.conf.js

    • Port: 4723 This is the port where appium server will spin off

    • specs: this is where all the spec are located

    • capabilities needs to specify all the android specification

    • log: default webdriverIO log which will generate when running the test

    • baseurl: We dont need this since we are going to run in in appium

    • services: appium server to , it is connected to appium services to spin off appium server

  • Add test up

    • create a new folder app/android add the app on that folder

  • Update capabilities

    • Platform name

    • Device name

    • App path

    config.capabilities = [
      {
        platformName: 'Android',
        'appium:platformVersion': "12",
        'appium:deviceName': 'Pixel 5',
        'appium:automationName': 'UIAutomator2',
        'appium:app': path.join(process.cwd(), 'app/android/app-dev-release.apk'),
        'appium:autoGrantPermissions': true
      }
    ]

  • Setup Test folder

    • Create test/specs folder and sample.js file and paste the code below

    describe('Sample', () => {
      it('Sample Test', async () => {
        await driver.pause(3000);
      });
    })

  • Run app with WebdriverIO npx wdio

    if you got an error: Unable to connect to the server:

    • Make sure you install appium on your project npm i appium@2.0.0-beta.35

    • Check if appium driver are installed : npx appium driver list

      Make sure uiautomator2 and xcuitest are installed

      • uiautomator2 - npx appium driver install uiautomator2

      • xcuitest - appium driver install xcuitest

Setup Emulator for Testing

  • Add emulator in Android Studio

    • Create another Virtual with different android version

  • Add capabilities in Appium Inspector

    • Remote Port: 4724

    • Remote Host: 127.0.0.1

    • Remote path: /

    • Desired Capabilities

      • PlatformName: Android

      • platformVersion: 11

      • deviceName: Nexus_S

      • app: <application path>

      • automationName: UIAutomator2

    • Check Automatically add necessary Appium vendor prefixes on Start

    • run port: appium -p 4724 on your terminal

    • Start Session to run the Appium Inspector

Last updated