Giter VIP home page Giter VIP logo

appium-demo's Introduction

Appium + WebDriver.IO Demo Framework - Android & IOS Example

This project has been created to demonstrate how a QA Engineer can perform Mobile Testing using Appium + WebDriver.IO More commands and insights about the integration at WebDriverIO Appium docs


General System Requirements

Node JS

We need node js to download Appium beta version & drivers easily.

  • Download Node Js depending on your operating system.

Java JDK & JAVA_HOME variable

I Tested the following steps on MAC OS Monterrey:

    /usr/libexec/java_home
  • If you want to check the java version:
    /usr/libexec/java_home -V
  • Open the zshenv file to insert the JAVA_HOME variable (i):
    vim ~/.zshenv
  • Enter the environment variable and save the vim session (:wq!):
    export JAVA_HOME=$(/usr/libexec/java_home)
  • Source and apply the changes in the system:
    source ~/.zshenv
  • You can check if it was set correctly running the command:
    echo $JAVA_HOME
  • It should return something like:
    /Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home

Android Setup

Android Studio & ANDROID_HOME variable

Tested the following steps on MAC OS Monterrey:

  • Android studio on Mac can be located at:
    * cd /Users/[USER]/Library/Android/sdk
  • We need to add a reference to a couple of folders inside of that SDK
    • Tools & Platform Tools
  • Open the zshenv file to insert the ANDROID_HOME variable (i):
    vim ~/.zshenv
  • Enter the environment variables and save the vim session (:wq!):
    export ANDROID_HOME="/Users/[USER]/Library/Android/sdk"
    export PATH=$ANDROID_HOME/platform-tools:$PATH
    export PATH=$ANDROID_HOME/tools:$PATH
  • Source and apply the changes in the system:
    source ~/.zshenv
  • You can check if it was set correctly running the command:
    echo $ANDROID_HOME
  • It should return something like:
    /Users/[USER]/Library/Android/sdk
    adb

IOS Setup

  1. Install XCode from the MacOs App Store
  2. Install XCode Command line tools
    xcode-select --install
  • Make sure it is installed correctly using the following command:
    xcode-select -p
  • It should return something like(may defer from your OS version):
    /Applications/Xcode.app/Contents/Developer
  1. Install Carthage(It is a simple dependency manager for macOS and iOS, created by a group of developers from GitHub).
    brew install carthage

Download Appium Inspector

In order to find the correct locators to map elements, you will need to have this tool installed in your computer.

For this project you can use the following configuration:

Server Key Server Value
Remote Host 0.0.0.0
Remote Port 4724
Remote Path /

Android Desired Capabilities(Example)

Desired Capability Key Desired Capability Value
platformName Android
platformVersion [OS VERSION / IMAGE]
deviceName [EMULATED_DEVICE_NAME]
app /[PROJECT_PATH]/[APP_NAME].apk
appium:automationName UIAutomator2

IOS Desired Capabilities(Emulator - App)

Desired Capability Key Desired Capability Value
platformName IOS
platformVersion [OS VERSION / IMAGE]
deviceName [EMULATED_DEVICE_NAME]
app /[PROJECT_PATH]/[APP_NAME].app
appium:automationName XCUItest

Install Apium

Appium is an open source test automation framework for use with native, hybrid and mobile web apps. It drives iOS, Android, and Windows apps using the WebDriver protocol.

  • Install Appium from the official documentation
  • Install Appium 2 by Node JS(Beta):
    npm install -g appium@next

Check the appium version using

    appium -v

Appium Doctor

To check if your OS meets the appium requirements, install this node package.

npm install appium-doctor -g

And then use the library:

appium-doctor

Appium drivers

If you want Appium to work correctly, you need to download and have the android/ios driver in your system. Run the commands:

appium driver install xcuitest
appium driver install uiautomator2

Check the installed drivers using

appium driver list

Sample applications

Sample Application that you can use:

SauceDemo Hybrid App - React Native) - (Framework is configured to use this one)

Sauce Labs Native Sample Application

WebdriverIO Demo App for iOS and Android

Important Note: For IOS you are going to need an app build to run it in simulators, but an .IPA file to run it in real devices. It required additonal desired capabilities, and you can see which ones in the next article: Appium XCUITest Driver Real Device Setup

Setup WebDriverIO

1- Run the command to create the package.json & continue with the installation process

    npm init wdio .

2- Using the WDIO Configuration Helper select the options you want to select. In my case I decided to use:

  • On my local machine
  • Mocha
  • No compiler
  • Spect Location: Default
  • Do you want WebDriverIO to generate some test files?: No
  • Reporter: Spec
  • No Plugin
  • Service: Appium
  • Base URL: Default
  • NPM Install: Yes

3- Add your tests at

'./[yourProject]/specs/**/*.js'

4- Configure the app route at wdio.conf.js

  • Declare where it is going to be located
