Giter VIP home page Giter VIP logo

appium-webdriverio-typescript's Introduction

titleImage.png

Test framework for automating mobile apps with appium using webdriverio & typescript!


About

Currently this framework has been developed to run scripts in ANDROID platform with real device.

The tests run both on Android Native App and Mobile Browser. Chrome browser is configured currently for running browser tests.

Tech Stack

  • Appium - This is the node server which interacts with the mobile devices
  • WebdriverIO - It is the selenium webdriver api bindings for node.js, It has a very simple api which could be used to automate web & browser apps in a fast and scalable way.
  • Typescript(Javascript) - It is the superset of javascript which has additional static typings and features like JAVA and other languaes. Now you could write your code which compiles to pure javascript.
  • Cucumber - The popular BDD test framework which helps us write automated tests.

Getting Started

Pre-requisites

  1. NodeJS installed globally in the system. https://nodejs.org/en/download/

  2. JAVA(jdk) installed in the system.

  3. Andriod(sdk) installed in the system.

  4. Set JAVA_HOME & ANDROID_HOME paths correctly in the system.

  5. Chrome browser installed.

  6. Text Editor/IDE (Optional) installed-->Sublime/Visual Studio Code/Brackets.

Tip: Install npm install -g appium-doctor and run it from the command-line which checks if your java jdk and android sdk paths are set correctly or not.

Installation

Setup Scripts

  • Clone the repository into a folder
  • Go inside the folder and run following command from terminal/command prompt
npm install 
  • All the dependencies from package.json and typescript typings would be installed in node_modules folder.

Tip: Use Yarn to install your modules npm install -g yarn as it caches & locks them which would help us install correct versions of modules across various platforms without any issues. This project is configured with yarn.lock file. So you could make use of it.

Run Tests

  • First step is to start the appium server, This project includes the appium node module so you don't have to download it externally. You can run the appium server by the following npm command.
npm run appium
  • Next you have to transpile/compile your typescript files to javascript files, you could do this by running the command -
npm run build

Next step is to execute the config files. This project has 2 config files -

  • wdio.app.config.js - This config file is used to run tests in real mobile native apps. You would have to change the appium settings to run tests in your device.
capabilities: [
{
    appiumVersion: '1.7.1',                             // Appium module version
    browserName: '',                                   // browser name is empty for native apps
    platformName: 'Android',
    app: './app/LGCalculator.apk',                     // Path to the native app
    appPackage: 'com.android.calculator2',             // Package name of the app
    appActivity: 'com.android.calculator2.Calculator', // App activity of the app
    platformVersion: '5.1.1',                         // Android platform version of the device
    deviceName: 'THF755e0384',                       // device name of the mobile device
    waitforTimeout: waitforTimeout,
    commandTimeout: commandTimeout,
    newCommandTimeout: 30 * 60000,
}
],

To know your device name you could run the adb devices command which comes out of the box from Android SDK.

The node command to run Native app tests of this project is -

npm run app-test

The above command which is set in package.json internally calls the WebdriverIO's binary wdio ./config/wdio.app.config.js and runs the app config file.

  • wdio.browser.config.js - This config file is used to run tests in the chrome browser of the configured mobile device. The appium settings would looks like this-
capabilities: [
{
    appiumVersion: '1.7.1',
    browserName: 'chrome',  // browser name should be specified
    platformName: 'Android',
    platformVersion: '5.1.1',
    deviceName: 'THF755e0384', // device name is mandatory
    waitforTimeout: waitforTimeout,
    commandTimeout: commandTimeout,
    newCommandTimeout: 30 * 60000,
}
],

The node command to run browser tests of this project is -

npm run browser-test

The above command internally calls the WebdriverIO's binary wdio ./config/wdio.browser.config.js and runs the browser config file.

Run Test Suite

You could run both the native app and browser tests by running the following command -

npm test

The above command internally calls npm run app-test and npm run browser-test.

Writing Tests

Cucumber framework has been integrated with thi project, WebdriverIO's wdio-cucumber-framework adapter helps write BDD style tests with Features & Step Definitions.

const {Given, When, Then} = require('cucumber');
import {expect} from 'chai';
import {CalculatorPageObject} from '../pages/calcPage';

const calc: CalculatorPageObject = new CalculatorPageObject();

