Best JavaScript code snippet using appium-android-driver
PumpController.js
Source:PumpController.js
1'use strict';2/* Controllers */3// Pump controller4app5 .controller('PumpController', ['$scope', '$http', '$state', '$localStorage', 'CRUD', 'toaster', '$filter', '$location', '$rootScope', '$modal', function ($scope, $http, $state, $localStorage, CRUD, toaster, $filter, $location, $rootScope, $modal) {6 var listurl = 'pumps';7 var guidurl = 'pumps/guid';8 var createurl = 'pumps/create';9 var viewurl = 'pumps/'; // user id required10 var saveurl = 'pumps';11 var updateurl = 'pumps/update/'; // user id required12 var deleteurl = 'pumps/delete/'; // user id required13 $scope.isUpdateForm=false;14 $scope.rowCollection = [];15 $scope.selectedSite = '';16 $scope.sites = [];17 $scope.displayCollection = [];18 if($state.is('app.pumps_edit')) {19 if($state.params.id != ''){20 $rootScope.loading = true;21 CRUD.findById(viewurl,$state.params.id).then(function(response){22 $scope.isUpdateForm=true;23 var data=response.data.data;24 $scope.pumpData = {25 name: data.name,26 ip: data.ip,27 code: data.code,28 guid: data.guid,29 attendent_tag: (data.attendent_tag != null) ? data.attendent_tag.toString() : '',30 vehicle_tag: (data.vehicle_tag != null) ? data.vehicle_tag.toString() : '',31 odo_meter: data.odo_meter,32 driver_fingerprint: data.driver_fingerprint,33 order_number: data.order_number,34 pin: data.pin,35 location: (data.location != null) ? data.location.toString() : "",36 job_tag: (data.job_tag != null) ? data.job_tag.toString() : '',37 site_id: data.site_id38 };39 $rootScope.loading = false;40 },function(error){41 $rootScope.loading = false;42 //toaster.pop('error','',error.data.message);43 });44 }45 $scope.pumpData={};46 }47 $scope.getAllPumps = function () {48 $rootScope.loading = true;49 CRUD.getAll(listurl).then(success).catch(failed);50 function success(res) {51 $scope.sites = res.data;52 if ($scope.sites.data && $scope.sites.data.length) {53 if ($localStorage.site_id) {54 angular.forEach($scope.sites.data, function (value, key) {55 if (value.id == $localStorage.site_id) {56 $scope.selectedSite = value;57 }58 });59 }60 else {61 $rootScope.siteData = $scope.sites.data[0];62 $scope.selectedSite = $scope.sites.data[0];63 $localStorage.site_id = $scope.sites.data[0].id;64 }65 $scope.rowCollection = $scope.selectedSite.pumps;66 $scope.displayCollection = $scope.selectedSite.pumps;67 }68 $rootScope.loading = false;69 }70 function failed(error) {71 $rootScope.loading = false;72 //toaster.pop('error','',error.data.message);73 }74 };75 $scope.changeSite = function () {76 $rootScope.siteData = $scope.selectedSite;77 $localStorage.site_id = $scope.selectedSite.id;78 $scope.rowCollection = $scope.selectedSite.pumps;79 $scope.displayCollection = $scope.selectedSite.pumps;80 }81 $scope.createPump = function (site_id) {82 $rootScope.site_id = site_id;83 $state.go('app.pumps_new');84 }85 $scope.initForm = function(){86 $scope.pumpData = {87 name: '',88 ip: '',89 code: '',90 guid: '',91 attendent_tag: '',92 vehicle_tag: '',93 odo_meter: '',94 driver_fingerprint: '',95 order_number: '',96 pin: '',97 job_tag: ''98 };99 }100 $scope.generateGuid = function () {101 $rootScope.loading = true;102 CRUD.getAll(guidurl).then(success).catch(failed);103 function success(res) {104 $scope.pumpData.guid = res.data.guid;105 $rootScope.loading = false;106 }107 function failed(error) {108 $rootScope.loading = false;109 toaster.pop('error','',error.data.message);110 }111 }112 $scope.save = function (isValid) {113 if(isValid)114 {115 var data=$scope.pumpData;116 var filterData = {117 name: data.name,118 ip: data.ip,119 code: data.code,120 guid: data.guid,121 attendent_tag: data.attendent_tag,122 vehicle_tag: data.vehicle_tag,123 odo_meter: data.odo_meter,124 driver_fingerprint: data.driver_fingerprint,125 order_number: data.order_number,126 pin: data.pin,127 location: data.location,128 job_tag: data.job_tag,129 };130 if($state.is('app.pumps_edit'))131 {132 filterData.site_id = data.site_id;133 $rootScope.loading = true;134 CRUD.update(updateurl, $state.params.id, $.param(filterData)).then(function (response) {135 toaster.pop('success', "Pump", response.data.message);136 $rootScope.loading = false;137 $state.go('app.pumps');138 }, function (res) {139 if(res.status == 400)140 {141 angular.forEach(res.data.validation_errors, function (value, key) {142 toaster.pop('error', '', value[0]);143 });144 }145 $rootScope.loading = false;146 });147 }148 else {149 if ($rootScope.site_id) {150 filterData.site_id = $rootScope.site_id;151 $rootScope.loading = true;152 CRUD.store(saveurl, $.param(filterData)).then(function (response) {153 if (response.data.status == "success") {154 toaster.pop('success', "Pump", response.data.message);155 }156 $rootScope.loading = false;157 $scope.pumpData = {};158 $state.go('app.pumps');159 }, function (res) {160 if (res.status == 400) {161 angular.forEach(res.data.validation_errors, function (value, key) {162 toaster.pop('error', '', value[0]);163 });164 }165 $rootScope.loading = false;166 });167 }168 else {169 toaster.pop('error', "Pump", "Whoops Something Wrong");170 }171 }172 }173 }174 $scope.deleteConfirm = function (ID) {175 var modalInstance = $modal.open({176 templateUrl: 'deleteFileModal.html',177 controller: ('remove', ['$scope', '$rootScope', '$localStorage', '$modalInstance', 'toaster', 'ID', remove]),178 size: 'med',179 resolve: {180 ID: function () {181 return ID;182 },183 }184 });185 modalInstance.result.then(function (data) {186 if (data) {187 $scope.deletePump(data);188 }189 });190 }191 function remove($scope, $rootScope, $localStorage, $modalInstance, toaster, ID) {192 $scope.confirm = function () {193 $modalInstance.close(ID);194 }195 $scope.closeModal = function () {196 $modalInstance.close();197 }198 }199 $scope.deletePump = function (id) {200 $rootScope.loading = true;201 CRUD.delete(deleteurl, id).then(function (res) {202 if(res.data.status == "success")203 {204 toaster.pop('success', "Pump", res.data.message);205 $rootScope.loading = false;206 $scope.getAllPumps();207 }208 }, function (error) {209 $rootScope.loading = false;210 toaster.pop('error','',error.data.message);211 });212 };...
js-wdio.js
Source:js-wdio.js
...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) {...
fpScanner.js
Source:fpScanner.js
1const parser = UAParser;2const fpscanner = (function () {3 const TESTS = {4 PHANTOM_UA: 'PHANTOM_UA',5 PHANTOM_PROPERTIES: 'PHANTOM_PROPERTIES',6 PHANTOM_ETSL: 'PHANTOM_ETSL',7 PHANTOM_LANGUAGE: 'PHANTOM_LANGUAGE',8 PHANTOM_WEBSOCKET: 'PHANTOM_WEBSOCKET',9 MQ_SCREEN: 'MQ_SCREEN',10 PHANTOM_OVERFLOW: 'PHANTOM_OVERFLOW',11 PHANTOM_WINDOW_HEIGHT: 'PHANTOM_WINDOW_HEIGHT',12 HEADCHR_UA: 'HEADCHR_UA',13 WEBDRIVER: 'WEBDRIVER',14 HEADCHR_CHROME_OBJ: 'HEADCHR_CHROME_OBJ',15 HEADCHR_PERMISSIONS: 'HEADCHR_PERMISSIONS',16 HEADCHR_PLUGINS: 'HEADCHR_PLUGINS',17 HEADCHR_IFRAME: 'HEADCHR_IFRAME',18 CHR_DEBUG_TOOLS: 'CHR_DEBUG_TOOLS',19 SELENIUM_DRIVER: 'SELENIUM_DRIVER',20 CHR_BATTERY: 'CHR_BATTERY',21 CHR_MEMORY: 'CHR_MEMORY',22 TRANSPARENT_PIXEL: 'TRANSPARENT_PIXEL',23 SEQUENTUM: 'SEQUENTUM',24 VIDEO_CODECS: 'VIDEO_CODECS'25 };26 const VENDORS = {27 ONEPLUS: 'OnePlus'28 };29 const BROWSERS = {30 CHROME: 'Chrome',31 CHROMIUM: 'Chromium',32 OPERA: 'Opera'33 };34 // TODO adds test for memoryDevices > 8 except for 'ONEPLUS'35 const INCONSISTENT = 1;36 const UNSURE = 2;37 const CONSISTENT = 3;38 const analysisResult = (name, consistent, data) => {39 return {name: name, consistent: consistent, data: data};40 };41 const analyseFingerprint = (fingerprint) => {42 const detectionTests = {};43 const uaParsed = parser(fingerprint.userAgent);44 const OS_REF = uaParsed.os.name;45 const OS_VERSION_REF = uaParsed.os.version;46 const BROWSER_REF = uaParsed.browser.name;47 const BROWSER_VERSION_REF = uaParsed.browser.major;48 const IS_MOBILE_REF = uaParsed.device.type === parser.DEVICE.MOBILE;49 const VENDOR_REF = uaParsed.device.vendor;50 const addTestResult = (fn) => {51 let result = fn(fingerprint);52 detectionTests[result.name] = result;53 };54 // Add tests below:55 addTestResult(() => {56 const testResult = /PhantomJS/.test(fingerprint.userAgent) ? INCONSISTENT : CONSISTENT;57 return analysisResult(TESTS.PHANTOM_UA, testResult, {userAgent: fingerprint.userAgent});58 });59 addTestResult(() => {60 const testResult = fingerprint.phantomJS.some((val) => {61 return val;62 }) ? INCONSISTENT : CONSISTENT;63 return analysisResult(TESTS.PHANTOM_PROPERTIES, testResult, {attributesFound: fingerprint.phantomJS});64 });65 addTestResult(() => {66 let testResult = !/Firefox/.test(fingerprint.userAgent) && !/Safari/.test(BROWSER_REF) &&67 fingerprint.etsl === 37 ? INCONSISTENT : CONSISTENT;68 return analysisResult(TESTS.PHANTOM_ETSL, testResult, {etsl: fingerprint.etsl});69 });70 addTestResult(() => {71 let testResult = !/Trident|MSIE|Edge/.test(fingerprint.userAgent) &&72 fingerprint.languages === undefined ? INCONSISTENT : CONSISTENT;73 return analysisResult(TESTS.PHANTOM_LANGUAGE, testResult, {languages: fingerprint.languages});74 });75 addTestResult(() => {76 let testResult = /SyntaxError: DOM Exception 12/.test(fingerprint.errorsGenerated[7]) ? INCONSISTENT : CONSISTENT;77 return analysisResult(TESTS.PHANTOM_WEBSOCKET, testResult, {error: fingerprint.errorsGenerated[7]});78 });79 addTestResult(() => {80 let testResult = fingerprint.screenMediaQuery ? CONSISTENT : INCONSISTENT;81 return analysisResult(TESTS.MQ_SCREEN, testResult, {});82 });83 addTestResult(() => {84 let testResult = fingerprint.resOverflow.errorName === 'RangeError' &&85 fingerprint.resOverflow.errorMessage === 'Maximum call stack size exceeded.' &&86 fingerprint.resOverflow.errorStacklength > 20 * fingerprint.resOverflow.depth ? INCONSISTENT : CONSISTENT;87 return analysisResult(TESTS.PHANTOM_OVERFLOW, testResult, fingerprint.resOverflow)88 });89 addTestResult(() => {90 let testResult = fingerprint.screen.sAvailWidth <= fingerprint.screen.sWidth &&91 fingerprint.screen.sAvailHeight <= fingerprint.screen.sHeight ? CONSISTENT : INCONSISTENT;92 return analysisResult(TESTS.PHANTOM_WINDOW_HEIGHT, testResult, fingerprint.screen);93 });94 addTestResult(() => {95 let testResult = /HeadlessChrome/.test(fingerprint.userAgent) ? INCONSISTENT : CONSISTENT;96 return analysisResult(TESTS.HEADCHR_UA, testResult, {userAgent: fingerprint.userAgent});97 });98 addTestResult(() => {99 let testResult;100 if (/Chrome/.test(fingerprint.userAgent)) {101 testResult = fingerprint.webDriver ? INCONSISTENT : CONSISTENT;102 } else {103 // Safari, Firefox have a webriver, but it is set to false104 testResult = fingerprint.webDriver && fingerprint.webDriverValue ? INCONSISTENT : CONSISTENT;105 }106 return analysisResult(TESTS.WEBDRIVER, testResult, {});107 });108 addTestResult(() => {109 let testResult = !fingerprint.hasChrome && /Chrome|Chromium/.test(BROWSER_REF) ? INCONSISTENT : CONSISTENT;110 return analysisResult(TESTS.HEADCHR_CHROME_OBJ, testResult, {});111 });112 addTestResult(() => {113 let testResult = fingerprint.permissions.permission === 'denied' &&114 fingerprint.permissions.state === 'prompt' ? INCONSISTENT : CONSISTENT;115 return analysisResult(TESTS.HEADCHR_PERMISSIONS, testResult, {});116 });117 addTestResult(() => {118 let testResult = /Chrome/.test(fingerprint.userAgent) &&119 fingerprint.plugins.length === 0 ? UNSURE : CONSISTENT;120 return analysisResult(TESTS.HEADCHR_PLUGINS, testResult, {plugins: fingerprint.plugins});121 });122 addTestResult(() => {123 let testResult = /Chrome/.test(fingerprint.userAgent) &&124 fingerprint.iframeChrome === 'undefined' ? INCONSISTENT : CONSISTENT;125 return analysisResult(TESTS.HEADCHR_IFRAME, testResult, {});126 });127 addTestResult(() => {128 let testResult = /Chrome/.test(fingerprint.userAgent) &&129 fingerprint.debugTool ? UNSURE : CONSISTENT;130 console.log(testResult);131 console.log(/Chrome/.test(fingerprint.userAgent));132 console.log(fingerprint.debugTool);133 return analysisResult(TESTS.CHR_DEBUG_TOOLS, testResult, {});134 });135 addTestResult(() => {136 const testResult = fingerprint.selenium.some((val) => {137 return val;138 }) ? INCONSISTENT : CONSISTENT;139 return analysisResult(TESTS.SELENIUM_DRIVER, testResult, {attributesFound: fingerprint.selenium});140 });141 addTestResult(() => {142 let testResult = /Chrome/.test(fingerprint.userAgent) &&143 BROWSER_VERSION_REF > 49 && !fingerprint.battery ? INCONSISTENT : CONSISTENT;144 return analysisResult(TESTS.CHR_BATTERY, testResult, {});145 });146 addTestResult(() => {147 let testResult = CONSISTENT;148 if (fingerprint.deviceMemory !== 0 &&149 !(BROWSER_REF === BROWSERS.CHROME && BROWSER_VERSION_REF >= 63) &&150 !(/Opera/.test(BROWSER_REF) && BROWSER_VERSION_REF >= 50)) {151 // If deviceMemory != 0 and not recent Chrome or Opera152 testResult = INCONSISTENT;153 } else if (fingerprint.deviceMemory === 0 &&154 ((BROWSER_REF === BROWSERS.CHROME && BROWSER_VERSION_REF >= 63) ||155 (/Opera/.test(BROWSER_REF) && BROWSER_VERSION_REF >= 50))) {156 // If deviceMemory = 0 and recent Chrome or Opera157 testResult = INCONSISTENT;158 }159 return analysisResult(TESTS.CHR_MEMORY, testResult, {});160 });161 addTestResult(() => {162 let testResult = fingerprint.tpCanvas !== 'error' &&163 fingerprint.tpCanvas[0] === 0 &&164 fingerprint.tpCanvas[1] === 0 &&165 fingerprint.tpCanvas[2] === 0 &&166 fingerprint.tpCanvas[3] === 0 ? CONSISTENT : UNSURE;167 return analysisResult(TESTS.TRANSPARENT_PIXEL, testResult, fingerprint.tpCanvas);168 });169 addTestResult(() => {170 let testResult = fingerprint.sequentum ? INCONSISTENT : CONSISTENT;171 return analysisResult(TESTS.SEQUENTUM, testResult, {});172 });173 // TODO: do more tests on Windows and Mac OS to change UNSURE to INCONSISTENT174 addTestResult(() => {175 let testResult = (BROWSER_REF === BROWSERS.CHROME || BROWSER_REF === BROWSERS.CHROMIUM) &&176 fingerprint.videoCodecs.h264 !== 'probably' ? UNSURE : CONSISTENT;177 return analysisResult(TESTS.VIDEO_CODECS, testResult, {h264: fingerprint.videoCodecs.h264});178 });179 return detectionTests;180 };181 return {182 analyseFingerprint: analyseFingerprint,183 CONSISTENT: CONSISTENT,184 UNSURE: UNSURE,185 INCONSISTENT: INCONSISTENT,186 TESTS: TESTS187 }188})();189let cptt = 0;190const regexpp = /./;191regexpp.toString = () => {192 cptt++;193 return 'spooky';194};195let aa = cptt.toString();196console.debug(regexpp);197//cptt > 1;...
js-oxygen.js
Source:js-oxygen.js
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';...
fpEvaluate.js
Source:fpEvaluate.js
1 2 3function testPhantom(fingerprint, BROWSER_REF) {4 return [5 /PhantomJS/.test(fingerprint.userAgent), 6 fingerprint.phantomJS.some((val) => { return val;}), 7 !/Firefox/.test(fingerprint.userAgent) && !/Safari/.test(BROWSER_REF) && fingerprint.etsl === 37, 8 !/Trident|MSIE|Edge/.test(fingerprint.userAgent) && fingerprint.languages === undefined, 9 /SyntaxError: DOM Exception 12/.test(fingerprint.errorsGenerated[7])10 ]11}12function testOverriddenPermissions(fingerprint) {13 const navigatorPermissions = fingerprint.permissions.permissions;14 return [15 navigatorPermissions.query.toString() !== 'function query() { [native code] }',16 navigatorPermissions.query.toString.toString() !== 'function toString() { [native code] }',17 navigatorPermissions.query.toString.hasOwnProperty('[[Handler]]') && navigatorPermissions.query.toString.hasOwnProperty('[[Target]]') && navigatorPermissions.query.toString.hasOwnProperty('[[IsRevoked]]'),18 navigatorPermissions.hasOwnProperty('query')19 ]20}21function testOverriddenLanguagesAndPlugins() {22 // evaluateOnNewDocument scripts don't apply within [srcdoc] (or [sandbox]) iframes23 // https://github.com/GoogleChrome/puppeteer/issues/1106#issuecomment-35931389824 const iframe = document.createElement('iframe');25 iframe.srcdoc = 'page intentionally left blank';26 document.body.appendChild(iframe);27 const descriptors = Object.getOwnPropertyDescriptors(HTMLIFrameElement.prototype);28 return [29 // Verify iframe prototype isn't touched30 descriptors.contentWindow.get.toString() !== 'function get contentWindow() { [native code] }',31 // Verify iframe isn't remapped to main window32 iframe.contentWindow === window,33 iframe.contentWindow.navigator.plugins.length === 0,34 iframe.contentWindow.navigator.languages === ''35 ]36}37function checkUAOS(fingerprint, OS_REF, DEVICE_TYPE_REF) {38 var navigatorOscpu = fingerprint.oscpu.toLowerCase();39 var navigatorPlatform = fingerprint.platform.toLowerCase();40 var navigatorUA = fingerprint.userAgent.toLowerCase();41 return [42 // should be touch screen but not.. hopefully this doesnt screw over43 // mobile users. need to test44 // reliable to guess that isBot = true if there is touchscreen but device45 // = empty?46 !fingerprint.touchScreen.some((val) => { return val; }) && ["mobile", "tablet", "wearable"].includes(DEVICE_TYPE_REF),47 48 (navigatorOscpu !== "unknown") && ((navigatorOscpu.indexOf("win") >= 0 && !OS_REF.includes("Windows")) || (navigatorOscpu.indexOf("linux") >= 0 && navigatorUA.indexOf("linux") < 0) || (navigatorOscpu.indexOf("mac") >= 0 && !(["Mac OS", "iOS"].includes(OS_REF)))),49 50 (navigatorPlatform !== "unknown") && ((navigatorPlatform.indexOf("win") >= 0 && !OS_REF.includes("Windows")) || ((navigatorPlatform.indexOf("linux") >= 0 || navigatorPlatform.indexOf("android") >= 0 || navigatorPlatform.indexOf("pike") >= 0) && navigatorUA.indexOf("linux") < 0) || ((navigatorPlatform.indexOf("mac") >= 0 || navigatorPlatform.indexOf("ipad") >= 0 || navigatorPlatform.indexOf("ipod") >= 0 || navigatorPlatform.indexOf("iphone") >= 0) && !(["Mac OS", "iOS"].includes(OS_REF))))51 ]52}53function checkUABrowser(fingerprint, BROWSER_REF) {54 var specialNum = eval.toString().length;55 const browserRef = {37: ["Safari", "Firefox"],39:["IE"],33:["Chrome", "Opera"]}56 const allBrowsers = ["Safari", "Firefox", "IE", "Chrome", "Opera"]57 return [58 (BROWSER_REF.includes("Chrome") || BROWSER_REF.includes("Opera") || BROWSER_REF.includes("Android") || BROWSER_REF.includes("Edge") || BROWSER_REF.includes("Safari")) && fingerprint.productSub !== "20030107",59 37 === specialNum && (!browserRef[37].some((val) => BROWSER_REF.includes(val)) && allBrowsers.some((val) => BROWSER_REF.includes(val))),60 39 === specialNum && (!browserRef[39].some((val) => BROWSER_REF.includes(val)) && allBrowsers.some((val) => BROWSER_REF.includes(val))),61 33 === specialNum && (!browserRef[33].some((val) => BROWSER_REF.includes(val)) && allBrowsers.some((val) => BROWSER_REF.includes(val)))62 ]63}64function modaliseOutput(mode, testName) {65 var output = true;66 if (mode === "verbose") {67 output = [true, testName];68 }69 return output;70}71function isBot(fingerprint, mode="") {72 var parser = new UAParser();73 parser.setUA(fingerprint.userAgent);74 var uaParsed = parser.getResult();75 const BROWSER_REF = uaParsed.browser.name;76 const OS_REF = uaParsed.os.name;77 const BROWSER_VERSION = parseFloat(uaParsed.browser.version);78 const DEVICE_TYPE_REF = uaParsed.device.type;79 const BROWSERS = {80 CHROME: 'Chrome',81 CHROMIUM: 'Chromium',82 OPERA: 'Opera'83 };84 if (testPhantom(fingerprint).some((val) => { return val; })) {85 return modaliseOutput(mode, "testPhantom");86 }87 if (!fingerprint.screenMediaQuery) {88 return modaliseOutput(mode, "watchMediaSize");89 }90 if (fingerprint.resOverflow.errorName === 'RangeError' && fingerprint.resOverflow.errorMessage === 'Maximum call stack size exceeded.' && fingerprint.resOverflow.errorStacklength > 20 * fingerprint.resOverflow.depth) {91 return modaliseOutput(mode, "longNameTest");92 }93 if (fingerprint.screen.sAvailWidth > fingerprint.screen.sWidth ||94 fingerprint.screen.sAvailHeight > fingerprint.screen.sHeight) {95 return modaliseOutput(mode, "screenSize");96 }97 if (/HeadlessChrome/.test(fingerprint.userAgent)) {98 return modaliseOutput(mode, "puppeteer1");99 }100 if (/Chrome/.test(fingerprint.userAgent) && BROWSER_VERSION < 80) {101 if (fingerprint.webDriver) {102 return modaliseOutput(mode, "puppeteer2");103 }104 }105 else {106 if (fingerprint.webDriver && fingerprint.webDriverValue) {107 return modaliseOutput(mode, "altHeadless");108 }109 }110 if (!fingerprint.hasChrome && /Chrome|Chromium/.test(BROWSER_REF)) {111 return modaliseOutput(mode, "windowChromeLiar");112 }113 if (fingerprint.permissions.permissionNotification === 'denied' && fingerprint.permissions.state === 'prompt') {114 return modaliseOutput(mode, "permissionsMatch");115 }116 if (/Chrome/.test(fingerprint.userAgent) && fingerprint.iframeChrome === 'undefined') {117 return modaliseOutput(mode, "chromeIFrameCheck");118 }119 // following 2 from here: https://github.com/paulirish/headless-cat-n-mouse120 if (/Chrome/.test(fingerprint.userAgent)) {121 if (testOverriddenLanguagesAndPlugins().some((val) => { return val; })) {122 return modaliseOutput(mode, "overridenLangsPlugins");123 }124 if (testOverriddenPermissions(fingerprint).some((val) => { return val; })) {125 return modaliseOutput(mode, "overridenPermissions");126 }127 }128 if (fingerprint.selenium.some((val) => { return val; })) {129 return modaliseOutput(mode, "selenium");130 }131 // If deviceMemory != 0 and not recent Chrome or Opera132 if (fingerprint.deviceMemory !== 0 && !(BROWSER_REF === BROWSERS.CHROME && BROWSER_VERSION >= 63) && !(/Opera/.test(BROWSER_REF) && BROWSER_VERSION >= 50)) {133 return modaliseOutput(mode, "deviceMemory1");134 }135 // If deviceMemory = 0 and recent Chrome or Opera136 if (fingerprint.deviceMemory === 0 && ((BROWSER_REF === BROWSERS.CHROME && BROWSER_VERSION >= 63) || (/Opera/.test(BROWSER_REF) && BROWSER_VERSION >= 50))) {137 return modaliseOutput(mode, "deviceMemory2");138 }139 if (fingerprint.sequentum) {140 return modaliseOutput(mode, "sequentumTest");141 }142 if (checkUAOS(fingerprint, OS_REF, DEVICE_TYPE_REF).some((val) => { return val; })) {143 return modaliseOutput(mode, "naughtyOS");144 }145 if (checkUABrowser(fingerprint, BROWSER_REF).some((val) => { return val; })) {146 return modaliseOutput(mode, "naughtyBrowser");147 }148 return false;...
AndroidSettings.js
Source:AndroidSettings.js
1import {DEFAULT_PIN} from "../configs/constants";2class AndroidSettings {3 /**4 * Find an element based on text5 *6 * @param {String} string7 *8 * @return WebdriverIO.Element9 */10 findAndroidElementByText(string) {11 return $(`android=new UiSelector().textContains("${string}")`);12 }13 /**14 * Enable biometric login15 */16 enableBiometricLogin() {17 // Android Oreo and higher (API 26+) added `locksettings` to ADB to set the pin. So we need to take18 // a different flow Android on lower than OREO19 if (driver.capabilities.deviceApiLevel < 26) {20 // Open the settings screen21 this.executeAdbCommand('am start -a android.settings.SECURITY_SETTINGS');22 this.waitAndClick('Fingerprint');23 this.fingerPrintWizardSevenOrLower(DEFAULT_PIN);24 } else {25 // Open the settings screen and set screen lock to pin26 this.executeAdbCommand(`am start -a android.settings.SECURITY_SETTINGS && locksettings set-pin ${DEFAULT_PIN}`);27 this.waitAndClick('Fingerprint');28 this.fingerPrintWizardEightOrHigher(DEFAULT_PIN);29 }30 // We need to end this method where we started it, which is the current running app31 // Open the app again32 driver.launchApp();33 }34 /**35 * Execute the fingerprint wizard for Android 7 or lower36 *37 * @param {number} pin38 */39 fingerPrintWizardSevenOrLower(pin) {40 this.waitAndClick('NEXT');41 this.setPinSevenOrLower(pin)42 this.touchSensorSevenOrLower(pin)43 this.waitAndClick('DONE');44 }45 /**46 * Enable the finger print through the wizard47 *48 * @param {number} pin49 */50 fingerPrintWizardEightOrHigher(pin) {51 // There is a difference in the order the wizard in Android 10 is executed52 if (driver.capabilities.deviceApiLevel > 28) {53 this.reEnterPin(pin);54 this.waitAndClick('NEXT');55 } else {56 this.waitAndClick('NEXT');57 this.reEnterPin(pin);58 }59 this.touchSensorEightAndHigher(pin);60 this.waitAndClick('DONE');61 }62 /**63 * Wait and click on an element64 *65 * @param {string} string66 */67 waitAndClick(string){68 this.findAndroidElementByText(string).waitForDisplayed();69 this.findAndroidElementByText(string).click();70 }71 /**72 * Re-enter pin and submit screen73 *74 * @param {number} pin75 */76 reEnterPin(pin) {77 this.findAndroidElementByText('Re-enter your PIN').waitForDisplayed();78 this.executeAdbCommand(`input text ${pin} && input keyevent 66`);79 }80 /**81 * Set the pin for Android 7 or lower82 *83 * @param {number} pin84 */85 setPinSevenOrLower(pin) {86 this.waitAndClick('Fingerprint + PIN');87 this.waitAndClick('No thanks');88 this.findAndroidElementByText('Choose your PIN').waitForDisplayed();89 this.executeAdbCommand(`input text ${pin} && input keyevent 66 && input text ${pin} && input keyevent 66`);90 this.waitAndClick('DONE');91 }92 /**93 * Touch sensor and enable finger print for Android 7 and lower94 *95 * @param {number} pin96 */97 touchSensorSevenOrLower(pin) {98 // Touch code needs to be a number99 const touchCode = parseInt(pin, 10);100 this.waitAndClick('NEXT');101 this.findAndroidElementByText('Put your finger').waitForDisplayed();102 driver.fingerPrint(touchCode);103 this.findAndroidElementByText('Move your finger').waitForDisplayed();104 driver.fingerPrint(touchCode);105 }106 /**107 * Touch sensor and enable finger print for Android 8 and higher108 *109 * @param {number} pin110 */111 touchSensorEightAndHigher(pin) {112 // Touch code needs to be a number113 const touchCode = parseInt(pin, 10);114 // Touch the sensor for the first time to trigger finger print115 this.findAndroidElementByText('Touch the sensor').waitForDisplayed();116 driver.fingerPrint(touchCode);117 // Add finger print118 this.findAndroidElementByText('Put your finger').waitForDisplayed();119 driver.fingerPrint(touchCode);120 // Confirm finger print121 this.findAndroidElementByText('Keep lifting').waitForDisplayed();122 driver.fingerPrint(touchCode);123 }124 /**125 * Execute ADB commands on the device126 *127 * @param {string} adbCommand128 */129 executeAdbCommand(adbCommand) {130 driver.execute(131 'mobile: shell',132 {133 command: adbCommand,134 },135 );136 }137}...
Login.js
Source:Login.js
1// import { Given, When, Then } from 'cucumber';2// import { expect } from 'chai';3// class Login extends CommonPage {4// static teclaLabel = "Teclado Clave Tecla ";5// botonAceptar = $("~Boton Aceptar");6// botonAyuda = $("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup[3]/android.view.ViewGroup/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.view.ViewGroup/androidx.appcompat.widget.LinearLayoutCompat/android.widget.TextView\n");7// botonActivarBiometria = $("~Activar biometria");8// botonCancelarBiometria = $("~Cancelar biometria");9// botonCancelarLimiteDispositivos = $("~Cancelar");10// boton1 = $(teclaLabel + "1");11// botonContinuarUltimoIntento = $("~Continuar");12// enterPasscode(pass) {13// for (i = 0; i < pass.length(); i++) {14// c = Character.toString(pass.charAt(i));15// $(teclaLabel + c).click();16// }17// }18// pressHelp() {19// this.botonAyuda.click();20// }21// helpAvailable() {22// botonAyuda.waitForDisplayed();23// }24// showsDeviceLimitBreached() {25// //TODO: CHEQUEAR26// botonCancelarLimiteDispositivos.waitForDisplayed();27// }28// enableFingerprint() {29// this.botonActivarBiometria.click();30// }31// cancelFingerprintModal() {32// this.botonCancelarBiometria.click();33// }34// enterFingerprint() {35// appium = SerenityWebdriverManager.inThisTestThread().getActiveDrivers().get(0);36// if (appium.getCapabilities().getCapability(MobileCapabilityType.PLATFORM_NAME) == "Android") {37// //appium.execute("adb -e emu finger touch 1");38// AndroidDriver driver = new AndroidDriver(appium.getCapabilities());39// driver.fingerPrint(1);40// } else if41// (appium.getCapabilities().getCapability(MobileCapabilityType.PLATFORM_NAME) == "IOS") {42// IOSDriver driver = new IOSDriver(appium.getCapabilities());43// driver.performTouchID(true);44// }45// }46// acceptTermsAndConditions() {47// try {48// if (botonAceptar.isDisplayed())this.botonAceptar.click();49// } catch (ElementShouldBeEnabledException | NoSuchElementException e) {50// }51// }52// keyboardIsDisplayed() {53// boton1.waitForDisplayed();54// }55// continueToLastAttempt() {56// this.botonContinuarUltimoIntento.click();57// }...
View.js
Source:View.js
1const wdio = require('webdriverio');2const selectors = require('./selectors');3module.exports = class View {4 driver = wdio.remote;5 constructor(driver) {6 this.driver = driver;7 }8 async waitForElement(selector, timeout = 10000) {9 await this.driver.waitUntil(10 async () => {11 return (await this.driver.$$(selector)).length === 1;12 },13 {timeout},14 );15 return await this.driver.$(selector);16 }17 async waitForElementSetValue(selector, value) {18 const elm = await this.waitForElement(selector);19 await elm.setValue(value);20 }21 async waitForElementClick(selector) {22 const elm = await this.waitForElement(selector);23 await elm.click();24 }25 async findElements(selector) {26 return await this.driver.$$(selector);27 }28 async findElementClick(selector) {29 await this.driver.$(selector).then((elm) => elm.click());30 }31 async findElementText(selector) {32 return await this.driver.$(selector).then((elm) => elm.getText());33 }34 async pressFinger(index) {35 await this.driver.fingerPrint(index);36 }37 async androidRegisterFingerprint() {38 await this.driver.execute('mobile: shell', {39 command:40 'am start -a android.settings.SECURITY_SETTINGS && locksettings set-pin 1234',41 });42 await this.driver.pause(1500);43 await this.findElementClick(selectors.fingerprintSettings);44 await this.driver.pause(1500);45 await this.driver.execute('mobile: shell', {46 command: 'input text 1234 && input keyevent 66',47 });48 await this.driver.pause(1500);49 await this.findElementClick(selectors.button('NEXT'));50 for (let i = 0; i < 3; i++) {51 await this.driver.pause(1500);52 await this.pressFinger(1);53 }54 await this.driver.pause(1500);55 await this.findElementClick(selectors.button('DONE'));56 }...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .fingerprint(1)9 .end();10var webdriverio = require('webdriverio');11var options = {12 desiredCapabilities: {13 }14};15 .remote(options)16 .init()17 .fingerprint(2)18 .end();19var webdriverio = require('webdriverio');20var options = {21 desiredCapabilities: {22 }23};24 .remote(options)25 .init()26 .fingerprint(3)27 .end();28var webdriverio = require('webdriverio');29var options = {30 desiredCapabilities: {31 }32};33 .remote(options)34 .init()35 .fingerprint(4)36 .end();37var webdriverio = require('webdriverio');38var options = {39 desiredCapabilities: {40 }41};42 .remote(options)43 .init()44 .fingerprint(5)45 .end();46var webdriverio = require('webdriverio');47var options = {48 desiredCapabilities: {49 }50};51 .remote(options)52 .init()53 .fingerprint(6)54 .end();55var webdriverio = require('webdriverio');56var options = {57 desiredCapabilities: {58 }59};60 .remote(options)61 .init()62 .fingerprint(7)63 .end();64var webdriverio = require('webdriverio');65var options = {
Using AI Code Generation
1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();
Using AI Code Generation
1exports.fingerprint = async function fingerprint (fingerprintId) {2 return fingerprintId;3};4exports.fingerprint = async function fingerprint (fingerprintId) {5 return fingerprintId;6};7exports.fingerprint = async function fingerprint (finge
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var android = require('appium-android-driver');3var driver = new android.AndroidDriver();4driver.fingerprint(1);5var webdriver = require('selenium-webdriver');6var android = require('appium-android-driver');7var driver = new android.AndroidDriver();8driver.fingerprint(1);
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!!