Best JavaScript code snippet using appium
icon_colors.js
Source:icon_colors.js
1"use strict";2module.exports = function () {3 require('colors');4 let wd = require("wd");5 let assert = require('assert');6 let asserters = wd.asserters;7 let _ = require('underscore');8 let Q = require('q');9 let fsExtra = require('fs-extra');10 let fs = require('fs');11 let pry = require('pryjs');12 const sql = require('mssql');13 let _p = require('../helpers/promise-utils');14 let elements = require('../helpers/elements');15 let actions = require('../helpers/actions');16 let store = require('../helpers/store');17 let config = require('../helpers/config');18 let serverConfigs = require('../helpers/appium-servers');19 let creds = require('../credentials');20 let sqlQuery = require('../helpers/queries');21 let serverConfig = process.env.SAUCE ? serverConfigs.sauce : serverConfigs.local;22 let args = process.argv.slice( 2 );23 let simulator = false;24 let desired;25 let driver = config.driver;26 let commons = require('../helpers/commons'); // this must be after the desired and driver are set27 describe("Test all icon colors", function() {28 let allPassed = true;29 console.log(('RUNNING ' + __filename.slice(__dirname.length + 1) + ' for iOS').green.bold.underline);30 it.skip('For debugging', function () {31 // config.theseNameAttrs = [];32 return driver33 .loginQuick()34 .elementById(elements.homeScreen.walkbooks)35 .click()36 .waitForElementById(elements.surveys.survey1, 10000)37 .elementById('Copy of Copy of Survey with Custom Email and for checking numbers')38 .click()39 .waitForElementById(elements.survey.start, 10000)40 .consoleLog('Waiting until spinner is gone to click start'.white.bold)41 .waitForElementToDisappearByClassName(elements.general.spinner)42 .consoleLog('All done!'.white.bold)43 .elementById(elements.survey.start)44 .click()45 .waitForElementByClassName('XCUIElementTypeTable', 10000)46 .then(sqlQuery.touchedHouses)47 .elementById('oopsie')48 //click walkbook49 .getFirstListItemByIdPart('walkbook_notstarted')50 .then(function () {51 console.log('about to click thisElem: ' + config.thisElem)52 return driver53 .sleep(15000) // testing to make sure thisElem is not redefined54 .elementById(config.thisElem) // should click cellWalkbook_155 .click()56 })57 .waitForElementById(elements.survey.popoverOpenBook, 10000)58 .click()59 .waitForElementByClassName('XCUIElementTypeTable', 10000)60 //click house61 .getFirstListItemByIdPart('cellHouse_3')62 .then(function () {63 console.log('Should click cellHouse_3, actually clicking ' + config.thisHousehold)64 return driver65 .sleep(10000)66 .elementById(config.thisHousehold)67 .click()68 })69 .then(function () {70 console.log('ALL DONE!'.green.bold.underline)71 return driver72 .elementById('oopsie')73 })74 .waitForElementById(elements.walkbook.popoverOpenHouse)75 .click()76 .waitForElementById(elements.houseHold.notHome)77 //works:78 .elementByXPath("//*/XCUIElementTypeScrollView[1]/XCUIElementTypeOther[1]") // target button area79 .elementsByClassName('>','XCUIElementTypeButton') // all button elements in the above context80 .saveAllNameAttributes('cellContact_', 'theseNameAttrs')81 .then(function () {82 let regexp = new RegExp('^prim_cellContact_\\d+$', 'i');83 var prom;84 for (let i = 0; i < config.theseNameAttrs.length; i++) {85 // take survey with all primary targets86 if (regexp.test(config.theseNameAttrs[i])) {87 let thisTarget = config.theseNameAttrs[i];88 if (i == 0) {89 prom = commons.takeSurveyTemp(thisTarget);90 } else {91 prom = prom.then(function () {92 return commons.takeSurveyTemp(thisTarget)93 })94 }95 }96 }97 return prom;98 })99 .consoleLog('TEST CASE IS OVER'.red.bold.underline) //surveys should have been taken with all primary targets and no non-primary targets.100 });101 it.skip('Should perform a full login', function () {102 return driver103 .fullLogin(creds.testUserName1, creds.testUserPwd1)104 });105 it('Should login quick', function () {106 return driver107 .loginQuick()108 });109 it('Should turn the house green: survey both primary targets', function () {110 config.housesWithMoreThan1Primary = {}111 config.theseHouses = [];112 config.thisHouseholdAfter = '';113 config.thisSurvey = '';114 config.thisHousehold = '';115 config.thisElem = '';116 /*117 Abstract:118 Use SQL to unassign all walkbooks for the helper, then reassign walkbooks in the current survey that contain multiple primary targets119 Use SQL to create an array of walkbook-household object pairs, of houses in walkbooks that have multiple primary targets120 Select a house from the list we created and survey all primary targets121 Verify house is green122 */123 return driver124 // .consoleLog(stackTrace.get()[1].getFileName() + stackTrace.get()[1].getLineNumber()) // todo experiment with this125 .startTime('Home Page to Household')126 .elementById(elements.homeScreen.walkbooks)127 .click()128 .startTime('Load Survey List')129 .waitForElementById(elements.surveys.survey1, 10000)130 .endTotalAndLogTime('Load Survey List')131 .elementById('DO NOT USE: Mobile Automation Survey 1.0')132 .click()133 .waitForElementById(elements.survey.start, 10000)134 .consoleLog('Making sure spinner is gone before trying to click start'.white.bold)135 .waitForElementToDisappearByClassName(elements.general.spinner)136 .consoleLog('Spinner is gone'.white.bold)137 .elementByXPath('//*/XCUIElementTypeNavigationBar[1]/XCUIElementTypeStaticText[1]') // > get and store the survey name ...138 .then(function (el) {139 return el.getAttribute('name').then(function (attr) {140 config.thisSurvey = attr;141 })142 })143 .then(sqlQuery.assignBooksWithMultiplePrimaries) // > unassign and reassign walkbooks with multiple primary targets ...144 .elementById(elements.survey.start)145 .click()146 .startTime('Load Survey')147 .waitForElementByClassName('XCUIElementTypeTable', 10000)148 .endTotalAndLogTime('Load Survey')149 .getFirstListItemByIdPart(elements.survey.walkbook1) // > choose first walkbook in the list ...150 .then(function () {151 return driver152 .elementById(config.thisElem)153 .click()154 })155 .waitForElementById(elements.survey.popoverOpenBook, 10000)156 .click()157 .startTime('Load Walkbook')158 .waitForElementByClassName('XCUIElementTypeTable', 10000)159 .endTotalAndLogTime('Load Walkbook')160 .getHouseWithMultPrimary() // > find the first house in the list that contains multiple primary targets ...161 .then(function () {162 return driver163 .getFirstListItemByIdPart(config.thisHousehold)164 })165 .surveyAllPrimaryTargets() // > survey all primary targets - requires config.thisHousehold to be defined.166 .then(function () {167 config.thisHouseholdAfter = config.thisHousehold.replace('notstarted', 'complete');168 })169 //todo fix - config.thisHouseholdAfter is empty and returning a positive result regardless170 .waitForElementById(config.thisHouseholdAfter, 10000) // > verify the house is green before refresh171 .consoleLog(('Household color/status check passed - before refresh. config.thisHouseholdAfter = '172 + config.thisHouseholdAfter + '\nTest: ' + config.currentTest.title).green.bold)173 .refreshHouseList()174 .sleep(1000)175 .waitForElementById(config.thisHouseholdAfter, 10000) // > verify the house is green after refresh176 .consoleLog(('Household color/status check passed - after refresh. config.thisHouseholdAfter = '177 + config.thisHouseholdAfter + '\nTest: ' + config.currentTest.title).green.bold)178 .consoleLog('TEST CASE IS OVER'.green.bold.underline)179 });180 it('Should turn the house blue: one primary target not home', function () {181 config.thisHousehold = '';182 // Survey: DO NOT USE: Mobile Automation Survey 1.0183 // todo - test this when there is more than one primary target184 return driver185 .sleep(1)186 .then(function () {187 //if we're not running in dbg mode, reset the app188 if( !process.argv.slice(2).includes("--dbg") ) {189 return driver190 .resetApp()191 .loginQuick()192 .homeToHouseList()193 }194 })195 .getFirstListItemByIdPart('notstarted')196 .then(function () {197 return driver198 .elementById(config.thisHousehold)199 .click()200 })201 .then(function () {202 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);203 let thisHouseholdAfter = config.thisHousehold.replace('notstarted','attempted');204 return driver205 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)206 .elementById(elements.walkbook.popoverOpenHouse)207 .click()208 .waitForElementById(elements.houseHold.notHome, 10000)209 .endTotalAndLogTime('Home Page to Household')210 .elementById(elements.houseHold.primTarget1)211 .click()212 .waitForElementById(elements.target.takeSurvey, 10000)213 .elementById(elements.target.notHome)214 .click()215 .waitForElementById(elements.houseHold.finished, 10000)216 .click()217 .waitForElementById(thisHouseholdAfter, 10000) // verify the house is blue218 .consoleLog('Household color/status check passed - before refresh - Test: ' + config.currentTest.title)219 .refreshHouseList()220 .sleep(1000)221 .waitForElementById(thisHouseholdAfter, 10000) // verify the house is blue after refresh222 .consoleLog('Household color/status check passed - after refresh - Test: ' + config.currentTest.title)223 });224 });225 it('Should turn the house red: wrong address house', function () {226 config.thisHousehold = '';227 // Survey: DO NOT USE: Mobile Automation Survey 1.0228 return driver229 // save household IDs:230 .sleep(1)231 .then(function () {232 //if we're not running in dbg mode, reset the app and navigate to house list233 if( !process.argv.slice(2).includes("--dbg") ) {234 return driver235 .resetApp()236 .loginQuick()237 .homeToHouseList()238 }239 })240 .getFirstListItemByIdPart('notstarted')241 .then(function () {242 return driver243 .elementById(config.thisHousehold)244 .click()245 })246 .then(function () {247 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);248 let thisHouseholdAfter = config.thisHousehold.replace('notstarted','reject');249 return driver250 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)251 .elementById(elements.walkbook.popoverOpenHouse)252 .click()253 .waitForElementById(elements.houseHold.wrongAddress, 10000)254 .elementById(elements.houseHold.wrongAddress)255 .click()256 .waitForElementByClassName('XCUIElementTypeTable', 10000) // wait for the house list257 .waitForElementById(thisHouseholdAfter, 10000) // verify house258 .consoleLog('Household color/status check passed - before refresh - Test: ' + config.currentTest.title)259 .refreshHouseList()260 .waitForElementById(thisHouseholdAfter, 10000) // verify house after refresh261 .consoleLog('Household color/status check passed - after refresh - Test: ' + config.currentTest.title)262 });263 });264 it('Should turn the house red: refused house', function () {265 config.thisHousehold = '';266 // Survey: DO NOT USE: Mobile Automation Survey 1.0267 return driver268 // save household IDs:269 .sleep(1)270 .then(function () {271 //if we're not running in dbg mode, reset the app272 if( !process.argv.slice(2).includes("--dbg") ) {273 return driver274 .resetApp()275 .loginQuick()276 .homeToHouseList()277 }278 })279 .getFirstListItemByIdPart('notstarted')280 .then(function () {281 return driver282 .elementById(config.thisHousehold)283 .click()284 })285 .then(function () {286 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);287 let thisHouseholdAfter = config.thisHousehold.replace('notstarted','reject');288 return driver289 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)290 .elementById(elements.walkbook.popoverOpenHouse)291 .click()292 .waitForElementById(elements.houseHold.refused, 10000)293 .elementById(elements.houseHold.refused)294 .click()295 .waitForElementByClassName('XCUIElementTypeTable', 10000) // wait for the house list296 .waitForElementById(thisHouseholdAfter, 10000) // verify house297 .consoleLog('Household color/status check passed - before refresh - Test: ' + config.currentTest.title)298 .refreshHouseList()299 .waitForElementById(thisHouseholdAfter, 10000) // verify house after refresh300 .consoleLog('Household color/status check passed - after refresh - Test: ' + config.currentTest.title)301 });302 });303 it('Should turn the house blue: not home house', function () {304 config.thisHousehold = '';305 // Survey: DO NOT USE: Mobile Automation Survey 1.0306 return driver307 .sleep(1)308 .then(function () {309 //if we're not running in dbg mode, reset the app310 if( !process.argv.slice(2).includes("--dbg") ) {311 return driver312 .resetApp()313 .loginQuick()314 .homeToHouseList()315 }316 })317 .getFirstListItemByIdPart('notstarted')318 .then(function () {319 return driver320 .elementById(config.thisHousehold)321 .click()322 })323 .then(function () {324 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);325 let thisHouseholdAfter = config.thisHousehold.replace('notstarted','attempted');326 return driver327 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)328 .click()329 .waitForElementById(elements.houseHold.notHome, 10000)330 .elementById(elements.houseHold.notHome)331 .click()332 .waitForElementByClassName('XCUIElementTypeTable', 10000) // wait for the house list333 .waitForElementById(thisHouseholdAfter, 10000) // verify house is blue334 .consoleLog('Household color/status check passed - before refresh - Test: ' + config.currentTest.title)335 .refreshHouseList()336 .waitForElementById(thisHouseholdAfter, 10000) // verify house after refresh337 .consoleLog('Household color/status check passed - after refresh - Test: ' + config.currentTest.title)338 });339 });340 it('TRANSITION: blue to red: one primary not home --> restricted access house', function () {341 config.thisHousehold = '';342 // todo probably make this "any blue"343 // Survey: DO NOT USE: Mobile Automation Survey 1.0344 return driver345 // save household IDs:346 .sleep(1)347 .then(function () {348 //if we're not running in dbg mode, reset the app349 if( !process.argv.slice(2).includes("--dbg") ) {350 return driver351 .resetApp()352 .loginQuick()353 .homeToHouseList()354 }355 })356 .getFirstListItemByIdPart('attempted')357 .then(function () {358 return driver359 .elementById(config.thisHousehold)360 .click()361 })362 .then(function () {363 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);364 let thisHouseholdAfter = config.thisHousehold.replace('attempted','reject');365 return driver366 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)367 .elementById(elements.walkbook.popoverOpenHouse)368 .click()369 .waitForElementById(elements.houseHold.restricted, 10000)370 .click()371 .waitForElementByClassName('XCUIElementTypeTable', 10000) // wait for the house list372 .waitForElementById(thisHouseholdAfter, 10000) // verify house is blue373 .consoleLog('Household color/status check passed - before refresh - Test: ' + config.currentTest.title)374 .refreshHouseList()375 .sleep(1000)376 .waitForElementById(thisHouseholdAfter, 10000) // verify the house is blue after refresh377 .consoleLog('Household color/status check passed - after refresh - Test: ' + config.currentTest.title)378 });379 });380 it('REPORTING BUSINESS RULE 4 (multiple dispositions) & TRANSITION (red to blue: restricted house --> not home house)', function () {381 config.thisHousehold = '';382 // todo probably make this "any red"383 // Survey: DO NOT USE: Mobile Automation Survey 1.0384 return driver385 // save household IDs:386 .sleep(1)387 .then(function () {388 //if we're not running in dbg mode, reset the app389 if( !process.argv.slice(2).includes("--dbg") ) {390 return driver391 .resetApp()392 .loginQuick()393 .homeToHouseList()394 }395 })396 .getFirstListItemByIdPart('reject')397 .then(function () {398 return driver399 .elementById(config.thisHousehold)400 .click()401 })402 .then(function () {403 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);404 let thisHouseholdAfter = config.thisHousehold.replace('reject','attempted');405 return driver406 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)407 .elementById(elements.walkbook.popoverOpenHouse)408 .click()409 .waitForElementById(elements.houseHold.notHome, 10000)410 .elementById(elements.houseHold.notHome)411 .click()412 .waitForElementByClassName('XCUIElementTypeTable', 10000) // wait for the house list413 .waitForElementById(config.thisHousehold, 10000) // house is still red - new reporting should have processed business rule 4. Must refresh to see correct household color.414 .consoleLog('Household color/status check passed - before refresh - Test: ' + config.currentTest.title)415 .refreshHouseList()416 .waitForElementById(thisHouseholdAfter, 10000) // verify the house is blue after refresh417 .consoleLog('Household color/status check passed - after refresh - Test: ' + config.currentTest.title)418 });419 });420 it('TRANSITION: blue to green: not home house --> take survey all primary', function () {421 config.housesWithMoreThan1Primary = {}422 config.theseHouses = [];423 config.thisHouseholdAfter = '';424 config.thisSurvey = '';425 config.thisHousehold = '';426 config.thisElem = '';427 // todo probably make this "any blue"428 return driver429 .sleep(1)430 .then(function () {431 //if we're not running in dbg mode, reset the app432 if( !process.argv.slice(2).includes("--dbg") ) {433 return driver434 .resetApp()435 .loginQuick()436 .homeToHouseList()437 }438 })439 //generate an 'attempted' house440 .getFirstListItemByIdPart('notstarted')441 .then(function () {442 console.log('About to attempt clicking a notstarted house to generate a not home'.white.bold)443 return driver444 .elementById(config.thisHousehold)445 .click()446 })447 .then(function () {448 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);449 let thisHouseholdAfter = config.thisHousehold.replace('notstarted','attempted');450 return driver451 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)452 .elementById(elements.walkbook.popoverOpenHouse)453 .click()454 .waitForElementById(elements.houseHold.notHome, 10000)455 .elementById(elements.houseHold.notHome)456 .click()457 .waitForElementByClassName('XCUIElementTypeTable', 10000) // wait for the house list458 .waitForElementById(thisHouseholdAfter, 10000) // verify house is blue459 })460 //surveying all primary targets in a house that was previously attempted should turn it green.461 .then(function () {462 let thisHousehold = config.thisHousehold.replace('notstarted','attempted');463 if (/notstarted/.test(config.thisHousehold)) {464 config.thisHouseholdAfter = config.thisHousehold.replace('notstarted', 'complete') //trying this465 } else if (/attempted/.test(config.thisHousehold)) {466 config.thisHouseholdAfter = config.thisHousehold.replace('attempted', 'complete') //trying this467 }468 config.thisHousehold = thisHousehold;469 return driver470 .surveyAllPrimaryTargets()471 .waitForElementById(config.thisHouseholdAfter, 10000) // > verify the house is green before refresh472 .consoleLog(('Household color/status check passed - before refresh. config.thisHouseholdAfter = '473 + config.thisHouseholdAfter + '\nTest: ' + config.currentTest.title).green.bold)474 .refreshHouseList()475 .sleep(1000)476 .waitForElementById(config.thisHouseholdAfter, 10000) // > verify the house is green after refresh477 .consoleLog(('Household color/status check passed - after refresh. config.thisHouseholdAfter = '478 + config.thisHouseholdAfter + '\nTest: ' + config.currentTest.title).green.bold)479 .consoleLog('TEST CASE IS OVER'.green.bold.underline)480 })481 });482 it('TRANSITION: blue to red: not home house --> refused house', function () {483 config.housesWithMoreThan1Primary = {}484 config.theseHouses = [];485 config.thisHouseholdAfter = '';486 config.thisSurvey = '';487 config.thisHousehold = '';488 config.thisElem = '';489 // todo probably make this "any blue"490 // Survey: DO NOT USE: Mobile Automation Survey 1.0491 return driver492 .sleep(1)493 .then(function () {494 //if we're not running in dbg mode, reset the app495 if( !process.argv.slice(2).includes("--dbg") ) {496 return driver497 .resetApp()498 .loginQuick()499 .homeToHouseList()500 }501 })502 .getFirstListItemByIdPart('notstarted')503 .then(function () {504 console.log('About to attempt clicking a notstarted house to generate a not home'.white.bold)505 return driver506 .elementById(config.thisHousehold)507 .click()508 })509 // generate a "not home house"510 .then(function () {511 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);512 let thisHouseholdAfter = config.thisHousehold.replace('notstarted','attempted');513 return driver514 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)515 .elementById(elements.walkbook.popoverOpenHouse)516 .click()517 .waitForElementById(elements.houseHold.notHome, 10000)518 .elementById(elements.houseHold.notHome)519 .click()520 .waitForElementByClassName('XCUIElementTypeTable', 10000) // wait for the house list521 .waitForElementById(thisHouseholdAfter, 10000) // verify house is blue522 .then(function () {523 if (config.houseNum > 10){524 return driver525 .execute('mobile: scroll', {direction: 'up'}) // scroll up if we were at the bottom526 }527 })528 })529 .getFirstListItemByIdPart('attempted')530 .then(function () {531 return driver532 .elementById(config.thisHousehold)533 .click()534 })535 // from not home => refused536 .then(function () {537 console.log('Using ' + config.thisHousehold + ', houseNum ' + config.houseNum);538 let thisHouseholdAfter = config.thisHousehold.replace('attempted','reject');539 return driver540 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)541 .elementById(elements.walkbook.popoverOpenHouse)542 .click()543 .waitForElementById(elements.houseHold.refused, 10000)544 .elementById(elements.houseHold.refused)545 .click()546 .waitForElementByClassName('XCUIElementTypeTable', 10000) // wait for the house list547 .waitForElementById(thisHouseholdAfter, 10000) // verify house548 .consoleLog('Household color/status check passed - before refresh - Test: ' + config.currentTest.title)549 .refreshHouseList()550 .waitForElementById(thisHouseholdAfter, 10000) // verify house after refresh551 .consoleLog('Household color/status check passed - after refresh - Test: ' + config.currentTest.title)552 });553 });554 });...
walkbooks_smoke_tests.js
Source:walkbooks_smoke_tests.js
1"use strict";2module.exports = function () {3 4 require('colors');5 let wd = require("wd");6 let assert = require('assert');7 let asserters = wd.asserters;8 let _ = require('underscore');9 let Q = require('q');10 let fsExtra = require('fs-extra');11 let fs = require('fs');12 let pry = require('pryjs');13 const sql = require('mssql');14 let _p = require('../helpers/promise-utils');15 let elements = require('../helpers/elements');16 let actions = require('../helpers/actions');17 let store = require('../helpers/store');18 let config = require('../helpers/config');19 let serverConfigs = require('../helpers/appium-servers');20 let creds = require('../credentials');21 let sqlQuery = require('../helpers/queries');22 let serverConfig = process.env.SAUCE ? serverConfigs.sauce : serverConfigs.local;23 let args = process.argv.slice( 2 );24 let simulator = false;25 let desired;26 let driver = config.driver;27 let commons = require('../helpers/commons'); // this must be after the desired and driver are set28 // all passing 6-20-1729 describe("Walkbooks smoke tests, start to household", function() {30 let allPassed = true;31 console.log(('RUNNING ' + __filename.slice(__dirname.length + 1)).green.bold.underline)32 config.thisSurvey = ''33 it('Login quick', function () {34 return driver35 .loginQuick()36 });37 it('Load survey list', function () {38 return driver39 .sleep(1)40 .then(function () {41 //if we're not running in dbg mode, reset the app42 if( !process.argv.slice(2).includes("--dbg") ) {43 return driver44 .resetApp()45 .loginQuick()46 }47 })48 .elementById(elements.homeScreen.walkbooks)49 .click()50 .startTime('Load Survey List')51 .waitForElementById(elements.surveys.survey1, 30000)52 .endTotalAndLogTime('Load Survey List')53 });54 it('Open survey', function () {55 return driver56 .sleep(1)57 .then(function () {58 //if we're not running in dbg mode, reset the app59 if( !process.argv.slice(2).includes("--dbg") ) {60 return driver61 .resetApp()62 .loginQuick()63 .elementById(elements.homeScreen.walkbooks)64 .click()65 .waitForElementById(elements.surveys.survey1, 30000)66 }67 })68 .elementById(elements.surveys.survey1)69 .click()70 .startTime('Open survey')71 .consoleLog('Waiting until spinner is gone'.white.bold)72 .waitForElementToDisappearByClassName(elements.general.spinner)73 .consoleLog('Spinner is gone'.white.bold)74 .waitForElementById(elements.survey.start, 30000)75 .endTotalAndLogTime('Open survey')76 //todo look up disclaimer text with sql and assert that it's present77 //todo assert the title is not blank i.e. title !== ''78 });79 it('Open survey preview', function () {80 return driver81 .sleep(1)82 .then(function () {83 //if we're not running in dbg mode, reset the app84 if( !process.argv.slice(2).includes("--dbg") ) {85 return driver86 .resetApp()87 .loginQuick()88 .elementById(elements.homeScreen.walkbooks)89 .click()90 .waitForElementById(elements.surveys.survey1, 30000)91 .click()92 }93 })94 .consoleLog('Waiting for spinner to disappear'.white.bold)95 .waitForElementToDisappearByClassName(elements.general.spinner)96 .consoleLog('Spinner is gone'.white.bold)97 .elementByXPath('//*/XCUIElementTypeNavigationBar[1]/XCUIElementTypeStaticText[1]') // > get and store the survey name ...98 .then(function (el) {99 return el.getAttribute('name').then(function (attr) {100 config.thisSurvey = attr;101 })102 })103 .waitForElementById(elements.survey.previewQuestions, 30000)104 .click()105 .startTime('Load survey preview')106 .waitForElementById(config.thisSurvey) // back button on survey preview page107 .endTotalAndLogTime('Load survey preview')108 //todo look up the survey questions in sql and assert the text is shown109 .back()110 });111 it('Start survey', function () {112 return driver113 .sleep(1)114 .then(function () {115 //if we're not running in dbg mode, reset the app116 if( !process.argv.slice(2).includes("--dbg") ) {117 return driver118 .resetApp()119 .loginQuick()120 .elementById(elements.homeScreen.walkbooks)121 .click()122 .waitForElementById(elements.surveys.survey1, 30000)123 .click()124 }125 })126 .consoleLog('Making sure spinner is gone before trying to click start'.white.bold)127 .waitForElementToDisappearByClassName(elements.general.spinner)128 .consoleLog('Spinner is gone'.white.bold)129 .waitForElementById(elements.survey.start,30000)130 .click()131 .startTime('Load Survey')132 .waitForElementByClassName('XCUIElementTypeTable', 30000)133 .endTotalAndLogTime('Load Survey')134 });135 it('Open a walkbook', function () {136 return driver137 .sleep(1)138 .then(function () {139 //if we're not running in dbg mode, reset the app140 if( !process.argv.slice(2).includes("--dbg") ) {141 return driver142 .resetApp()143 .loginQuick()144 .elementById(elements.homeScreen.walkbooks)145 .click()146 .waitForElementById(elements.surveys.survey1, 30000)147 .click()148 .consoleLog('Making sure spinner is gone before trying to click start'.white.bold)149 .waitForElementToDisappearByClassName(elements.general.spinner)150 .consoleLog('Spinner is gone'.white.bold)151 .waitForElementById(elements.survey.start,30000)152 .click()153 }154 })155 .waitForElementByClassName('XCUIElementTypeTable',30000)156 .getFirstListItemByIdPart(elements.survey.walkbook1) // > choose first walkbook in the list ...157 .then(function () {158 return driver159 .elementById(config.thisElem)160 .click()161 })162 .waitForElementById(elements.survey.popoverOpenBook, 30000)163 .click()164 .startTime('Load Walkbook')165 .waitForElementByClassName('XCUIElementTypeTable', 30000)166 .endTotalAndLogTime('Load Walkbook')167 });168 it('Open household and verify elements', function () {169 return driver170 .sleep(1)171 .then(function () {172 //if we're not running in dbg mode, reset the app173 if( !process.argv.slice(2).includes("--dbg") ) {174 return driver175 .resetApp()176 .loginQuick()177 .homeToHouseList()178 }179 })180 .getFirstListItemByIdPart(elements.walkbook.houseHold1)181 .then(function () {182 return driver183 .elementById(config.thisHousehold)184 .click()185 })186 .waitForElementById(elements.walkbook.popoverOpenHouse, 10000)187 .click()188 .startTime('Load Household')189 .waitForElementById(elements.houseHold.notHome, 30000)190 .endTotalAndLogTime('Load Household')191 .elementById(elements.houseHold.refused)192 .elementById(elements.houseHold.wrongAddress)193 .elementById(elements.houseHold.restricted)194 .elementById(elements.houseHold.addContact)195 .elementById(elements.houseHold.finished)196 });197 });...
Signup.spec.js
Source:Signup.spec.js
...10 await selector.addValue("10")11 selector = await ageNextButtonPOM()12 await selector.click()13 expect(selector).exist("Next")14 await driver.resetApp();15 })16 it('Signup with invalid age2', async () =>{17 selector = await signupButtonPOM();18 await selector.click()19 selector= await emailSignupButtonPOM();20 await selector.click()21 selector = ageTextBoxPOM()22 await selector.addValue("140")23 selector = await ageNextButtonPOM()24 await selector.click()25 expect(selector).exist("Next")26 await driver.resetApp();27 })28 it('Full valid test through profile icon', async () => {29 30 selector = await signupButtonPOM();31 await selector.click()32 selector= await emailSignupButtonPOM();33 await selector.click()34 selector = ageTextBoxPOM()35 await selector.addValue("10")36 selector = await ageNextButtonPOM()37 await selector.click()38 expect(selector).exist("Next")39 await driver.resetApp();40 /*For real application and cross testing Interests needs to be added*/41 selector = await 'new UiSelector().text("Trending")'42 intrest = await $(`android=${selector}`).click()43 selector = await 'new UiSelector().text("F1")'44 intrest = await $(`android=${selector}`).click()45 selector = await 'new UiSelector().text("Tgcf")'46 intrest = await $(`android=${selector}`).click()47 selector = await 'new UiSelector().text("Ski Jumping")'48 intrest = await $(`android=${selector}`).click()49 selector = await 'new UiSelector().text("Pierre Gasly")'50 intrest = await $(`android=${selector}`).click()51 52 selector = await 'new UiSelector().resourceId("com.tumblr:id/next_button")'53 const intrestsNext = await $(`android=${selector}`).click()54 /********************************************************************/55 selector = await profileButtonPOM();56 await selector.click()57 58 selector = await emailTextBoxPOM()59 await selector.addValue("ziad@gmail.com")60 selector = await passwordTextBoxPOM()61 await selector.addValue("Qwer1234##")62 selector = await nameTextBoxPOM()63 await selector.addValue("ssthsrth2lm")64 selector = await signupDoneButtonPOM()65 await selector.click()66 driver.waitUntil (()=>selector)67 })68 it('Full valid test through message icon', async () => {69 70 selector = await signupButtonPOM();71 await selector.click()72 selector= await emailSignupButtonPOM();73 await selector.click()74 selector = ageTextBoxPOM()75 await selector.addValue("10")76 selector = await ageNextButtonPOM()77 await selector.click()78 expect(selector).exist("Next")79 await driver.resetApp();80 /*For real application and cross testing Interests needs to be added*/81 selector = await 'new UiSelector().text("Trending")'82 intrest = await $(`android=${selector}`).click()83 selector = await 'new UiSelector().text("F1")'84 intrest = await $(`android=${selector}`).click()85 selector = await 'new UiSelector().text("Tgcf")'86 intrest = await $(`android=${selector}`).click()87 selector = await 'new UiSelector().text("Ski Jumping")'88 intrest = await $(`android=${selector}`).click()89 selector = await 'new UiSelector().text("Pierre Gasly")'90 intrest = await $(`android=${selector}`).click()91 92 selector = await 'new UiSelector().resourceId("com.tumblr:id/next_button")'93 const intrestsNext = await $(`android=${selector}`).click()94 /********************************************************************/95 selector = await messageButtonPOM();96 await selector.click()97 98 selector = await emailTextBoxPOM()99 await selector.addValue("ziad@gmail.com")100 selector = await passwordTextBoxPOM()101 await selector.addValue("Qwer1234##")102 selector = await nameTextBoxPOM()103 await selector.addValue("ssthsrth2lm")104 selector = await signupDoneButtonPOM()105 await selector.click()106 driver.waitUntil (()=>selector)107 })108 it('Full valid test through post icon', async () => {109 110 selector = await signupButtonPOM();111 await selector.click()112 selector= await emailSignupButtonPOM();113 await selector.click()114 selector = ageTextBoxPOM()115 await selector.addValue("10")116 selector = await ageNextButtonPOM()117 await selector.click()118 expect(selector).exist("Next")119 await driver.resetApp();120 /*For real application and cross testing Interests needs to be added*/121 selector = await 'new UiSelector().text("Trending")'122 intrest = await $(`android=${selector}`).click()123 selector = await 'new UiSelector().text("F1")'124 intrest = await $(`android=${selector}`).click()125 selector = await 'new UiSelector().text("Tgcf")'126 intrest = await $(`android=${selector}`).click()127 selector = await 'new UiSelector().text("Ski Jumping")'128 intrest = await $(`android=${selector}`).click()129 selector = await 'new UiSelector().text("Pierre Gasly")'130 intrest = await $(`android=${selector}`).click()131 132 selector = await 'new UiSelector().resourceId("com.tumblr:id/next_button")'133 const intrestsNext = await $(`android=${selector}`).click()...
context-e2e-specs.js
Source:context-e2e-specs.js
...44 await driver.context(NATIVE);45 await driver.elementByXPath(NATIVE_LOCATOR);46 });47 it('should be able to go into native context and interact with it after resetting app', async function () {48 await driver.resetApp();49 await driver.context(NATIVE);50 await driver.elementByXPath(NATIVE_LOCATOR);51 });52 it('should be able to go into webview context and interact with it after restarting app', async function () {53 // TODO: Fix this on TestObject. Chromedriver does not exist error54 if (process.env.TESTOBJECT_E2E_TESTS) {55 this.skip();56 }57 await driver.closeApp();58 await driver.launchApp();59 await driver.context(WEBVIEW);60 await driver.elementByXPath(WEBVIEW_LOCATOR);61 });62 it('should be able to go into webview context and interact with it after resetting app', async function () {63 // TODO: Fix this on TestObject. Chromedriver does not exist error64 if (process.env.TESTOBJECT_E2E_TESTS) {65 this.skip();66 }67 await driver.resetApp();68 await driver.context(WEBVIEW);69 await driver.elementByXPath(WEBVIEW_LOCATOR);70 });71 });72 describe('autoWebview', function () {73 let driver;74 afterEach(async function () {75 await deleteSession();76 });77 it('should enter into the webview', async function () {78 driver = await initSession(Object.assign({}, caps, {79 autoWebview: true,80 autoWebviewTimeout: 20000,81 }));...
reset.js
Source:reset.js
...18 }19 return back(driver, 3).setImplicitWaitTimeout(env.IMPLICIT_WAIT_TIMEOUT);20};21// module.exports = function (driver) {22// return driver.resetApp();...
hooks.js
Source:hooks.js
...10 search.asset_counter = 0;11 search.subfilter_number = 0;12 search.element_position= 0;13 helper._counter = 0;14 browser.driver.resetApp();15 });...
Header.ios.test.js
Source:Header.ios.test.js
...3 let driver;4 runApp();5 beforeEach(async () => {6 driver = await getDriver();7 await driver.resetApp();8 await driver.setImplicitWaitTimeout(20000);9 });10 it('should get "Albums"', async () => {11 const header = await driver.elementByAccessibilityId('Header');12 const text = await header.elementByXPath('//XCUIElementTypeStaticText[1]');13 expect(await text.text()).to.equal('Albums');14 });...
Header.android.test.js
Source:Header.android.test.js
...3 let driver;4 runApp();5 beforeEach(async () => {6 driver = await getDriver();7 await driver.resetApp();8 await driver.setImplicitWaitTimeout(20000);9 });10 it('should get "Albums"', async () => {11 const header = await driver.elementByAccessibilityId('Header');12 const text = await header.elementByXPath('//android.widget.TextView[1]');13 expect(await text.text()).to.equal('Albums');14 });...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12driver.resetApp();13driver.resetApp();14driver.resetApp();
Using AI Code Generation
1var webdriverio = require('webdriverio');2var assert = require('assert');3var options = {4 desiredCapabilities: {5 }6};7 .remote(options)8 .init()9 .getTitle().then(function(title) {10 console.log('Title was: ' + title);11 })12 .pause(5000)13 .resetApp()14 .getTitle().then(function(title) {15 console.log('Title was: ' + title);16 })17 .end();18Error: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.example.salmanahmad.myapp' application. Make sure it is a debuggable build. Original error: Error executing adbExec. Original error: 'Command '/Users/salmanahmad/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start -W -n com.example.salmanahmad.myapp/com.example.salmanahmad.myapp.MainActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000' exited with code 255'; Stderr: 'Exception occurred while executing:19 at android.content.Intent.addCategory(Intent.java:4102)20 at com.android.commands.am.Am.runStart(Am.java:509)21 at com.android.commands.am.Am.onRun(Am.java:280)22 at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)23 at com.android.commands.am.Am.main(Am.java:79)24 at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desired)7 .elementById('App')8 .click()9 .elementById('Activity')10 .click()11 .elementById('Custom Title')12 .click()13 .elementById('Graphics')14 .click()15 .elementById('Arcs')16 .click()17 .elementById('graphics_arc1')18 .click()19 .elementById('graphics_arc2')20 .click()21 .elementById('graphics_arc3')22 .click()23 .elementById('graphics_arc4')24 .click()25 .elementById('graphics_arc5')26 .click()27 .elementById('graphics_arc6')28 .click()29 .elementById('graphics_arc7')30 .click()31 .elementById('graphics_arc8')32 .click()33 .elementById('graphics_arc9')34 .click()35 .elementById('graphics_arc10')36 .click()37 .elementById('graphics_arc11')38 .click()39 .elementById('graphics_arc12')40 .click()41 .elementById('graphics_arc13')42 .click()43 .elementById('graphics_arc14')44 .click()45 .elementById('graphics_arc15')46 .click()47 .elementById('graphics_arc16')48 .click()49 .elementById('graphics_arc17')50 .click()51 .elementById('graphics_arc18')52 .click()53 .elementById('graphics_arc19')54 .click()55 .elementById('graphics_arc20')56 .click()57 .elementById('graphics_arc21')58 .click()59 .elementById('graphics_arc22')60 .click()61 .elementById('graphics_arc23')62 .click()63 .elementById('graphics_arc24')64 .click()65 .elementById('graphics_arc25')66 .click()67 .elementById('graphics_arc26')68 .click()69 .elementById('graphics_arc27
Using AI Code Generation
1var wd = require('wd'),2 assert = require('assert');3var browser = wd.remote("localhost", 4723);4browser.init({5}, function() {6 browser.elementById("lst-ib", function(err, el) {7 el.sendKeys("Hello World!", function() {8 browser.elementById("tsbb", function(err, el) {9 el.click(function() {10 browser.waitForElementById("resultStats", function() {11 browser.title(function(err, title) {12 assert.ok(~title.indexOf('Hello World!'));13 browser.quit();14 });15 });16 });17 });18 });19 });20 });21});22var wd = require('wd'),23 assert = require('assert');24var browser = wd.remote("localhost", 4723);25describe('Google Search', function() {26 before(function(done) {27 browser.init({28 }, done);29 });30 after(function(done) {31 browser.quit(done);32 });33 it('should work', function(done) {34 browser.elementById("lst-ib", function(err, el) {35 el.sendKeys("Hello World!", function() {36 browser.elementById("tsbb", function(err, el) {37 el.click(function() {38 browser.waitForElementById("resultStats", function() {39 browser.title(function(err, title) {40 assert.ok(~title.indexOf('Hello World!'));41 done();42 });43 });44 });45 });46 });47 });48 });49 });50});
Using AI Code Generation
1var wd = require("wd");2var assert = require("assert");3var config = require('./config.json')4var driver = wd.promiseChainRemote(config.host, config.port, config.username, config.accessKey);5driver.init(config.desiredCapabilities)6 .then(function() {7 return driver.elementById("com.android.calculator2:id/digit_1")8 })9 .then(function(el) {10 return el.click();11 })12 .then(function() {13 return driver.elementById("com.android.calculator2:id/op_add")14 })15 .then(function(el) {16 return el.click();17 })18 .then(function() {19 return driver.elementById("com.android.calculator2:id/digit_1")20 })21 .then(function(el) {22 return el.click();23 })24 .then(function() {25 return driver.elementById("com.android.calculator2:id/eq")26 })27 .then(function(el) {28 return el.click();29 })30 .then(function() {31 return driver.elementById("com.android.calculator2:id/result")32 })33 .then(function(el) {34 return el.text()35 })36 .then(function(text) {37 assert.equal(text, "2");38 })39 .fin(function() {40 return driver.resetApp();41 })42 .fin(function() {43 return driver.quit();44 })45 .done();
Using AI Code Generation
1var wd = require("wd");2var asserters = wd.asserters;3var desiredCaps = {4};5var driver = wd.promiseChainRemote("localhost", 4723);6 .init(desiredCaps)7 .elementByAccessibilityId('myButton')8 .click()9 .elementByAccessibilityId('myOtherButton')10 .click()11 .resetApp()12 .elementByAccessibilityId('myButton')13 .click()14 .elementByAccessibilityId('myOtherButton')15 .click()16 .quit();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!