Given(/^I am on my mobile calculator app$/, () => {
    const title = browser.getText('android.widget.TextView');
    expect(title).to.equal('Calculator');
});

Page Objects

This framework is strictly written using page-object design pattern.

class GooglePageObject {
    public get searchTextBox(): any { return browser.element('#lst-ib'); }
    public get searchButton(): any { return browser.element('button[name="btnG"]'); }
    public get results(): any { return browser.waitForVisible('#rso', 5000); }
    public get firstLink(): any { return browser.element('#rso div._H1m._ees'); }
}
/*
Public Interface - export instances of classes
**/
export const GooglePage = new GooglePageObject()

Finding-Elements

Finding elements in mobile apps and browser's could be tricky sometimes.

  • Best way to find elements in native mobile apps is using UIAutomatorViewer .This supports Android 4.3 and above only, If you are using android version less than that, you could use Selendriod
  • Best way to find elements in mobile browser is by Remote debugging with Chrome DevTools. I personally find it lot easier & hassle free. You could find detail steps about it in this blog

Reports

Currently this project has been integrated with Allure-Reports. WebdriverIO's wdio-allure-reporter helps us generate detailed reports of our mobile automated tests. Once the test execution is finished you would find the allure-results folder generated automatically. Then you would have to run the following command to generate HTML Report

npm run report

Caveat: Chrome browser has an issue rendering the AJAX requests from local files generated by allure, You could use Firefox for seeing the html report. You could find more details about this issue here

allure.png

allure_graph.png

License

MIT License

Copyright (c) 2017 Ram Pasala

appium-webdriverio-typescript's People

Contributors

dependabot[bot] avatar igniteram 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appium-webdriverio-typescript's Issues

Cannot install APK

I tried to start and I got the error message:
ERROR: An unknown server-side error occurred while processing the command. Original error: 'com.android.calculator2' pac
kage cannot be uninstalled
emulator-5554.android.5_1_1.lgcalculator_apk

And I tried to install this apk to the emulator (emulator ABIS x86_x64) manual then I got the error:
D:\webdriver-io\appium-webdriverio-typescript\app>adb -s emulator-5554 install LGCalculator.apk
Performing Push Install
LGCalculator.apk: 1 file pushed. 27.8 MB/s (1393502 bytes in 0.048s)
pkg: /data/local/tmp/LGCalculator.apk
Failure [INSTALL_FAILED_NO_MATCHING_ABIS]

I don't know how to fix it.
Please help me.

Regards,
Dan

ENOENT Error using Windows 10

According README.md and using SO Windows 10, during "npm run app-test", I have the following problem :

[email protected] app-test C:\dev\workspace\hoff\ticket\appium-webdriverio-typescript
wdio ./config/wdio.app.config.js
<<< NATIVE APP TESTS STARTED >>>
events.js:183
throw er; // Unhandled 'error' event
^
Error: spawn appium ENOENT
at _errnoException (util.js:992:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] app-test: wdio ./config/wdio.app.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] app-test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

[Appium logs]: taking invalid path

ERROR: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C:\Users\Fran\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZY322C865Q shell pm install /data/local/tmp/appium_cache/e1ccbc83780504f65017e742eeecb064dedbeba7.apk' exited with code 1'; Stderr: 'Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed to collect certificates
from /data/app/vmdl2145678506.tmp/base.apk: File res/drawable-sw360dp-xxhdpi-v13/calculator_advanced_btn_multi_functions_popup_tan1_normal.png in manifest does not exist]'; Code: '1'
zy322c865q.android.8_1_0.c:\users\fran\desktop\mobile\appium-webdriverio-typescript\app\lgcalculator_apk

Cannot upgrade 'io.appium.settings' because of 'Error executing adbExec. Original error: 'Command 'C:\Users\Fran\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s ZY322C865Q shell pm install -r -g /data/local/tmp/appium_cache/728413456b86856a2003edeb524d6bd577ca6418.apk'

I think its taking worng plateformTools path means that starting of path with "c:" this one is wrong but i m not getting why its taking such type of path

Unable to transpile

Hi,

When I try to transpile, I get the following errors,

node_modules/@types/chai/index.d.ts:121:9 - error TS8020: JSDoc types can only be used inside documentation comments.
121 any?, // actual value
~~~~
node_modules/@types/chai/index.d.ts:122:9 - error TS8020: JSDoc types can only be used inside documentation comments.