const projectPath = require('path')
const androidAppPath = projectPath.join(process.cwd(), "app/android/Android-MyDemoAppRN.1.3.0.build-244.apk")
const iosAppPath = projectPath.join(process.cwd(),"app/ios/MyRNDemoApp.app");
  • Set up the capabilities for Android(Emulator sample)
capabilities: [{
        platformName: 'Android', 
        "appium:device-name": 'Pixel 4 API 30(R)',
        "appium:platformVersion": "11.0",
        "appium:automationName": "UIAutomator2",
        "appium:app": androidAppPath,
        // "appium:appWaitActivity": "com.swaglabsmobileapp.MainActivity"(For OLD swaglabs app)
    }]
  • Set up the capabilities for Android(Emulator sample)
capabilities: [{
        platformName: 'IOS',
        "appium:device-name": 'iPhone 13 Pro Max',
        "appium:platformVersion": "16.0",
        "appium:automationName": "XCUItest",
        "appium:app": iosAppPath,   
    }]
  • Install Appium in your project
    npm install --save-dev appium@next
  • Check if the drivers are still available, if not install them again:
appium driver list
appium driver install xcuitest
appium driver install uiautomator2
  • Run your scripts using
npx wdio

Setup WebDriverIO

if you want to run this project:

1- Install all the system requirements

2- Clone the project

3- Run: npm i

4- Download the android app and place it under app/android or app/IOS

5- npm run wdioIOS/wdioAndroid

Android setup & demo

ANDROID TESTING VIDEO

IOS setup & demo

IOS TESTING VIDEO

Extra Information

Notes

  • To manage node versions you can install "n" using the command "npm install -g n". Then you can install the version you may need, for instance "n 16.15.1"(LTS version where this project is working fine.)

appium-demo's People

Contributors

joanesquivel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

appium-demo's Issues

need to add a step in the README

Before running npx wdio as i had discovered after reading line 267:

you should include these commands:

adb uninstall io.appium.uiautomator2.server
adb uninstall io.appium.uiautomator2.server.test

(I found from https://stackoverflow.com/questions/59075420/an-unknown-server-side-error-occurred-while-processing-the-command-could-not-pr)

before restarting appium server:

appium -p 4724

otherwise you will get the issue:

Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up

missing packages typescript and ts-node

after

  1. cloning this repo
  2. attempting to follow README.md for setup instructions
  3. running npx wdio

i get this error

`% npx wdio

Execution of 4 workers started at 2023-11-20T12:20:41.708Z

2023-11-20T12:20:41.718Z INFO @wdio/cli:launcher: Run onPrepare hook
2023-11-20T12:20:41.719Z INFO @wdio/appium-service: Will spawn Appium process: node /Users/ivan.cheung/node-lab/mocha-wdio-appium/exercises/appium-demo/node_modules/appium/index.js --base-path /
2023-11-20T12:20:43.658Z INFO @wdio/appium-service: Appium started with ID: 20310
2023-11-20T12:20:43.660Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2023-11-20T12:20:43.660Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2023-11-20T12:20:43.660Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2023-11-20T12:20:43.660Z INFO @wdio/cli:launcher: Run onWorkerStart hook
2023-11-20T12:20:43.661Z INFO @wdio/local-runner: Start worker 0-0 with arg:
2023-11-20T12:20:43.662Z INFO @wdio/local-runner: Start worker 0-1 with arg:
2023-11-20T12:20:43.663Z INFO @wdio/local-runner: Start worker 0-2 with arg:
2023-11-20T12:20:43.664Z INFO @wdio/local-runner: Start worker 0-3 with arg:
[0-2] Error: "ts-node/esm/transpile-only 'resolve'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, include shortCircuit: true in the hook's return.
[0-2] at new NodeError (node:internal/errors:406:5)
[0-2] at Hooks.resolve (node:internal/modules/esm/hooks:286:13)
[0-2] at MessagePort.handleMessage (node:internal/modules/esm/worker:168:18)
[0-1] Error: "ts-node/esm/transpile-only 'resolve'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, include shortCircuit: true in the hook's return.
[0-1] at new NodeError (node:internal/errors:406:5)
[0-1] at Hooks.resolve (node:internal/modules/esm/hooks:286:13)
[0-1] at MessagePort.handleMessage (node:internal/modules/esm/worker:168:18)
[0-0] Error: "ts-node/esm/transpile-only 'resolve'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, include shortCircuit: true in the hook's return.
[0-0] at new NodeError (node:internal/errors:406:5)
[0-0] at Hooks.resolve (node:internal/modules/esm/hooks:286:13)
[0-0] at MessagePort.handleMessage (node:internal/modules/esm/worker:168:18)
[0-3] Error: "ts-node/esm/transpile-only 'resolve'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, include shortCircuit: true in the hook's return.
[0-3] at new NodeError (node:internal/errors:406:5)
[0-3] at Hooks.resolve (node:internal/modules/esm/hooks:286:13)
[0-3] at MessagePort.handleMessage (node:internal/modules/esm/worker:168:18)
[0-0] FAILED
2023-11-20T12:20:43.901Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
[0-1] FAILED
2023-11-20T12:20:43.901Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
[0-2] FAILED
2023-11-20T12:20:43.901Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
[0-3] FAILED
2023-11-20T12:20:43.901Z INFO @wdio/cli:launcher: Run onWorkerEnd hook
2023-11-20T12:20:43.901Z INFO @wdio/cli:launcher: Run onComplete hook
2023-11-20T12:20:43.902Z INFO @wdio/appium-service: Appium (pid: 20310) killed

Spec Files: 0 passed, 4 failed, 4 total (100% completed) in 00:00:02

2023-11-20T12:20:43.902Z INFO @wdio/local-runner: Shutting down spawned worker
2023-11-20T12:20:44.154Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2023-11-20T12:20:44.155Z INFO @wdio/local-runner: shutting down`

it's after I added these two packages:

npm i -D typescript ts-node

then this is solved and the test runs

perhaps need to fix this in packages.json?

thanks

Issues following the README.md when learning how to set things up

Issue 1) The readme line 267 says npx wdio . but this assumes thart wdio.config.js file is already created on the repo, but doesn't menation that the repo already has

  • android-wdio.conf.js
  • ios-wdio.conf.js

