How to use driver.longPressKeycode method in Appium

Best JavaScript code snippet using appium

js-wdio.js

Source:js-wdio.js Github

copy

Full Screen

1import Framework from './framework';2class JsWdIoFramework extends Framework {3 get language () {4 return 'js';5 }6 chainifyCode (code) {7 return code8 .replace(/let .+ = /g, '')9 .replace(/(\n|^)(driver|el[0-9]+)\./g, '\n.')10 .replace(/;\n/g, '\n');11 }12 wrapWithBoilerplate (code) {13 let host = JSON.stringify(this.host);14 let caps = JSON.stringify(this.caps);15 let proto = JSON.stringify(this.scheme);16 let path = JSON.stringify(this.path);17 return `// Requires the webdriverio client library18// (npm install webdriverio)19// Then paste this into a .js file and run with Node:20// node <file>.js21const wdio = require('webdriverio');22const caps = ${caps};23const driver = wdio.remote({24 protocol: ${proto},25 host: ${host},26 port: ${this.port},27 path: ${path},28 desiredCapabilities: caps29});30driver.init()31${this.indent(this.chainifyCode(code), 2)}32 .end();33`;34 }35 codeFor_findAndAssign (strategy, locator, localVar, isArray) {36 // wdio has its own way of indicating the strategy in the locator string37 switch (strategy) {38 case 'xpath': break; // xpath does not need to be updated39 case 'accessibility id': locator = `~${locator}`; break;40 case 'id': locator = `${locator}`; break;41 case 'name': locator = `name=${locator}`; break;42 case 'class name': locator = `${locator}`; break;43 case '-android uiautomator': locator = `android=${locator}`; break;44 case '-android datamatcher': locator = `android=${locator}`; break;45 case '-android viewtag': locator = `android=unsupported`; break;46 case '-ios predicate string': locator = `ios=${locator}`; break;47 case '-ios class chain': locator = `ios=${locator}`; break; // TODO: Handle IOS class chain properly. Not all libs support it. Or take it out48 default: throw new Error(`Can't handle strategy ${strategy}`);49 }50 if (isArray) {51 return `let ${localVar} = driver.elements(${JSON.stringify(locator)});`;52 } else {53 return `let ${localVar} = driver.element(${JSON.stringify(locator)});`;54 }55 }56 codeFor_click (varName, varIndex) {57 return `${this.getVarName(varName, varIndex)}.click();`;58 }59 codeFor_clear (varName, varIndex) {60 return `${this.getVarName(varName, varIndex)}.clearElement();`;61 }62 codeFor_sendKeys (varName, varIndex, text) {63 return `${this.getVarName(varName, varIndex)}.setValue(${JSON.stringify(text)});`;64 }65 codeFor_back () {66 return `driver.back();`;67 }68 codeFor_tap (varNameIgnore, varIndexIgnore, x, y) {69 return `driver.touchAction({actions: 'tap', x: ${x}, y: ${y}})`;70 }71 codeFor_swipe (varNameIgnore, varIndexIgnore, x1, y1, x2, y2) {72 return `driver.touchAction([73 {action: 'press', x: ${x1}, y: ${y1}},74 {action: 'moveTo', x: ${x2}, y: ${y2}},75 'release'76]);`;77 }78 codeFor_getCurrentActivity () {79 return `let activityName = await driver.currentActivity();`;80 }81 codeFor_getCurrentPackage () {82 return `let packageName = await driver.currentPackage();`;83 }84 codeFor_installAppOnDevice (varNameIgnore, varIndexIgnore, app) {85 return `await driver.installApp('${app}');`;86 }87 codeFor_isAppInstalledOnDevice (varNameIgnore, varIndexIgnore, app) {88 return `let isAppInstalled = await driver.isAppInstalled("${app}");`;89 }90 codeFor_launchApp () {91 return `await driver.launch();`;92 }93 codeFor_backgroundApp (varNameIgnore, varIndexIgnore, timeout) {94 return `await driver.background(${timeout});`;95 }96 codeFor_closeApp () {97 return `await driver.close_app();`;98 }99 codeFor_resetApp () {100 return `await driver.reset();`;101 }102 codeFor_removeAppFromDevice (varNameIgnore, varIndexIgnore, app) {103 return `await driver.removeApp('${app}')`;104 }105 codeFor_getAppStrings (varNameIgnore, varIndexIgnore, language, stringFile) {106 return `let appStrings = await driver.getAppStrings(${language ? `${language}, ` : ''}${stringFile ? `"${stringFile}` : ''});`;107 }108 codeFor_getClipboard () {109 return `let clipboardText = await driver.getClipboard();`;110 }111 codeFor_setClipboard (varNameIgnore, varIndexIgnore, clipboardText) {112 return `await driver.setClipboard('${clipboardText}')`;113 }114 codeFor_pressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {115 return `await driver.longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;116 }117 codeFor_longPressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {118 return `await driver.longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;119 }120 codeFor_hideDeviceKeyboard () {121 return `await driver.hideDeviceKeyboard();`;122 }123 codeFor_isKeyboardShown () {124 return `//isKeyboardShown not supported`;125 }126 codeFor_pushFileToDevice (varNameIgnore, varIndexIgnore, pathToInstallTo, fileContentString) {127 return `await driver.pushFile('${pathToInstallTo}', '${fileContentString}');`;128 }129 codeFor_pullFile (varNameIgnore, varIndexIgnore, pathToPullFrom) {130 return `let data = await driver.pullFile('${pathToPullFrom}');`;131 }132 codeFor_pullFolder (varNameIgnore, varIndexIgnore, folderToPullFrom) {133 return `let data = await driver.pullFolder('${folderToPullFrom}');`;134 }135 codeFor_toggleAirplaneMode () {136 return `await driver.toggleAirplaneMode();`;137 }138 codeFor_toggleData () {139 return `await driver.toggleData();`;140 }141 codeFor_toggleWiFi () {142 return `await driver.toggleWiFi();`;143 }144 codeFor_toggleLocationServices () {145 return `await driver.toggleLocationServices();`;146 }147 codeFor_sendSMS () {148 return `// Not supported: sendSms;`;149 }150 codeFor_gsmCall () {151 return `// Not supported: gsmCall`;152 }153 codeFor_gsmSignal () {154 return `// Not supported: gsmSignal`;155 }156 codeFor_gsmVoice () {157 return `// Not supported: gsmVoice`;158 }159 codeFor_shake () {160 return `await driver.shake();`;161 }162 codeFor_lock (varNameIgnore, varIndexIgnore, seconds) {163 return `await driver.lock(${seconds});`;164 }165 codeFor_unlock () {166 return `await driver.unlock();`;167 }168 codeFor_isLocked () {169 return `let isLocked = await driver.isLocked();`;170 }171 codeFor_rotateDevice (varNameIgnore, varIndexIgnore, x, y, radius, rotation, touchCount, duration) {172 return `driver.rotate(${x}, ${y}, ${radius}, ${rotation}, ${touchCount}, ${duration});`;173 }174 codeFor_getPerformanceData () {175 return `// Not supported: getPerformanceData`;176 }177 codeFor_getSupportedPerformanceDataTypes () {178 return `// Not supported: getSupportedPerformanceDataTypes`;179 }180 codeFor_performTouchId (varNameIgnore, varIndexIgnore, match) {181 return `await driver.touchId(${match});`;182 }183 codeFor_toggleTouchIdEnrollment (varNameIgnore, varIndexIgnore, enroll) {184 return `await driver.toggleTouchIdEnrollment(${enroll});`;185 }186 codeFor_openNotifications () {187 return `await driver.openNotifications();`;188 }189 codeFor_getDeviceTime () {190 return `let time = await driver.getDeviceTime();`;191 }192 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {193 return `await driver.fingerprint(${fingerprintId});`;194 }195 codeFor_sessionCapabilities () {196 return `let caps = await driver.session('c8db88a0-47a6-47a1-802d-164d746c06aa');`;197 }198 codeFor_setPageLoadTimeout (varNameIgnore, varIndexIgnore, ms) {199 return `await driver.timeouts('page load', ${ms})`;200 }201 codeFor_setAsyncScriptTimeout (varNameIgnore, varIndexIgnore, ms) {202 return `await driver.timeouts('script', ${ms})`;203 }204 codeFor_setImplicitWaitTimeout (varNameIgnore, varIndexIgnore, ms) {205 return `await driver.timeouts('implicit', ${ms})`;206 }207 codeFor_setCommandTimeout (varNameIgnore, varIndexIgnore, ms) {208 return `await driver.timeouts('command', ${ms})`;209 }210 codeFor_getOrientation () {211 return `let orientation = await driver.orientation();`;212 }213 codeFor_setOrientation (varNameIgnore, varIndexIgnore, orientation) {214 return `driver.orientation("${orientation}");`;215 }216 codeFor_getGeoLocation () {217 return `let location = await driver.location();`;218 }219 codeFor_setGeoLocation (varNameIgnore, varIndexIgnore, latitude, longitude, altitude) {220 return `await driver.location({latitude: ${latitude}, longitude: ${longitude}, altitude: ${altitude}});`;221 }222 codeFor_logTypes () {223 return `let logTypes = await driver.log();`;224 }225 codeFor_log (varNameIgnore, varIndexIgnore, logType) {226 return `let logs = await driver.log('${logType}');`;227 }228 codeFor_updateSettings (varNameIgnore, varIndexIgnore, settingsJson) {229 return `await driver.settings(${settingsJson});`;230 }231 codeFor_settings () {232 return `let settings = await driver.settings();`;233 }234}235JsWdIoFramework.readableName = 'JS - Webdriver.io';...

Full Screen

Full Screen

searchTest.js

Source:searchTest.js Github

copy

Full Screen

1const base = require("../../BaseClass/base");2const searchPage = require("../../Pages/Androidbrowser/searchPage");3describe('Search', async () => {4 beforeEach(async () => {5 await driver.closeApp()6 await driver.launchApp()7 });8 it('TC_01 Verify Search functionality on Main header', async () => {9 await browser.url('/')10 var searchItem="creta" 11 expect(searchPage.searchBox).toBeDisplayed()12 console.log("Search Box is displayed on Home Page")13 await (await searchPage.searchBox).click()14 console.log("Clicked on Search Box")15 await (await searchPage.searchBox).setValue(searchItem)16 console.log("Required Vehicle name entered in the search Box")17 console.log("Searching for "+searchItem)18 await driver.longPressKeyCode(66, undefined, undefined)19 expect(await searchPage.cretaResult).toBeDisplayed()20 expect(await searchPage.cretaResult).toHaveTextContaining(searchItem)21 console.log("Using Seacth box User is able to search required items")22 console.log("First element displayed as :"+await(await searchPage.cretaResult).getText())23 });24 it('TC_02 Verify Search functionality on Vista Link', async () => {25 await browser.url('/')26 await base.swipeUp()27 console.log("Scrolling to the Vista Link")28 expect(await searchPage.bikeVistaLink).toBeDisplayed()29 console.log("Vista link of Bikes is Displayed")30 await(await searchPage.bikeVistaLink).waitForDisplayed({timeout:30000})31 await (await searchPage.bikeVistaLink).click()32 console.log("Clicked On Vista Link of Super Cars")33 await browser.pause(3000)34 expect(await searchPage.vistaLinkResult).toBeDisplayed()35 console.log("User able to navigate to required page by clicking related Vista Links")36 });37 it('TC_03 Verify the Popular Search Functionality from the Home Page', async () => { 38 await browser.url('/')39 expect(await searchPage.searchBoxHeader).toBeDisplayed()40 console.log("Search Box heading is displayed");41 expect(searchPage.searchBox).toBeDisplayed()42 console.log("Search Box is Displayed")43 await (await searchPage.searchBox).click()44 console.log("Clicked On Search Box")45 await browser.pause(10000)46 expect(await searchPage.trendingSearch).toBeDisplayed()47 console.log("Trending Searches is Displayed")48 expect(searchPage.mainSearchResult).toBeDisplayed()49 console.log("List of Vehicles Displayed under the Trending Searches")50 });51 it('TC_04 Verify the Auto-select Functionality of search on Home Page', async () => {52 await browser.url('/')53 var searchItem="Thar" 54 expect(searchPage.searchBox).toBeDisplayed()55 console.log("Search Box is displayed")56 await (await searchPage.searchBox).click()57 console.log("CLicked on Search Box")58 await (await searchPage.searchBox).setValue(searchItem)59 console.log("Searching for "+searchItem)60 await driver.longPressKeyCode(66, undefined, undefined)61 expect(await searchPage.tharResult).toBeDisplayed()62 console.log("Result get displayed")63 expect(await searchPage.tharResult).toHaveTextContaining(searchItem)64 console.log("Using Seacth box User is able to search required items")65 console.log("First element displayed as : "+await(await searchPage.tharResult).getText())66 });67 68 it('TC_05 Verify the Sorting Functinality of Search', async () => {69 await browser.url('/')70 var searchItem="Activa"71 expect(searchPage.searchBox).toBeDisplayed()72 await (await searchPage.searchBox).click()73 await (await searchPage.searchBox).setValue(searchItem)74 console.log("Searching for "+searchItem)75 await driver.longPressKeyCode(66, undefined, undefined)76 expect(await searchPage.headingVehicle).toBeDisplayed()77 expect(await searchPage.headingVehicle).toHaveTextContaining(searchItem)78 console.log("Using Seacth box User is able to search required items")79 expect(await searchPage.sort).toBeDisplayed()80 console.log("Sort opton is availbale on Page")81 //await(await searchPage.Sort).waitForClickable({ timeout: 3000 })82 await(await searchPage.sort).click()83 console.log("Clicked On Sort Option")84 expect(await searchPage.sortingLable).toBeDisplayed()85 console.log("Sorting Lable is availbale on Page")86 console.log("Sorting Options displayed as ->:")87 console.log(await (await searchPage.nearMe).getText())88 console.log(await (await searchPage.priceLowToHigh).getText())89 console.log(await (await searchPage.pricehighToLow).getText())90 console.log(await (await searchPage.kmsdriven).getText())91 console.log(await (await searchPage.Year).getText())92 console.log(await (await searchPage.fullCircle).getText())93 console.log(await (await searchPage.mostViewed).getText())94 console.log(await (await searchPage.mostRecent).getText())95 console.log("Expected Sorting option is availbale")96 await(await searchPage.Year).click()97 console.log("Clicked on Year (Newest to Oldest)")98 expect(await searchPage.sortResultNew).toBeDisplayed()99 console.log(await (await searchPage.sortResultNew).getText())100 await base.swipeUp()101 expect(await searchPage.sortResultNew).toBeDisplayed()102 console.log(await (await searchPage.sortResultNew).getText())103 console.log("Activa list is displayed according to applied Filter")104 });105 106 it('TC 06 Verify the Filter Functionality', async () => {107 await browser.url('/')108 var searchItem="Honda City"109 expect(searchPage.searchBox).toBeDisplayed()110 await (await searchPage.searchBox).click()111 await (await searchPage.searchBox).setValue(searchItem)112 console.log("Searching for "+searchItem)113 await driver.longPressKeyCode(66, undefined, undefined)114 expect(await searchPage.hondaResult).toBeDisplayed()115 expect(await searchPage.hondaResult).toHaveTextContaining(searchItem)116 console.log("Using Seacth box User is able to search required items")117 expect(await searchPage.filter).toBeDisplayed()118 console.log("Filter opton is availbale on Page")119 //await(await searchPage.filter).waitForClickable({ timeout: 3000 })120 await(await searchPage.filter).click()121 console.log("Clicked On Filter Option")122 console.log("Available Filter Options are-->")123 expect(await searchPage.locationFilter).toBeDisplayed()124 console.log(await(await searchPage.locationFilter).getText())125 //expect(await searchPage.PriceFilter).toBeDisplayed()126 //console.log(await(await searchPage.PriceFilter).getText())127 expect(await searchPage.modelFilter).toBeDisplayed()128 console.log(await(await searchPage.modelFilter).getText())129 expect(await searchPage.yearFilter).toBeDisplayed()130 console.log(await(await searchPage.yearFilter).getText())131 expect(await searchPage.certificationFilter).toBeDisplayed()132 console.log(await(await searchPage.certificationFilter).getText())133 expect(await searchPage.makeFilter).toBeDisplayed()134 console.log(await(await searchPage.makeFilter).getText())135 expect(await searchPage.BodyTypeFilter).toBeDisplayed()136 console.log(await(await searchPage.BodyTypeFilter).getText())137 expect(await searchPage.colorFilter).toBeDisplayed()138 console.log(await(await searchPage.colorFilter).getText())139 expect(await searchPage.warrantyFilter).toBeDisplayed()140 console.log(await(await searchPage.warrantyFilter).getText())141 expect(await searchPage.HistoryFilter).toBeDisplayed()142 console.log(await(await searchPage.HistoryFilter).getText())143 await(await searchPage.makeFilter).click()144 console.log("Clicked on Make filter")145 await(await searchPage.applyFilter).click()146 console.log("Clicked on Apply Filter Button")147 expect(await searchPage.filterResult).toBeDisplayed()148 console.log(await(await searchPage.filterResult).getText())149 console.log("Expected result shown using applied Filter")150 });151 it('TC_08 Verify the functionality of recent Search', async () => {152 await browser.url('/')153 expect(await searchPage.searchBoxHeader).toBeDisplayed()154 console.log("Search Box heading is displayed");155 expect(searchPage.searchBox).toBeDisplayed()156 console.log("Search Box is Displayed")157 await (await searchPage.searchBox).click()158 console.log("Clicked On Search Box")159 await(await searchPage.recentSearch).waitForDisplayed({timeout:10000})160 console.log("Recent Searches is Displayed")161 await expect(searchPage.mainSearchResult).toBeDisplayed()162 console.log("List of Vehicles Displayed under the Recent Searches")163 });...

Full Screen

Full Screen

js-wd.js

Source:js-wd.js Github

copy

Full Screen

1import Framework from './framework';2class JsWdFramework extends Framework {3 get language () {4 return 'js';5 }6 wrapWithBoilerplate (code) {7 let caps = JSON.stringify(this.caps);8 return `// Requires the admc/wd client library9// (npm install wd)10// Then paste this into a .js file and run with Node 7.6+11const wd = require('wd');12const driver = wd.promiseChainRemote("${this.serverUrl}");13const caps = ${caps};14async function main () {15 await driver.init(caps);16${this.indent(code, 2)}17 await driver.quit();18}19main().catch(console.log);20`;21 }22 codeFor_findAndAssign (strategy, locator, localVar, isArray) {23 let suffixMap = {24 xpath: 'XPath',25 'accessibility id': 'AccessibilityId',26 'id': 'Id',27 'name': 'Name',28 'class name': 'ClassName',29 '-android uiautomator': 'AndroidUIAutomator',30 '-android datamatcher': 'AndroidDataMatcher',31 '-android viewtag': 'unsupported',32 '-ios predicate string': 'IosUIAutomation',33 '-ios class chain': 'IosClassChain',34 };35 if (!suffixMap[strategy]) {36 throw new Error(`Strategy ${strategy} can't be code-gened`);37 }38 if (isArray) {39 return `let ${localVar} = await driver.elementsBy${suffixMap[strategy]}(${JSON.stringify(locator)});`;40 } else {41 return `let ${localVar} = await driver.elementBy${suffixMap[strategy]}(${JSON.stringify(locator)});`;42 }43 }44 codeFor_click (varName, varIndex) {45 return `await ${this.getVarName(varName, varIndex)}.click();`;46 }47 codeFor_clear (varName, varIndex) {48 return `await ${this.getVarName(varName, varIndex)}.clear();`;49 }50 codeFor_sendKeys (varName, varIndex, text) {51 return `await ${this.getVarName(varName, varIndex)}.sendKeys(${JSON.stringify(text)});`;52 }53 codeFor_back () {54 return `await driver.back();`;55 }56 codeFor_tap (varNameIgnore, varIndexIgnore, x, y) {57 return `await (new wd.TouchAction(driver))58 .tap({x: ${x}, y: ${y}})59 .perform()60 `;61 }62 codeFor_swipe (varNameIgnore, varIndexIgnore, x1, y1, x2, y2) {63 return `await (new wd.TouchAction(driver))64 .press({x: ${x1}, y: ${y1}})65 .moveTo({x: ${x2}, y: ${y2}})66 .release()67 .perform()68 `;69 }70 codeFor_getCurrentActivity () {71 return `let activityName = await driver.getCurrentActivity()`;72 }73 codeFor_getCurrentPackage () {74 return `let packageName = await driver.getCurrentPackage()`;75 }76 codeFor_installAppOnDevice (varNameIgnore, varIndexIgnore, app) {77 return `let isAppInstalled = await driver.installAppOnDevice('${app}');`;78 }79 codeFor_isAppInstalledOnDevice (varNameIgnore, varIndexIgnore, app) {80 return `driver.isAppInstalled("${app}");`;81 }82 codeFor_launchApp () {83 return `await driver.launchApp();`;84 }85 codeFor_backgroundApp (varNameIgnore, varIndexIgnore, timeout) {86 return `await driver.backgroundApp(${timeout});`;87 }88 codeFor_closeApp () {89 return `await driver.closeApp();`;90 }91 codeFor_resetApp () {92 return `await driver.resetApp();`;93 }94 codeFor_removeAppFromDevice (varNameIgnore, varIndexIgnore, app) {95 return `await driver.removeAppFromDevice('${app}');`;96 }97 codeFor_getAppStrings (varNameIgnore, varIndexIgnore, language, stringFile) {98 return `let appStrings = await driver.getAppStrings(${language ? `${language}, ` : ''}${stringFile ? `"${stringFile}` : ''});`;99 }100 codeFor_getClipboard () {101 return `let clipboardText = await driver.getClipboard();`;102 }103 codeFor_setClipboard (varNameIgnore, varIndexIgnore, clipboardText) {104 return `await driver.setClipboard('${clipboardText}')`;105 }106 codeFor_pressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {107 return `await driver.longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;108 }109 codeFor_longPressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {110 return `await driver.longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;111 }112 codeFor_hideDeviceKeyboard () {113 return `await driver.hideDeviceKeyboard();`;114 }115 codeFor_isKeyboardShown () {116 return `await driver.isKeyboardShown();`;117 }118 codeFor_pushFileToDevice (varNameIgnore, varIndexIgnore, pathToInstallTo, fileContentString) {119 return `await driver.pushFileToDevice('${pathToInstallTo}', '${fileContentString}');`;120 }121 codeFor_pullFile (varNameIgnore, varIndexIgnore, pathToPullFrom) {122 return `let fileBase64 = await driver.pullFile('${pathToPullFrom}');`;123 }124 codeFor_pullFolder (varNameIgnore, varIndexIgnore, folderToPullFrom) {125 return `let fileBase64 = await driver.pullFolder('${folderToPullFrom}');`;126 }127 codeFor_toggleAirplaneMode () {128 return `await driver.toggleAirplaneMode();`;129 }130 codeFor_toggleData () {131 return `await driver.toggleData();`;132 }133 codeFor_toggleWiFi () {134 return `await driver.toggleWiFi();`;135 }136 codeFor_toggleLocationServices () {137 return `await driver.toggleLocationServices();`;138 }139 codeFor_sendSMS (varNameIgnore, varIndexIgnore, phoneNumber, text) {140 return `await driver.sendSms('${phoneNumber}', '${text}');`;141 }142 codeFor_gsmCall (varNameIgnore, varIndexIgnore, phoneNumber, action) {143 return `await driver.gsmCall('${phoneNumber}', '${action}');`;144 }145 codeFor_gsmSignal (varNameIgnore, varIndexIgnore, signalStrength) {146 return `await driver.gsmSignal(${signalStrength});`;147 }148 codeFor_gsmVoice (varNameIgnore, varIndexIgnore, state) {149 return `await driver.gsmVoice('${state}');`;150 }151 codeFor_shake () {152 return `await driver.shake();`;153 }154 codeFor_lock (varNameIgnore, varIndexIgnore, seconds) {155 return `await driver.lock(${seconds})`;156 }157 codeFor_unlock () {158 return `await driver.unlock()`;159 }160 codeFor_isLocked () {161 return `let isLocked = await driver.isLocked();`;162 }163 codeFor_rotateDevice (varNameIgnore, varIndexIgnore, x, y, radius, rotation, touchCount, duration) {164 return `driver.rotateDevice({x: ${x}, y: ${y}, duration: ${duration}, radius: ${radius}, rotation: ${rotation}, touchCount: ${touchCount}});`;165 }166 codeFor_getPerformanceData (varNameIgnore, varIndexIgnore, packageName, dataType, dataReadTimeout) {167 return `let performanceData = await driver.getPerformanceData('${packageName}', '${dataType}', ${dataReadTimeout});`;168 }169 codeFor_getSupportedPerformanceDataTypes () {170 return `let supportedPerformanceDataTypes = await driver.getSupportedPerformanceDataTypes();`;171 }172 codeFor_performTouchId (varNameIgnore, varIndexIgnore, match) {173 return `await driver.touchId(${match});`;174 }175 codeFor_toggleTouchIdEnrollment (varNameIgnore, varIndexIgnore, enroll) {176 return `await driver.toggleTouchIdEnrollment(${enroll});`;177 }178 codeFor_openNotifications () {179 return `await driver.openNotifications();`;180 }181 codeFor_getDeviceTime () {182 return `let time = await driver.getDeviceTime();`;183 }184 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {185 return `await driver.fingerprint(${fingerprintId});`;186 }187 codeFor_sessionCapabilities () {188 return `let caps = await driver.sessionCapabilities();`;189 }190 codeFor_setPageLoadTimeout (varNameIgnore, varIndexIgnore, ms) {191 return `await setPageLoadTimeout(${ms})`;192 }193 codeFor_setAsyncScriptTimeout (varNameIgnore, varIndexIgnore, ms) {194 return `await setAsyncScriptTimeout(${ms})`;195 }196 codeFor_setImplicitWaitTimeout (varNameIgnore, varIndexIgnore, ms) {197 return `await setImplicitWaitTimeout(${ms})`;198 }199 codeFor_getOrientation () {200 return `let orientation = await driver.getOrientation();`;201 }202 codeFor_setOrientation (varNameIgnore, varIndexIgnore, orientation) {203 return `await driver.setOrientation('${orientation}');`;204 }205 codeFor_getGeoLocation () {206 return `let location = await driver.getGeoLocation();`;207 }208 codeFor_setGeoLocation (varNameIgnore, varIndexIgnore, latitude, longitude, altitude) {209 return `await driver.setGeoLocation(${latitude}, ${longitude}, ${altitude});`;210 }211 codeFor_logTypes () {212 return `let logTypes = await driver.logTypes();`;213 }214 codeFor_log (varNameIgnore, varIndexIgnore, logType) {215 return `let logs = await driver.log('${logType}');`;216 }217 codeFor_updateSettings (varNameIgnore, varIndexIgnore, settingsJson) {218 return `await driver.updateSettings(${settingsJson});`;219 }220 codeFor_settings () {221 return `let settings = await driver.settings();`;222 }223}224JsWdFramework.readableName = 'JS - WD (Promise)';...

Full Screen

Full Screen

js-oxygen.js

Source:js-oxygen.js Github

copy

Full Screen

1import Framework from './framework';2class JsOxygenFramework extends Framework {3 get language () {4 return 'js';5 }6 wrapWithBoilerplate (code) {7 let caps = JSON.stringify(this.caps);8 let url = JSON.stringify(`${this.scheme}://${this.host}:${this.port}${this.path}`);9 return `// Requires the Oxygen HQ client library10// (npm install oxygen-cli -g)11// Then paste this into a .js file and run with:12// oxygen <file>.js13mob.init(${caps}, ${url});14${code}15`;16 }17 codeFor_findAndAssign (strategy, locator, localVar, isArray) {18 // wdio has its own way of indicating the strategy in the locator string19 switch (strategy) {20 case 'xpath': break; // xpath does not need to be updated21 case 'accessibility id': locator = `~${locator}`; break;22 case 'id': locator = `id=${locator}`; break;23 case 'name': locator = `name=${locator}`; break;24 case 'class name': locator = `css=${locator}`; break;25 case '-android uiautomator': locator = `android=${locator}`; break;26 case '-android datamatcher': locator = `android=${locator}`; break;27 case '-ios predicate string': locator = `ios=${locator}`; break;28 case '-ios class chain': locator = `ios=${locator}`; break; // TODO: Handle IOS class chain properly. Not all libs support it. Or take it out29 default: throw new Error(`Can't handle strategy ${strategy}`);30 }31 if (isArray) {32 return `let ${localVar} = mob.findElements(${JSON.stringify(locator)});`;33 } else {34 return `let ${localVar} = mob.findElement(${JSON.stringify(locator)});`;35 }36 }37 codeFor_click (varName, varIndex) {38 return `mob.click(${this.getVarName(varName, varIndex)});`;39 }40 codeFor_clear (varName, varIndex) {41 return `mob.clear(${this.getVarName(varName, varIndex)});`;42 }43 codeFor_sendKeys (varName, varIndex, text) {44 return `mob.type(${this.getVarName(varName, varIndex)}, ${JSON.stringify(text)});`;45 }46 codeFor_back () {47 return `mob.back();`;48 }49 codeFor_tap (varNameIgnore, varIndexIgnore, x, y) {50 return `mob.tap(${x}, ${y});`;51 }52 codeFor_swipe (varNameIgnore, varIndexIgnore, x1, y1, x2, y2) {53 return `mob.swipeScreen(${x1}, ${y1}, ${x2}, ${y2});`;54 }55 codeFor_getCurrentActivity () {56 return `let activityName = mob.getCurrentActivity();`;57 }58 codeFor_getCurrentPackage () {59 return `let packageName = mob.getCurrentPackage();`;60 }61 codeFor_installAppOnDevice (varNameIgnore, varIndexIgnore, app) {62 return `mob.installApp('${app}');`;63 }64 codeFor_isAppInstalledOnDevice (varNameIgnore, varIndexIgnore, app) {65 return `let isAppInstalled = mob.isAppInstalled("${app}");`;66 }67 codeFor_launchApp () {68 return `mob.launchApp();`;69 }70 codeFor_backgroundApp (varNameIgnore, varIndexIgnore, timeout) {71 return `mob.driver().background(${timeout});`;72 }73 codeFor_closeApp () {74 return `mob.closeApp();`;75 }76 codeFor_resetApp () {77 return `mob.resetApp();`;78 }79 codeFor_removeAppFromDevice (varNameIgnore, varIndexIgnore, app) {80 return `mob.removeApp('${app}')`;81 }82 codeFor_getAppStrings (varNameIgnore, varIndexIgnore, language, stringFile) {83 return `let appStrings = mob.driver().getAppStrings(${language ? `${language}, ` : ''}${stringFile ? `"${stringFile}` : ''});`;84 }85 codeFor_getClipboard () {86 return `let clipboardText = mob.driver().getClipboard();`;87 }88 codeFor_setClipboard (varNameIgnore, varIndexIgnore, clipboardText) {89 return `mob.driver().setClipboard('${clipboardText}')`;90 }91 codeFor_pressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {92 return `mob.driver().longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;93 }94 codeFor_longPressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {95 return `mob.driver().longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;96 }97 codeFor_hideDeviceKeyboard () {98 return `mob.driver().hideKeyboard();`;99 }100 codeFor_isKeyboardShown () {101 return `//isKeyboardShown not supported`;102 }103 codeFor_pushFileToDevice (varNameIgnore, varIndexIgnore, pathToInstallTo, fileContentString) {104 return `mob.driver().pushFile('${pathToInstallTo}', '${fileContentString}');`;105 }106 codeFor_pullFile (varNameIgnore, varIndexIgnore, pathToPullFrom) {107 return `let data = mob.driver().pullFile('${pathToPullFrom}');`;108 }109 codeFor_pullFolder (varNameIgnore, varIndexIgnore, folderToPullFrom) {110 return `let data = mob.driver().pullFolder('${folderToPullFrom}');`;111 }112 codeFor_toggleAirplaneMode () {113 return `mob.driver().toggleAirplaneMode();`;114 }115 codeFor_toggleData () {116 return `mob.driver().toggleData();`;117 }118 codeFor_toggleWiFi () {119 return `mob.driver().toggleWiFi();`;120 }121 codeFor_toggleLocationServices () {122 return `mob.driver().toggleLocationServices();`;123 }124 codeFor_sendSMS () {125 return `// Not supported: sendSms;`;126 }127 codeFor_gsmCall () {128 return `// Not supported: gsmCall`;129 }130 codeFor_gsmSignal () {131 return `// Not supported: gsmSignal`;132 }133 codeFor_gsmVoice () {134 return `// Not supported: gsmVoice`;135 }136 codeFor_shake () {137 return `mob.shake();`;138 }139 codeFor_lock (varNameIgnore, varIndexIgnore, seconds) {140 return `mob.driver().lock(${seconds});`;141 }142 codeFor_unlock () {143 return `mob.driver().unlock();`;144 }145 codeFor_isLocked () {146 return `let isLocked = mob.driver().isLocked();`;147 }148 codeFor_rotateDevice (varNameIgnore, varIndexIgnore, x, y, radius, rotation, touchCount, duration) {149 return `mob.driver().rotateDevice(${x}, ${y}, ${radius}, ${rotation}, ${touchCount}, ${duration});`;150 }151 codeFor_getPerformanceData () {152 return `// Not supported: getPerformanceData`;153 }154 codeFor_getSupportedPerformanceDataTypes () {155 return `// Not supported: getSupportedPerformanceDataTypes`;156 }157 codeFor_performTouchId (varNameIgnore, varIndexIgnore, match) {158 return `mob.driver().touchId(${match});`;159 }160 codeFor_toggleTouchIdEnrollment (varNameIgnore, varIndexIgnore, enroll) {161 return `mob.driver().toggleEnrollTouchId(${enroll});`;162 }163 codeFor_openNotifications () {164 return `mob.driver().openNotifications();`;165 }166 codeFor_getDeviceTime () {167 return `let time = mob.getDeviceTime();`;168 }169 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {170 return `mob.driver().fingerPrint(${fingerprintId});`;171 }172 codeFor_sessionCapabilities () {173 return `let caps = mob.driver().capabilities;`;174 }175 codeFor_setPageLoadTimeout (varNameIgnore, varIndexIgnore, ms) {176 return `mob.driver().setTimeout({'pageLoad': ${ms}});`;177 }178 codeFor_setAsyncScriptTimeout (varNameIgnore, varIndexIgnore, ms) {179 return `mob.driver().setTimeout({'script': ${ms}});`;180 }181 codeFor_setImplicitWaitTimeout (varNameIgnore, varIndexIgnore, ms) {182 return `mob.driver().setTimeout({'implicit': ${ms}});`;183 }184 codeFor_setCommandTimeout () {185 return `// Not supported: setCommandTimeout`;186 }187 codeFor_getOrientation () {188 return `let orientation = mob.driver().getOrientation();`;189 }190 codeFor_setOrientation (varNameIgnore, varIndexIgnore, orientation) {191 return `mob.driver().setOrientation("${orientation}");`;192 }193 codeFor_getGeoLocation () {194 return `let location = mob.driver().getGeoLocation();`;195 }196 codeFor_setGeoLocation (varNameIgnore, varIndexIgnore, latitude, longitude, altitude) {197 return `mob.driver().setGeoLocation({latitude: ${latitude}, longitude: ${longitude}, altitude: ${altitude}});`;198 }199 codeFor_logTypes () {200 return `let logTypes = mob.driver().getLogTypes();`;201 }202 codeFor_log (varNameIgnore, varIndexIgnore, logType) {203 return `let logs = mob.driver().getLogs('${logType}');`;204 }205 codeFor_updateSettings (varNameIgnore, varIndexIgnore, settingsJson) {206 return `mob.driver().updateSettings(${settingsJson});`;207 }208 codeFor_settings () {209 return `let settings = mob.driver().getSettings();`;210 }211}212JsOxygenFramework.readableName = 'JS - Oxygen HQ';...

Full Screen

Full Screen

actions-e2e-specs.js

Source:actions-e2e-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import AndroidDriver from '../../..';4import _ from 'lodash';5import DEFAULT_CAPS from '../desired';6chai.should();7chai.use(chaiAsPromised);8const PNG_MAGIC = '89504e47';9const PNG_MAGIC_LENGTH = 4;10let driver;11let caps = _.defaults({12 appPackage: 'io.appium.android.apis',13 appActivity: '.view.TextFields'14}, DEFAULT_CAPS);15describe('actions', function () {16 before(async function () {17 driver = new AndroidDriver();18 await driver.createSession(caps);19 });20 after(async function () {21 await driver.deleteSession();22 });23 describe('replaceValue', function () {24 it('should replace existing value in a text field', async function () {25 this.retries(4);26 let el = _.last(await driver.findElements('class name', 'android.widget.EditText'));27 el.should.exist;28 await driver.setValue('original value', el.ELEMENT);29 await driver.getText(el.ELEMENT).should.eventually.equal('original value');30 await driver.replaceValue('replaced value', el.ELEMENT);31 await driver.getText(el.ELEMENT).should.eventually.equal('replaced value');32 });33 });34 describe('key codes', function () {35 beforeEach(async function () {36 await driver.startActivity(caps.appPackage, caps.appActivity);37 });38 it('should press key code 3 without metastate', async function () {39 await driver.pressKeyCode(3).should.not.be.rejected;40 });41 it('should press key code 3 with metastate', async function () {42 await driver.pressKeyCode(3, 193).should.not.be.rejected;43 });44 it('should long press key code 3 without metastate', async function () {45 await driver.longPressKeyCode(3).should.not.be.rejected;46 });47 it('should long press key code 3 with metastate', async function () {48 await driver.longPressKeyCode(3, 193).should.not.be.rejected;49 });50 });51 describe('getScreenshot', function () {52 it('should return valid base64-encoded screenshot', async function () {53 const base64screenshot = await driver.getScreenshot();54 const imageMagic = Buffer.from(base64screenshot, 'base64').toString('hex', 0, PNG_MAGIC_LENGTH);55 imageMagic.should.be.equal(PNG_MAGIC);56 });57 });...

Full Screen

Full Screen

ViewMovieDetail.js

Source:ViewMovieDetail.js Github

copy

Full Screen

1var appiumUtils = require("../../appium_helpers");2var wd = require("selenium-webdriver");3const By = wd.By;4const until = wd.until;5const { Before, Given, When, Then, After } = require('cucumber')6var assert = require('assert');7var driver;8Before({ timeout: 6000 * 10000 }, async function () {9 driver = await appiumUtils.appLaunch();10 console.log('app ready' + driver);11 let searchBar = await driver.findElement(By.id("com.insiderser.android.movies:id/search_bar_text"));12})13Given('User on the List of Movies named {string}', async function (movieName) {14 console.log("driver is ", driver)15 let searchBar = await driver.findElement(By.id("com.insiderser.android.movies:id/search_bar_text"));16 await searchBar.click();17 await searchBar.sendKeys(movieName);18 await driver.longPressKeyCode(66, undefined, undefined);19});20When('Clicked on text with {string}', function (string) {21 // Write code here that turns the phrase above into concrete actions22 return 'pending';23});24Then('I should see Details with year {string}', function (movieName) {25 // Write code here that turns the phrase above into concrete actions26 return 'pending';...

Full Screen

Full Screen

longPressKeyCode.js

Source:longPressKeyCode.js Github

copy

Full Screen

1/*2 * Copyright (C) 2015-present CloudBeat Limited3 *4 * This program is free software: you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 3 of the License, or7 * (at your option) any later version.8 */9/**10 * @summary Press and hold a particular key code on the device.11 * @function longPressKeyCode12 * @param {Number} keycode - Key code pressed on the device.13 * @for android, web14 * @example <caption>[javascript] Usage example</caption>15 * https://developer.android.com/reference/android/view/KeyEvent.html - list of key codes16 * mob.init();//Starts a mobile session17 * mob.open('https://keycode.info/');18 * mob.longPressKeyCode(32);// 32 - d key19 */20module.exports = async function(keycode) {21 this.helpers.assertArgumentNumberNonNegative(keycode, 'keycode');22 await this.helpers.assertContext(this.helpers.contextList.android, this.helpers.contextList.web);23 await this.driver.longPressKeyCode(keycode);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.manage().timeouts().implicitlyWait(10000);6driver.findElement(webdriver.By.linkText('Selenium - Web Browser Automation')).click();7driver.manage().timeouts().implicitlyWait(10000);8driver.longPressKeycode(82, webdriver.Key.SHIFT);9driver.manage().timeouts().implicitlyWait(10000);10driver.quit();11driver.longPressKeycode(82, webdriver.Key.SHIFT);12driver.longPressKeycode(82, webdriver.Key.SHIFT);13driver.longPressKeycode(82, webdriver.Key.SHIFT);14driver.longPressKeycode(82, webdriver.Key.SHIFT);15driver.longPressKeycode(82, webdriver.Key.SHIFT);

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2}).build();3driver.findElement(webdriver.By.name('q')).sendKeys('appium');4driver.findElement(webdriver.By.name('btnG')).click();5driver.sleep(5000);6driver.longPressKeycode(82);7driver.sleep(5000);8driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.longPressKeycode(82, 1);2driver.longPressKeycode(82, 2);3driver.longPressKeycode(82, 3);4driver.longPressKeycode(82, 1);5driver.longPressKeycode(82, 2);6driver.longPressKeycode(82, 3);7driver.longPressKeycode(82, 1);8driver.longPressKeycode(82, 2);9driver.longPressKeycode(82, 3);10driver.longPressKeycode(82, 1);11driver.longPressKeycode(82, 2);12driver.longPressKeycode(82, 3);13driver.longPressKeycode(82, 1);14driver.longPressKeycode(82, 2);15driver.longPressKeycode(82, 3);16driver.longPressKeycode(82, 1);17driver.longPressKeycode(82, 2);18driver.longPressKeycode(82, 3);19driver.longPressKeycode(82, 1);20driver.longPressKeycode(82, 2);21driver.longPressKeycode(82, 3);22driver.longPressKeycode(82, 1);23driver.longPressKeycode(82, 2);24driver.longPressKeycode(82, 3);25driver.longPressKeycode(82, 1);26driver.longPressKeycode(82, 2);27driver.longPressKeycode(82, 3);28driver.longPressKeycode(82, 1);29driver.longPressKeycode(82, 2);30driver.longPressKeycode(82, 3);31driver.longPressKeycode(82, 1);32driver.longPressKeycode(82, 2);33driver.longPressKeycode(82

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.longPressKeycode("KEYCODE_VOLUME_UP", 1);2driver.pressKeyCode(66);3driver.pressKeyCode(66, 1);4driver.pressKeyCode(66, 1, 1);5driver.pressKeyCode(66, 1, 1, 1);6driver.pressKeyCode(66, 1, 1, 1, 1);7driver.pressKeyCode(66, 1, 1, 1, 1, 1);8driver.pressKeyCode(66, 1, 1, 1, 1, 1, 1);9driver.pressKeyCode(66, 1, 1, 1, 1, 1, 1, 1);10driver.pressKeyCode(66, 1, 1, 1, 1, 1, 1, 1, 1);11driver.pressKeyCode(66, 1, 1, 1, 1, 1, 1, 1, 1, 1);12driver.pressKeyCode(66, 1, 1, 1, 1, 1, 1, 1, 1,

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful