├── .gitignore ├── ApiDemos-debug.apk ├── README.md ├── data └── data.js ├── package.json ├── pageObjects └── dialog.page.js ├── screenshots ├── landscape.png └── portrait.png ├── test └── specs │ ├── cancelDialog[Activity].js │ └── dialog.test.js └── wdio.conf.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store -------------------------------------------------------------------------------- /ApiDemos-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ofindley/appium-webdriverio/b3c9c61881c1fcbe9112e2a340e969500a3665ce/ApiDemos-debug.apk -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # appium-webdriverio 2 | This is a Appium project with webdriverIO by Orane Findley. This project is accompanied by a video course. 3 | -------------------------------------------------------------------------------- /data/data.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | shortCancelDialog: { 3 | 'title': 'Lorem ipsum dolor sit aie consectetur adipiscing\nPlloaso mako nuto siwuf cakso dodtos anr koop.' 4 | }, 5 | longCancelDialog: { 6 | 'title': 'Header title', 7 | 'msg': 'Plloaso mako nuto siwuf cakso dodtos anr koop a cupy uf cak vux noaw yerw phuno. Whag schengos, uf efed, quiel ba mada su otrenzr.\n\nSwipontgwook proudgs hus yag su ba dagarmidad. Plasa maku noga wipont trenzsa schengos ent kaap zux comy.\n\nWipont trenz kipg naar mixent phona. Cak pwico siructiun ruous nust apoply tyu cak Uhex sisulutiun munityuw uw dseg' 8 | }, 9 | ultraLongCancelDialog: { 10 | 'title': 'Header title', 11 | 'msg': 'Plloaso mako nuto siwuf cakso dodtos anr koop a cupy uf cak vux noaw yerw phuno. Whag schengos, uf efed, quiel ba mada su otrenzr.\n\nSwipontgwook proudgs hus yag su ba dagarmidad. Plasa maku noga wipont trenzsa schengos ent kaap zux comy.\n\nWipont trenz kipg naar mixent phona. Cak pwico siructiun ruous nust apoply tyu cak Uhex sisulutiun munityuw uw dseg\n\n Plloaso mako nuto siwuf cakso dodtos anr koop a cupy uf cak vux noaw yerw phuno. Whag schengos, uf efed, quiel ba mada su otrenzr.\n\nSwipontgwook proudgs hus yag su ba dagarmidad. Plasa maku noga wipont trenzsa schengos ent kaap zux comy.\n\nWipont trenz kipg naar mixent phona. Cak pwico siructiun ruous nust apoply tyu cak Uhex sisulutiun munityuw uw dseg\n\n Plloaso mako nuto siwuf cakso dodtos anr koop a cupy uf cak vux noaw yerw phuno. Whag schengos, uf efed, quiel ba mada su otrenzr.\n\nSwipontgwook proudgs hus yag su ba dagarmidad. Plasa maku noga wipont trenzsa schengos ent kaap zux comy.\n\nWipont trenz kipg naar mixent phona. Cak pwico siructiun ruous nust apoply tyu cak Uhex sisulutiun munityuw uw dseg\n\n Plloaso mako nuto siwuf cakso dodtos anr koop a cupy uf cak vux noaw yerw phuno. Whag schengos, uf efed, quiel ba mada su otrenzr.\n\nSwipontgwook proudgs hus yag su ba dagarmidad. Plasa maku noga wipont trenzsa schengos ent kaap zux comy.\n\nWipont trenz kipg naar mixent phona. Cak pwico siructiun ruous nust apoply tyu cak Uhex sisulutiun munityuw uw dseg\n\n Plloaso mako nuto siwuf cakso dodtos anr koop a cupy uf cak vux noaw yerw phuno. Whag schengos, uf efed, quiel ba mada su otrenzr.\n\nSwipontgwook proudgs hus yag su ba dagarmidad. Plasa maku noga wipont trenzsa schengos ent kaap zux comy.\n\nWipont trenz kipg naar mixent phona. Cak pwico siructiun ruous nust apoply tyu cak Uhex sisulutiun munityuw uw dseg\n\n Plloaso mako nuto siwuf cakso dodtos anr koop a cupy uf cak vux noaw yerw phuno. Whag schengos, uf efed, quiel ba mada su otrenzr.\n\nSwipontgwook proudgs hus yag su ba dagarmidad. Plasa maku noga wipont trenzsa schengos ent kaap zux comy.\n\nWipont trenz kipg naar mixent phona. Cak pwico siructiun ruous nust apoply tyu cak Uhex sisulutiun munityuw uw dseg\n\n' 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "appium_js", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "./node_modules/.bin/wdio wdio.conf.js" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@wdio/cli": "^5.16.10" 14 | }, 15 | "devDependencies": { 16 | "@wdio/local-runner": "^5.16.10", 17 | "@wdio/mocha-framework": "^5.16.10", 18 | "@wdio/selenium-standalone-service": "^5.16.10", 19 | "@wdio/spec-reporter": "^5.16.5", 20 | "@wdio/sync": "^5.16.10", 21 | "chai": "^4.2.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pageObjects/dialog.page.js: -------------------------------------------------------------------------------- 1 | class Dialog { 2 | /** 3 | * Define Elements 4 | */ 5 | get appBtn() {return $("~App");} 6 | get alertDialogBtn() {return $('//android.widget.TextView[@content-desc="Alert Dialogs"]');} 7 | get textEntryDialogBtn() {return $('//android.widget.Button[@content-desc="Text Entry dialog"]');} 8 | get userNameField() {return $('//android.widget.EditText[@resource-id="io.appium.android.apis:id/username_edit"]');} 9 | get passwordField() {return $('//android.widget.EditText[@resource-id="io.appium.android.apis:id/password_edit"]');} 10 | 11 | get dialogOkBtn() {return $('//android.widget.Button[@resource-id="android:id/button1"]');} 12 | get dialogCancelBtn() {return $('//android.widget.Button[@resource-id="android:id/button2"]');} 13 | 14 | get viewBtn() {return $('//android.widget.TextView[@content-desc="Views"]')}; 15 | get tabsBtn() {return $('//android.widget.TextView[@content-desc="Tabs"]')}; 16 | get contentByIdBtn() {return $('//android.widget.TextView[@content-desc="1. Content By Id"]')}; 17 | 18 | get tabs() {return $$('android.widget.LinearLayout')}; 19 | get tab1Details() {return $('~tab1')}; 20 | get tab2Details() {return $('~tab2')}; 21 | get tab3Details() {return $('~tab3')}; 22 | 23 | get repeatAlarmBtn() {return $('//android.widget.Button[@content-desc="Repeat alarm"]')}; 24 | 25 | // #region Activity 26 | get cancelDialogMsgBtn() { return $('//android.widget.Button[@content-desc="OK Cancel dialog with a message"]'); } 27 | get cancelLongDialogMsgBtn() { return $('//android.widget.Button[@content-desc="OK Cancel dialog with a long message"]'); } 28 | get cancelUltraLongDialogMsgBtn() { return $('//android.widget.Button[@content-desc="OK Cancel dialog with ultra long message"]'); } 29 | get dialogModalTitle() { return $('//android.widget.TextView[@resource-id="android:id/alertTitle"]'); } 30 | get dialogModalMsg() { return $('//android.widget.TextView[@resource-id="android:id/message"]'); } 31 | // #endregion 32 | 33 | 34 | _weekdayCheckbox(index){ 35 | return $(`//android.widget.CheckedTextView[@index="${index}"]`); 36 | } 37 | 38 | // #region Activity 39 | getDialogModalTitle() { 40 | let title = this.dialogModalTitle.getText(); 41 | return title; 42 | } 43 | 44 | getDialogModalMsg() { 45 | let msg = this.dialogModalMsg.getText(); 46 | return msg; 47 | } 48 | // #endregion 49 | } 50 | module.exports = new Dialog(); 51 | -------------------------------------------------------------------------------- /screenshots/landscape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ofindley/appium-webdriverio/b3c9c61881c1fcbe9112e2a340e969500a3665ce/screenshots/landscape.png -------------------------------------------------------------------------------- /screenshots/portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ofindley/appium-webdriverio/b3c9c61881c1fcbe9112e2a340e969500a3665ce/screenshots/portrait.png -------------------------------------------------------------------------------- /test/specs/cancelDialog[Activity].js: -------------------------------------------------------------------------------- 1 | const dialog = require('../../pageObjects/dialog.page'); 2 | const data = require('../../data/data'); 3 | const expect = require('chai').expect; 4 | 5 | describe('Cancel Dialogs', () => { 6 | // Execute a block of code at the start of the test suite 7 | before(() => { 8 | dialog.appBtn.click(); 9 | dialog.alertDialogBtn.click(); 10 | }); 11 | 12 | it('Verify that the cancel dialog short message is correct and displays', () => { 13 | dialog.cancelDialogMsgBtn.click(); 14 | expect(dialog.getDialogModalTitle()).equal(data.shortCancelDialog.title); 15 | dialog.dialogOkBtn.click(); 16 | }); 17 | 18 | it('Verify that the cancel dialog long message is correct and displays', () => { 19 | dialog.cancelLongDialogMsgBtn.click(); 20 | expect(dialog.getDialogModalTitle()).equal(data.longCancelDialog.title); 21 | expect(dialog.getDialogModalMsg()).equal(data.longCancelDialog.msg); 22 | dialog.dialogOkBtn.click(); 23 | }); 24 | 25 | it('Verify that the cancel dialog ultra long message is correct', () => { 26 | dialog.cancelUltraLongDialogMsgBtn.click(); 27 | expect(dialog.getDialogModalTitle()).equal(data.ultraLongCancelDialog.title); 28 | expect(dialog.getDialogModalMsg()).equal(data.ultraLongCancelDialog.msg); 29 | dialog.dialogOkBtn.click(); 30 | }); 31 | 32 | // Execute a block of code at the end of the test suite 33 | after(() => { 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /test/specs/dialog.test.js: -------------------------------------------------------------------------------- 1 | const dialog = require('../../pageObjects/dialog.page'); 2 | const expect = require('chai').expect; 3 | 4 | describe('Dialog', ()=>{ 5 | // Execute a block of code before every test 6 | beforeEach(() => { 7 | }); 8 | 9 | it('Verify that the text entry dialog username & password fields are editable', ()=>{ 10 | dialog.appBtn.click(); 11 | dialog.alertDialogBtn.click(); 12 | dialog.textEntryDialogBtn.click(); 13 | 14 | dialog.userNameField.addValue("Test User"); 15 | dialog.userNameField.clearValue(); 16 | dialog.userNameField.addValue("Actual User"); 17 | 18 | dialog.passwordField.clearValue(); 19 | dialog.passwordField.addValue("Test Pass"); 20 | 21 | let text = dialog.userNameField.getText(); 22 | console.log(text); 23 | expect(text).equal("Actual User"); 24 | 25 | dialog.dialogOkBtn.click(); 26 | }); 27 | 28 | it('Verify that the app adjust when orientation is switched', () => { 29 | console.log(driver.getOrientation()); 30 | driver.setOrientation('LANDSCAPE'); 31 | 32 | driver.saveScreenshot('./screenshots/landscape.png'); 33 | dialog.appBtn.click(); 34 | 35 | driver.setOrientation('PORTRAIT'); 36 | driver.back(); 37 | driver.saveScreenshot('./screenshots/portrait.png'); 38 | }); 39 | 40 | it('Verify isSelected, isEnabled & isDisplayed', () => { 41 | dialog.viewBtn.click(); 42 | driver.touchAction([ 43 | { action: 'press', x: 500, y: 1400 }, 44 | { action: 'moveTo', x: 500, y: 300 }, 45 | 'release', 46 | { action: 'press', x: 500, y: 1400 }, 47 | { action: 'moveTo', x: 500, y: 300 }, 48 | 'release', 49 | { action: 'press', x: 500, y: 1400 }, 50 | { action: 'moveTo', x: 500, y: 300 }, 51 | 'release' 52 | ]) 53 | 54 | dialog.tabsBtn.click(); 55 | dialog.contentByIdBtn.click(); 56 | 57 | let isEnabled, isSelected, isDisplayed; 58 | 59 | for(i=0; i<3; i++){ 60 | isEnabled = dialog.tabs[i].isEnabled(); 61 | isSelected = dialog.tabs[i].isSelected(); 62 | isDisplayed = dialog.tabs[i].isDisplayed(); 63 | 64 | console.log(`Tab ${i+1}`) 65 | console.log('isEnabled:', isEnabled); 66 | console.log('isSelected:', isSelected); 67 | console.log('isDisplayed:', isDisplayed); 68 | 69 | if(isEnabled && isSelected){ 70 | console.log("Tab Details 1:", dialog.tab1Details.isDisplayed()); 71 | console.log("Tab Details 2:", dialog.tab2Details.isDisplayed()); 72 | console.log("Tab Details 3:", dialog.tab3Details.isDisplayed()); 73 | } 74 | } 75 | }); 76 | 77 | it('Verify Timeouts', () => { 78 | //driver.setImplicitTimeout(10000); 79 | //driver.setTimeouts(10000); 80 | //driver.pause(10000); 81 | 82 | dialog.viewBtn.click(); 83 | //dialog.tabsBtn.click(); 84 | }); 85 | 86 | it('Verify the repeat alarm options has attribute checked set to true when selected', ()=>{ 87 | let isChecked, text; 88 | 89 | dialog.appBtn.click(); 90 | dialog.alertDialogBtn.click(); 91 | dialog.repeatAlarmBtn.click(); 92 | 93 | text = dialog._weekdayCheckbox(0).getText(); 94 | expect(text).equal('Every Monday'); 95 | 96 | isChecked = dialog._weekdayCheckbox(0).getAttribute('checked'); 97 | expect(isChecked).equal('false'); 98 | 99 | dialog._weekdayCheckbox(0).click(); 100 | 101 | isChecked = dialog._weekdayCheckbox(0).getAttribute('checked'); 102 | expect(isChecked).equal('true'); 103 | }); 104 | 105 | // Execute a block of code after every test 106 | afterEach(() => { 107 | driver.reset(); 108 | }); 109 | }) -------------------------------------------------------------------------------- /wdio.conf.js: -------------------------------------------------------------------------------- 1 | let { join } = require('path'); 2 | exports.config = { 3 | // 4 | // ==================== 5 | // Runner Configuration 6 | // ==================== 7 | // 8 | // WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or 9 | // on a remote machine). 10 | runner: 'local', 11 | port: 4723, 12 | // 13 | // ================== 14 | // Specify Test Files 15 | // ================== 16 | // Define which test specs should run. The pattern is relative to the directory 17 | // from which `wdio` was called. Notice that, if you are calling `wdio` from an 18 | // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working 19 | // directory is where your package.json resides, so `wdio` will be called from there. 20 | // 21 | specs: [ 22 | './test/specs/**/*.js' 23 | ], 24 | // Patterns to exclude. 25 | exclude: [ 26 | // 'path/to/excluded/files' 27 | ], 28 | // 29 | // ============ 30 | // Capabilities 31 | // ============ 32 | // Define your capabilities here. WebdriverIO can run multiple capabilities at the same 33 | // time. Depending on the number of capabilities, WebdriverIO launches several test 34 | // sessions. Within your capabilities you can overwrite the spec and exclude options in 35 | // order to group specific specs to a specific capability. 36 | // 37 | // First, you can define how many instances should be started at the same time. Let's 38 | // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have 39 | // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec 40 | // files and you set maxInstances to 10, all spec files will get tested at the same time 41 | // and 30 processes will get spawned. The property handles how many capabilities 42 | // from the same test should run tests. 43 | // 44 | maxInstances: 1, 45 | // 46 | // If you have trouble getting all important capabilities together, check out the 47 | // Sauce Labs platform configurator - a great tool to configure your capabilities: 48 | // https://docs.saucelabs.com/reference/platforms-configurator 49 | // 50 | capabilities: [{ 51 | platformName: 'Android', 52 | 'appium:deviceName': 'Pixel 2', 53 | 'appium:app': join(process.cwd(), './ApiDemos-debug.apk') 54 | }], 55 | // 56 | // =================== 57 | // Test Configurations 58 | // =================== 59 | // Define all options that are relevant for the WebdriverIO instance here 60 | // 61 | // Level of logging verbosity: trace | debug | info | warn | error | silent 62 | logLevel: 'error', 63 | // 64 | // Set specific log levels per logger 65 | // loggers: 66 | // - webdriver, webdriverio 67 | // - @wdio/applitools-service, @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service 68 | // - @wdio/mocha-framework, @wdio/jasmine-framework 69 | // - @wdio/local-runner, @wdio/lambda-runner 70 | // - @wdio/sumologic-reporter 71 | // - @wdio/cli, @wdio/config, @wdio/sync, @wdio/utils 72 | // Level of logging verbosity: trace | debug | info | warn | error | silent 73 | // logLevels: { 74 | // webdriver: 'info', 75 | // '@wdio/applitools-service': 'info' 76 | // }, 77 | // 78 | // If you only want to run your tests until a specific amount of tests have failed use 79 | // bail (default is 0 - don't bail, run all tests). 80 | bail: 0, 81 | // 82 | // Set a base URL in order to shorten url command calls. If your `url` parameter starts 83 | // with `/`, the base url gets prepended, not including the path portion of your baseUrl. 84 | // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url 85 | // gets prepended directly. 86 | baseUrl: 'http://localhost', 87 | // 88 | // Default timeout for all waitFor* commands. 89 | waitforTimeout: 10000, 90 | // 91 | // Default timeout in milliseconds for request 92 | // if Selenium Grid doesn't send response 93 | connectionRetryTimeout: 90000, 94 | // 95 | // Default request retries count 96 | connectionRetryCount: 3, 97 | // 98 | // Test runner services 99 | // Services take over a specific job you don't want to take care of. They enhance 100 | // your test setup with almost no effort. Unlike plugins, they don't add new 101 | // commands. Instead, they hook themselves up into the test process. 102 | services: ['selenium-standalone'], 103 | 104 | // Framework you want to run your specs with. 105 | // The following are supported: Mocha, Jasmine, and Cucumber 106 | // see also: https://webdriver.io/docs/frameworks.html 107 | // 108 | // Make sure you have the wdio adapter package for the specific framework installed 109 | // before running any tests. 110 | framework: 'mocha', 111 | // 112 | // The number of times to retry the entire specfile when it fails as a whole 113 | // specFileRetries: 1, 114 | // 115 | // Test reporter for stdout. 116 | // The only one supported by default is 'dot' 117 | // see also: https://webdriver.io/docs/dot-reporter.html 118 | reporters: ['spec'], 119 | 120 | // 121 | // Options to be passed to Mocha. 122 | // See the full list at http://mochajs.org/ 123 | mochaOpts: { 124 | ui: 'bdd', 125 | timeout: 60000 126 | }, 127 | // 128 | // ===== 129 | // Hooks 130 | // ===== 131 | // WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance 132 | // it and to build services around it. You can either apply a single function or an array of 133 | // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got 134 | // resolved to continue. 135 | /** 136 | * Gets executed once before all workers get launched. 137 | * @param {Object} config wdio configuration object 138 | * @param {Array.} capabilities list of capabilities details 139 | */ 140 | // onPrepare: function (config, capabilities) { 141 | // }, 142 | /** 143 | * Gets executed just before initialising the webdriver session and test framework. It allows you 144 | * to manipulate configurations depending on the capability or spec. 145 | * @param {Object} config wdio configuration object 146 | * @param {Array.} capabilities list of capabilities details 147 | * @param {Array.} specs List of spec file paths that are to be run 148 | */ 149 | // beforeSession: function (config, capabilities, specs) { 150 | // }, 151 | /** 152 | * Gets executed before test execution begins. At this point you can access to all global 153 | * variables like `browser`. It is the perfect place to define custom commands. 154 | * @param {Array.} capabilities list of capabilities details 155 | * @param {Array.} specs List of spec file paths that are to be run 156 | */ 157 | // before: function (capabilities, specs) { 158 | // }, 159 | /** 160 | * Runs before a WebdriverIO command gets executed. 161 | * @param {String} commandName hook command name 162 | * @param {Array} args arguments that command would receive 163 | */ 164 | // beforeCommand: function (commandName, args) { 165 | // }, 166 | /** 167 | * Hook that gets executed before the suite starts 168 | * @param {Object} suite suite details 169 | */ 170 | // beforeSuite: function (suite) { 171 | // }, 172 | /** 173 | * Function to be executed before a test (in Mocha/Jasmine) starts. 174 | */ 175 | // beforeTest: function (test, context) { 176 | // }, 177 | /** 178 | * Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling 179 | * beforeEach in Mocha) 180 | */ 181 | // beforeHook: function (test, context) { 182 | // }, 183 | /** 184 | * Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling 185 | * afterEach in Mocha) 186 | */ 187 | // afterHook: function (test, context, { error, result, duration, passed, retries }) { 188 | // }, 189 | /** 190 | * Function to be executed after a test (in Mocha/Jasmine). 191 | */ 192 | // afterTest: function(test, context, { error, result, duration, passed, retries }) { 193 | // }, 194 | 195 | 196 | /** 197 | * Hook that gets executed after the suite has ended 198 | * @param {Object} suite suite details 199 | */ 200 | // afterSuite: function (suite) { 201 | // }, 202 | /** 203 | * Runs after a WebdriverIO command gets executed 204 | * @param {String} commandName hook command name 205 | * @param {Array} args arguments that command would receive 206 | * @param {Number} result 0 - command success, 1 - command error 207 | * @param {Object} error error object if any 208 | */ 209 | // afterCommand: function (commandName, args, result, error) { 210 | // }, 211 | /** 212 | * Gets executed after all tests are done. You still have access to all global variables from 213 | * the test. 214 | * @param {Number} result 0 - test pass, 1 - test fail 215 | * @param {Array.} capabilities list of capabilities details 216 | * @param {Array.} specs List of spec file paths that ran 217 | */ 218 | // after: function (result, capabilities, specs) { 219 | // }, 220 | /** 221 | * Gets executed right after terminating the webdriver session. 222 | * @param {Object} config wdio configuration object 223 | * @param {Array.} capabilities list of capabilities details 224 | * @param {Array.} specs List of spec file paths that ran 225 | */ 226 | // afterSession: function (config, capabilities, specs) { 227 | // }, 228 | /** 229 | * Gets executed after all workers got shut down and the process is about to exit. An error 230 | * thrown in the onComplete hook will result in the test run failing. 231 | * @param {Object} exitCode 0 - success, 1 - fail 232 | * @param {Object} config wdio configuration object 233 | * @param {Array.} capabilities list of capabilities details 234 | * @param {} results object containing test results 235 | */ 236 | // onComplete: function(exitCode, config, capabilities, results) { 237 | // }, 238 | /** 239 | * Gets executed when a refresh happens. 240 | * @param {String} oldSessionId session ID of the old session 241 | * @param {String} newSessionId session ID of the new session 242 | */ 243 | //onReload: function(oldSessionId, newSessionId) { 244 | //} 245 | } 246 | --------------------------------------------------------------------------------