under /config

so perhaps add the line underneath it to run npx android-wdio or npx ios-wdio to save the user from running npx init wdio . first from line 202?

Issue 2) the current set of questions asked when running 'npm init wdio .' is now different to what is shown in the readme.

Expected questions in the readme from line 204 to 214:

2- Using the WDIO Configuration Helper select the options you want to select. In my case I decided to use:  
* On my local machine
* Mocha
* No compiler
* Spect Location: Default
* Do you want WebDriverIO to generate some test files?: No
* Reporter: Spec
* No Plugin 
* Service: Appium
* Base URL: Default
* NPM Install: Yes

Actual questions:

the questions now asked (after cloning this repo first) are:

i) A project named "webdriverio-tests" was detected at "/Users/<username>/<some more folders>/mocha-wdio-appium/exercises/appium-demo", correct? (i selected yes)
ii) What type of testing would you like to do? 

possible answers:
- E2E Testing - of Web or Mobile Applications **(i assume to pick this one?)**
- Component or Unit Testing - in the browser
    > https://webdriver.io/docs/component-testing 
- Desktop Testing - of Electron Applications
    > https://webdriver.io/docs/desktop-testing/electron 
- Desktop Testing - of MacOS Applications
    > https://webdriver.io/docs/desktop-testing/macos 
- VS Code Extension Testing
    > https://webdriver.io/docs/vscode-extension-testing 

iii) Where is your automation backend located? (selected 'on my local machine')
iv) Which environment you would like to automate?

possible answers:
- Web - web applications in the browser 
- Mobile - native, hybrid and mobile web apps, on Android or iOS **(i assume to pick this one?)**

v) Which mobile environment you'ld like to automate?

possible answers:
- Android - native, hybrid and mobile web apps, tested on emulators and real devices
    > using UiAutomator2 (https://www.npmjs.com/package/appium-uiautomator2-driver) **(i chose this one following the tutorial for now)** 
-   iOS - applications on iOS, iPadOS, and tvOS
    > using XCTest (https://appium.github.io/appium-xcuitest-driver) 

vi) Which framework do you want to use? **(selected Mocha (https://mochajs.org/) )**
vii) Do you want to use a compiler? **(selected "No")**
viii) Do you want WebdriverIO to autogenerate some test files? **(selected "No")**
ix) What should be the location of your spec files? **(gave '/appium-demo/test/specs/)**
x)  Do you want to use page objects (https://martinfowler.com/bliki/PageObject.html)?  **(selected "No")**
xi) Which reporter do you want to use? **(chose 'spec' as per the tutorial)**
xii) Do you want to add a plugin to your test setup? **(pressed 'enter' to select "No")**
xiii) Do you want to add a service to your test setup? **(selected "appium")**
xv) Do you want me to run `npm install`  **(selected "Yes")**

Wasn't sure which answers to pick and the resulting capabilities object generated in the wdio.conf.js doesn't look anything like the one in the tutorial

    capabilities: [{
        // capabilities for local Appium web tests on an Android Emulator
        platformName: 'Android',
        browserName: 'Chrome',
        'appium:deviceName': 'Android GoogleAPI Emulator',
        'appium:platformVersion': '12.0',
        'appium:automationName': 'UiAutomator2',
    }],

it won't have the property:
'appium:app':

and for some reason has the property:
browserName: 'Chrome',

when I didn't even specify this was browser testing (meant to be iOS or Android mobile app ๐Ÿ˜ )

Issue 3)
Typo at line 240

Expected:

  • Set up the capabilities for iOS(Emulator sample)

Actual

  • Set up the capabilities for Android(Emulator sample)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.