122 boolean? // showDiff
~~~~~~~~
node_modules/@types/chai/index.d.ts:126:16 - error TS2370: A rest parameter must be of an array type.
126 assert(...args: AssertionArgs): void;
~~~~~~~~~~~~~~~~~~~~~~

Could this please be helped??

Thanks,
Srikanth T.

npm run browser-test ->Unhandled 'error' event

events.js:174
throw er; // Unhandled 'error' event

C:\Projects\Mobile\AWT>npm run browser-test

[email protected] browser-test C:\Projects\MobileAPK\AWT
wdio ./config/wdio.browser.config.js

<<< BROWSER TESTS STARTED >>>
events.js:174
throw er; // Unhandled 'error' event
^

Error: spawn appium ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:19)
at onErrorNT (internal/child_process.js:421:16)
at internalTickCallback (internal/process/next_tick.js:72:19)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:777:11)
at executeUserCode (internal/bootstrap/node.js:342:17)
at startExecution (internal/bootstrap/node.js:276:5)
at startup (internal/bootstrap/node.js:227:5)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:252:12)
at onErrorNT (internal/child_process.js:421:16)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] browser-test: wdio ./config/wdio.browser.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] browser-test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Not started

I can't start this project - failed on start
I installed all dependencies and start appium server, virtual device and change virtual device name and android version into wdio.app.config but start application tests return an error

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'app-test' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'preapp-test', 'app-test', 'postapp-test' ]
5 info lifecycle [email protected]~preapp-test: [email protected]
6 info lifecycle [email protected]~app-test: [email protected]
7 verbose lifecycle [email protected]~app-test: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~app-test: PATH: C:\Users\Oleksandr\AppData\Roaming\nvm\v10.3.0\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\hobby\test\appium-webdriverio-typescript\node_modules\.bin;C:\Users\Oleksandr\AppData\Roaming\nvm\v10.3.0\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\hobby\test\appium-webdriverio-typescript\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Users\Oleksandr\AppData\Local\Android\sdk\tools;C:\Users\Oleksandr\AppData\Local\Android\sdk\tools\bin;C:\Users\Oleksandr\AppData\Local\Android\sdk\build-tools;C:\Users\Oleksandr\AppData\Local\Android\sdk\platform-tools;C:\Users\Oleksandr\AppData\Local\Android\sdk\emulator;C:\WINDOWS\System32\OpenSSH\;C:\Users\Oleksandr\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Android\Android Studio 2;C:\Program Files\Java\jdk1.8.0_111\bin;C:\Users\Oleksandr\AppData\Local\atom\bin;C:\Users\Oleksandr\AppData\Local\Microsoft\WindowsApps;C:\ant\bin;C:\Program Files\Microsoft VS Code\bin;C:\Python27;C:\Users\Oleksandr\AppData\Local\Android\sdk\tools;C:\Users\Oleksandr\AppData\Local\Android\sdk\tools\bin;C:\Users\Oleksandr\AppData\Local\Android\sdk\build-tools;C:\Users\Oleksandr\AppData\Local\Android\sdk\platform-tools;C:\Users\Oleksandr\AppData\Local\Android\sdk\emulator;C:\Users\Oleksandr\AppData\Local\Android\sdk;C:\Users\Oleksandr\AppData\Roaming\nvm;C:\Program Files\nodejs
9 verbose lifecycle [email protected]~app-test: CWD: D:\hobby\test\appium-webdriverio-typescript
10 silly lifecycle [email protected]~app-test: Args: [ '/d /s /c', 'wdio ./config/wdio.app.config.js' ]
11 silly lifecycle [email protected]~app-test: Returned: code: 1  signal: null
12 info lifecycle [email protected]~app-test: Failed to exec app-test script
13 verbose stack Error: [email protected] app-test: `wdio ./config/wdio.app.config.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\Oleksandr\AppData\Roaming\nvm\v10.3.0\node_modules\npm\node_modules\npm-lifecycle\index.js:304:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\Oleksandr\AppData\Roaming\nvm\v10.3.0\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:961:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
14 verbose pkgid [email protected]
15 verbose cwd D:\hobby\test\appium-webdriverio-typescript
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "app-test"
18 verbose node v10.3.0
19 verbose npm  v6.1.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] app-test: `wdio ./config/wdio.app.config.js`
22 error Exit status 1
23 error Failed at the [email protected] app-test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

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.