Best JavaScript code snippet using webdriverio-monorepo
storage.e2e.js
Source:storage.e2e.js
1describe('should test the Storage service', function () {2 describe('should check operations with directories', function () {3 it('should extract service', function () {4 browser.executeAsyncScript(function (callback) {5 callback(Storage.getStatus());6 })7 .then(function (status) {8 expect(status.status).toBe('Init success.');9 })10 .thenCatch(function (response) {11 throw new Error(response);12 });13 });14 it('should check size of storage', function () {15 browser.executeAsyncScript(function (callback) {16 Storage.getSize()17 .then(function (size) {18 callback(size);19 })20 .catch(function (error) {21 callback(error);22 });23 })24 .then(function (dataSize) {25 expect(dataSize).toEqual({value: 0});26 })27 .thenCatch(function (response) {28 throw new Error(response);29 });30 });31 it('should make directory', function () {32 browser.executeAsyncScript(function (callback) {33 Storage.makeDir('testDirrectory')34 .then(function (fileEntry) {35 callback(fileEntry.fullPath);36 })37 .catch(function (error) {38 callback(error);39 })40 })41 .then(function (fileEntry) {42 expect(fileEntry).toBe('/testDirrectory');43 })44 .thenCatch(function (error) {45 throw new Error(error);46 });47 });48 /**49 * Directory has one level, as example "/directory_name"50 */51 it('should check some directory without create', function () {52 browser.executeAsyncScript(function (callback) {53 Storage.hasDir('testDirrectory2')54 .then(callback)55 .catch(callback)56 })57 .then(function (fileEntry) {58 expect(fileEntry.name).toBe('NotFoundError');59 })60 .thenCatch(function (response) {61 throw new Error(response);62 });63 });64 it('should check directory with create', function () {65 browser.executeAsyncScript(function (callback) {66 Storage.hasDir('testDirrectory2', true)67 .then(function (fileEntry) {68 callback(fileEntry.fullPath);69 })70 .catch(function (error) {71 callback(error);72 })73 })74 .then(function (fileEntry) {75 expect(fileEntry).toBe('/testDirrectory2');76 })77 .thenCatch(function (response) {78 throw new Error(response);79 });80 });81 it('should check exist directory', function () {82 browser.executeAsyncScript(function (callback) {83 Storage.hasDir('testDirrectory2')84 .then(function (fileEntry) {85 callback(fileEntry.fullPath);86 })87 .catch(function (error) {88 callback(error);89 })90 })91 .then(function (fileEntry) {92 expect(fileEntry).toBe('/testDirrectory2');93 })94 .thenCatch(function (response) {95 throw new Error(response);96 });97 });98 it('should remove empty directory', function () {99 browser.executeAsyncScript(function (callback) {100 Storage.removeDir('testDirrectory2')101 .then(function (result) {102 callback(result);103 })104 .catch(function (error) {105 callback(error);106 })107 })108 .then(function (result) {109 expect(result).toBe(true);110 })111 .thenCatch(function (response) {112 throw new Error(response);113 });114 });115 /**116 * Directory has some level, as example "/directory_name/sub_directory_1/sub_directory_2"117 */118 it('should check exist directory with internal level', function () {119 browser.executeAsyncScript(function (callback) {120 Storage.hasDir('parent/child')121 .then(function (fileEntry) {122 callback(fileEntry.name);123 })124 .catch(function (error) {125 callback(error);126 })127 })128 .then(function (fileEntry) {129 expect(fileEntry.name).toBe('NotFoundError');130 })131 .thenCatch(function (response) {132 throw new Error(response);133 });134 });135 it('should check directory with internal level with create', function () {136 browser.executeAsyncScript(function (callback) {137 Storage.hasDir('parent/child', true)138 .then(function (fileEntry) {139 callback(fileEntry.fullPath);140 })141 .catch(function (error) {142 callback(error);143 })144 })145 .then(function (fileEntry) {146 expect(fileEntry).toBe('/parent/child');147 })148 .thenCatch(function (response) {149 throw new Error(response);150 });151 });152 it('should remove parent directory which has child directory', function () {153 browser.executeAsyncScript(function (callback) {154 Storage.removeDir('parent')155 .then(function (result) {156 callback(result);157 })158 .catch(function (error) {159 callback(error);160 })161 })162 .then(function (result) {163 expect(result).toBe(true);164 })165 .thenCatch(function (response) {166 throw new Error(response);167 });168 });169 it('should check directory with internal level with create', function () {170 browser.executeAsyncScript(function (callback) {171 Storage.hasDir('parent/child')172 .then(function (fileEntry) {173 callback(fileEntry.name);174 })175 .catch(function (error) {176 callback(error);177 })178 })179 .then(function (fileEntry) {180 expect(fileEntry.name).toBe('NotFoundError');181 })182 .thenCatch(function (response) {183 throw new Error(response);184 });185 browser.executeAsyncScript(function (callback) {186 Storage.hasDir('parent')187 .then(function (fileEntry) {188 callback(fileEntry.name);189 })190 .catch(function (error) {191 callback(error);192 })193 })194 .then(function (fileEntry) {195 expect(fileEntry.name).toBe('NotFoundError');196 })197 .thenCatch(function (response) {198 throw new Error(response);199 });200 });201 });202 describe('should check operations with files', function () {203 it('should check exist file', function () {204 browser.executeAsyncScript(function (callback) {205 Storage.hasFile('testfile1')206 .then(function (fileEntry) {207 callback(fileEntry);208 })209 .catch(function (error) {210 callback(error);211 })212 })213 .then(function (fileEntry) {214 expect(fileEntry).toBe(false);215 })216 .thenCatch(function (response) {217 throw new Error(response);218 });219 browser.executeAsyncScript(function (callback) {220 Storage.hasFile('/testdir/testfile1')221 .then(function (fileEntry) {222 callback(fileEntry);223 })224 .catch(function (error) {225 callback(error);226 })227 })228 .then(function (fileEntry) {229 expect(fileEntry).toBe(false);230 })231 .thenCatch(function (response) {232 throw new Error(response);233 });234 });235 it('should create file', function () {236 browser.executeAsyncScript(function (callback) {237 Storage.makeFile('testfile1', 'Some data')238 .then(function (fileEntry) {239 fileEntry.getMetadata(function (meta) {240 callback({241 size: fileEntry.name,242 fullPath: fileEntry.fullPath,243 isFile: fileEntry.isFile,244 size: meta.size245 });246 });247 })248 .catch(function (error) {249 callback(error);250 })251 })252 .then(function (fileEntry) {253 expect(fileEntry).toEqual({254 fullPath: '/testfile1',255 size: 'testfile1',256 isFile: true,257 size: 9258 });259 })260 .thenCatch(function (response) {261 throw new Error(response);262 });263 });264 it('should get size of filesystem after create the file', function () {265 browser.executeAsyncScript(function (callback) {266 Storage.getSize()267 .then(function (size) {268 callback(size);269 })270 .catch(function (error) {271 callback(error);272 });273 })274 .then(function (dataSize) {275 expect(dataSize).toEqual({value: 9});276 })277 .thenCatch(function (response) {278 throw new Error(response);279 });280 });281 it('should check the file after create', function () {282 browser.executeAsyncScript(function (callback) {283 Storage.hasFile('testfile1')284 .then(function (fileEntry) {285 callback(fileEntry.name);286 })287 .catch(function (error) {288 callback(error);289 })290 })291 .then(function (fileEntry) {292 expect(fileEntry).toBe('testfile1');293 })294 .thenCatch(function (response) {295 throw new Error(response);296 });297 });298 it('should remove the file', function () {299 browser.executeAsyncScript(function (callback) {300 Storage.removeFile('testfile1')301 .then(function (result) {302 callback(result);303 })304 .catch(function (error) {305 callback(error);306 })307 })308 .then(function (result) {309 expect(result).toBe(true);310 // Check exists file after remove311 browser.executeAsyncScript(function (callback) {312 Storage.hasFile('testfile1')313 .then(function (fileEntry) {314 callback(fileEntry.name);315 })316 .catch(function (error) {317 callback(error);318 })319 })320 .then(function (fileEntry) {321 expect(fileEntry).toBe(false);322 })323 .thenCatch(function (response) {324 throw new Error(response);325 });...
affixing-header-specs.js
Source:affixing-header-specs.js
...82 before(function() {83 return setupDocument();84 });85 beforeEach(function() {86 return driver.executeAsyncScript(function() {87 arguments[arguments.length - 1](document.documentElement.scrollHeight);88 }).then(function(scrollHeight) {89 pageHeight = scrollHeight;90 });91 });92 afterEach(function() {93 // Reset position and refresh browser, wait until it is reloaded94 driver.manage().timeouts().setScriptTimeout(scriptTimeout, 1);95 driver.executeAsyncScript(scrollTo(), 0).then(function() {96 driver.navigate().refresh();97 });98 driver.manage().timeouts().implicitlyWait(6000, 1);99 return driver.wait(webdriver.until.elementLocated({className: 'is-ready'}));100 });101 after(function() {102 // Using mocha's bail option, if test gets here, it passed103 // if (process.env.SAUCE_USERNAME && process.env.TRAVIS_JOB_NUMBER) {104 // var sauce = new Saucelabs({105 // username: process.env.SAUCE_USERNAME,106 // password: process.env.SAUCE_ACCESS_KEY107 // });108 // sauce.updateJob(sauceSessionId, {passed: true}, function () {});109 // }110 return driver.quit();111 // Resolve promise112 // deferred.resolve();113 });114 it('keeps header at top of document.body (off screen) when user scrolls down', function() {115 var header = driver.findElement({className: 'affixing-header'});116 expect(header.getCssValue('top')).to.eventually.equal('0px');117 expect(header.getCssValue('position')).to.eventually.equal('absolute');118 driver.manage().timeouts().setScriptTimeout(scriptTimeout, 1);119 return driver.executeAsyncScript(scrollTo(), Math.round(pageHeight / 2)).then(function(computedStyles) {120 expect(computedStyles.top).to.equal('0px');121 expect(computedStyles.position).to.equal('absolute');122 });123 });124 it('adjusts header position with bottom at the top of the viewport after âintentionalâ upward scrolling', function() {125 var scrollCount = 8,126 scrollY = Math.round(pageHeight / 2);127 driver.manage().timeouts().setScriptTimeout(scriptTimeout, 1 + scrollCount + 1);128 driver.executeAsyncScript(scrollTo(), scrollY).then(function(computedStyles) {129 expect(computedStyles.top).to.equal('0px');130 expect(computedStyles.position).to.equal('absolute');131 });132 while (scrollCount--) {133 scrollY -= 4;134 driver.executeAsyncScript(scrollTo(), scrollY);135 }136 return driver.executeAsyncScript(scrollTo(), scrollY - 2).then(function(computedStyles) {137 // TODO: should this be more specific?138 expect(computedStyles.top).to.not.equal('0px');139 expect(computedStyles.position).to.equal('absolute');140 });141 });142 it('adjusts header position to fixed when user scrolls back up the page far enough', function() {143 var scrollCount = 14,144 scrollY = Math.round(pageHeight / 2),145 scrollDelta = Math.round(scrollY / (scrollCount + 4));146 driver.manage().timeouts().setScriptTimeout(scriptTimeout, 1 + scrollCount + 1);147 driver.executeAsyncScript(scrollTo(), scrollY).then(function(computedStyles) {148 expect(computedStyles.top).to.equal('0px');149 expect(computedStyles.position).to.equal('absolute');150 });151 while (scrollCount--) {152 scrollY -= scrollDelta;153 driver.executeAsyncScript(scrollTo(), scrollY);154 }155 return driver.executeAsyncScript(scrollTo(), scrollY - scrollDelta).then(function(computedStyles) {156 expect(computedStyles.top).to.equal('0px');157 expect(computedStyles.position).to.equal('fixed');158 });159 });160 it('allows header to disappear again when scrolling down', function() {161 var scrollY = Math.round(pageHeight / 2);162 driver.manage().timeouts().setScriptTimeout(scriptTimeout, 4);163 driver.executeAsyncScript(scrollTo(), scrollY).then(function(computedStyles) {164 expect(computedStyles.top).to.equal('0px');165 expect(computedStyles.position).to.equal('absolute');166 });167 // Scroll back up a bunch168 scrollY -= Math.round(pageHeight / 8);169 driver.executeAsyncScript(scrollTo(), scrollY).then(function() {});170 scrollY -= Math.round(pageHeight / 8);171 driver.executeAsyncScript(scrollTo(), scrollY).then(function(computedStyles) {172 // Header should be affixed173 expect(computedStyles.top).to.equal('0px');174 expect(computedStyles.position).to.equal('fixed');175 });176 return driver.executeAsyncScript(scrollTo(), scrollY + 5).then(function(computedStyles) {177 // Header should no longer be fixed178 expect(computedStyles.top).to.not.equal('0px');179 expect(computedStyles.position).to.equal('absolute');180 });181 });182 });183}...
app.helpers.js
Source:app.helpers.js
...6 },7 AppConfig: {8 get: function(){9 var data = {};10 return browser.executeAsyncScript(function(data, callback) {11 var AppConfig = window.AppConfig;12 callback(AppConfig);13 }, data);14 }15 },16 MessageSvc: {17 infoEnable: function(enable) {18 var data = {enable:enable};19 return browser.executeAsyncScript(function(data, callback) {20 var MessageSvc = angular.element(document.body).injector().get('MessageSvc');21 MessageSvc.infoEnable=data.enable;22 callback(MessageSvc.infoEnable);23 }, data);24 },25 confirmEnable: function(enable) {26 var data = {enable:enable};27 return browser.executeAsyncScript(function(data, callback) {28 var MessageSvc = angular.element(document.body).injector().get('MessageSvc');29 MessageSvc.confirmEnable=data.enable;30 callback(MessageSvc.confirmEnable);31 }, data);32 }33 },34 AccountSvc: {35 item: function(){36 var data = {};37 return browser.executeAsyncScript(function(data, callback) {38 var AccountSvc = angular.element(document.body).injector().get('AccountSvc');39 callback(AccountSvc.item);40 }, data);41 },42 doLogin: function(email, password) {43 var data = {email:email, password:password};44 return browser.executeAsyncScript(function(data, callback) {45 var AccountSvc = angular.element(document.body).injector().get('AccountSvc');46 AccountSvc.doLogin(data.email, data.password);47 setTimeout(function(){48 callback(AccountSvc.item);49 },5000);50 }, data);51 },52 doLogout: function() {53 var data = {};54 return browser.executeAsyncScript(function(data, callback) {55 var AccountSvc = angular.element(document.body).injector().get('AccountSvc');56 AccountSvc.doLogout();57 setTimeout(function(){58 callback(AccountSvc.item);59 },5000);60 }, data);61 },62 doUpdate: function(item) {63 var data = item;64 return browser.executeAsyncScript(function(data, callback) {65 var AccountSvc = angular.element(document.body).injector().get('AccountSvc');66 AccountSvc.doUpdate(data);67 setTimeout(function(){68 callback(AccountSvc.item);69 },5000);70 }, data);71 }72 },73 ProjectSvc:{74 item: function(){75 var data = {};76 return browser.executeAsyncScript(function(data, callback) {77 var ProjectSvc = angular.element(document.body).injector().get('ProjectSvc');78 callback(ProjectSvc.item);79 }, data);80 },81 list: function(){82 var data = {};83 return browser.executeAsyncScript(function(data, callback) {84 var ProjectSvc = angular.element(document.body).injector().get('ProjectSvc');85 callback(ProjectSvc.list);86 }, data);87 },88 doUpdate: function(item) {89 var data = item;90 return browser.executeAsyncScript(function(data, callback) {91 var ProjectSvc = angular.element(document.body).injector().get('ProjectSvc');92 ProjectSvc.doUpdate(data);93 setTimeout(function(){94 callback(ProjectSvc.item);95 },5000);96 }, data);97 },98 doCreate: function(item) {99 var data = item;100 return browser.executeAsyncScript(function(data, callback) {101 var ProjectSvc = angular.element(document.body).injector().get('ProjectSvc');102 ProjectSvc.doCreate(data);103 setTimeout(function(){104 callback(ProjectSvc.item);105 },5000);106 }, data);107 },108 doDelete: function(item) {109 var data = item;110 return browser.executeAsyncScript(function(data, callback) {111 var ProjectSvc = angular.element(document.body).injector().get('ProjectSvc');112 ProjectSvc.doDelete(data);113 setTimeout(function(){114 callback(ProjectSvc.item);115 },5000);116 }, data);117 }118 },119 PostSvc:{120 item: function(){121 var data = {};122 return browser.executeAsyncScript(function(data, callback) {123 var PostSvc = angular.element(document.body).injector().get('PostSvc');124 callback(PostSvc.item);125 }, data);126 },127 list: function(){128 var data = {};129 return browser.executeAsyncScript(function(data, callback) {130 var PostSvc = angular.element(document.body).injector().get('PostSvc');131 callback(PostSvc.list);132 }, data);133 },134 doUpdate: function(item) {135 var data = item;136 return browser.executeAsyncScript(function(data, callback) {137 var PostSvc = angular.element(document.body).injector().get('PostSvc');138 PostSvc.doUpdate(data);139 setTimeout(function(){140 callback(PostSvc.item);141 },5000);142 }, data);143 },144 doCreate: function(item) {145 var data = item;146 return browser.executeAsyncScript(function(data, callback) {147 var PostSvc = angular.element(document.body).injector().get('PostSvc');148 PostSvc.doCreate(data);149 setTimeout(function(){150 callback(PostSvc.item);151 },5000);152 }, data);153 },154 doDelete: function(item) {155 var data = item;156 return browser.executeAsyncScript(function(data, callback) {157 var PostSvc = angular.element(document.body).injector().get('PostSvc');158 PostSvc.doDelete(data);159 setTimeout(function(){160 callback(PostSvc.item);161 },5000);162 }, data);163 }164 },165 FileSvc:{166 list: function() {167 var data = {};168 return browser.executeAsyncScript(function(data, callback) {169 var FileSvc = angular.element(document.body).injector().get('FileSvc');170 callback(FileSvc.list);171 }, data);172 },173 item: function() {174 var data = {};175 return browser.executeAsyncScript(function(data, callback) {176 var FileSvc = angular.element(document.body).injector().get('FileSvc');177 callback(FileSvc.item);178 }, data);179 },180 doDelete: function(item) {181 var data = item;182 return browser.executeAsyncScript(function(data, callback) {183 var FileSvc = angular.element(document.body).injector().get('FileSvc');184 FileSvc.doDelete(data);185 setTimeout(function(){186 callback(FileSvc.item);187 },5000);188 }, data);189 }190 }...
recording-syncronizer.spec.js
Source:recording-syncronizer.spec.js
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17import createRecorderSyncronizer from '../src/recording-syncronizer'18describe('recording syncronizer', () => {19 it('should sync the current window', async () => {20 const executeAsyncScript = jest.fn()21 const {22 hooks: { onStoreWindowHandle },23 } = createRecorderSyncronizer({24 sessionId: 'default',25 executeAsyncScript,26 })27 await onStoreWindowHandle({ windowHandle: '1', windowHandleName: 'first' })28 expect(executeAsyncScript.mock.calls[0][0]).toMatchSnapshot()29 })30 it('should sync a new window when switching to it', async () => {31 const executeAsyncScript = jest.fn()32 const {33 hooks: { onWindowAppeared, onWindowSwitched },34 } = createRecorderSyncronizer({35 sessionId: 'default',36 executeAsyncScript,37 })38 await onWindowAppeared({ windowHandle: '1', windowHandleName: 'first' })39 await onWindowSwitched({ windowHandle: '1' })40 expect(executeAsyncScript.mock.calls[0][0]).toMatchSnapshot()41 })42 it('should not sync a window if switched to it twice', async () => {43 const executeAsyncScript = jest.fn()44 const {45 hooks: { onWindowAppeared, onWindowSwitched },46 } = createRecorderSyncronizer({47 sessionId: 'default',48 executeAsyncScript,49 })50 await onWindowAppeared({ windowHandle: '1', windowHandleName: 'first' })51 await onWindowSwitched({ windowHandle: '1' })52 await onWindowSwitched({ windowHandle: '1' })53 expect(executeAsyncScript).toHaveBeenCalledTimes(1)54 })55 it('should log if tried to switch to a window that has no handle', async () => {56 const executeAsyncScript = jest.fn()57 const error = jest.fn()58 const {59 hooks: { onWindowSwitched },60 } = createRecorderSyncronizer({61 sessionId: 'default',62 executeAsyncScript,63 logger: { error },64 })65 await onWindowSwitched({ windowHandle: '1' })66 expect(error.mock.calls[0][0]).toMatchSnapshot()67 })68 it('should sync a new window when called if onWindowSwitched was not called for it', async () => {69 const executeAsyncScript = jest.fn()70 const switchToWindow = jest.fn()71 const getWindowHandle = jest.fn()72 const {73 hooks: { onWindowAppeared },74 syncAllPendingWindows,75 } = createRecorderSyncronizer({76 sessionId: 'default',77 executeAsyncScript,78 switchToWindow,79 getWindowHandle,80 })81 await onWindowAppeared({ windowHandle: '1', windowHandleName: 'first' })82 await syncAllPendingWindows()83 expect(getWindowHandle).toHaveBeenCalledTimes(1)84 expect(switchToWindow).toHaveBeenCalledTimes(2)85 expect(executeAsyncScript.mock.calls[0][0]).toMatchSnapshot()86 })87 it('should not sync a new window more than once when called', async () => {88 const executeAsyncScript = jest.fn()89 const switchToWindow = jest.fn()90 const getWindowHandle = jest.fn()91 const {92 hooks: { onWindowAppeared },93 syncAllPendingWindows,94 } = createRecorderSyncronizer({95 sessionId: 'default',96 executeAsyncScript,97 switchToWindow,98 getWindowHandle,99 })100 await onWindowAppeared({ windowHandle: '1', windowHandleName: 'first' })101 await syncAllPendingWindows()102 await syncAllPendingWindows()103 expect(getWindowHandle).toHaveBeenCalledTimes(1)104 expect(switchToWindow).toHaveBeenCalledTimes(2)105 expect(executeAsyncScript).toHaveBeenCalledTimes(1)106 })107 it('should sync one window through hooks and one when asked', async () => {108 const executeAsyncScript = jest.fn()109 const switchToWindow = jest.fn()110 const getWindowHandle = jest.fn()111 const {112 hooks: { onWindowAppeared, onWindowSwitched },113 syncAllPendingWindows,114 } = createRecorderSyncronizer({115 sessionId: 'default',116 executeAsyncScript,117 switchToWindow,118 getWindowHandle,119 })120 await onWindowAppeared({ windowHandle: '1', windowHandleName: 'first' })121 await onWindowSwitched({ windowHandle: '1' })122 expect(executeAsyncScript).toHaveBeenCalledTimes(1)123 await onWindowAppeared({ windowHandle: '2', windowHandleName: 'second' })124 await syncAllPendingWindows()125 expect(executeAsyncScript).toHaveBeenCalledTimes(2)126 })127 it('should sync the active context', async () => {128 const executeAsyncScript = jest.fn()129 const { syncActiveContext } = createRecorderSyncronizer({130 sessionId: 'default',131 executeAsyncScript,132 })133 await syncActiveContext()134 expect(executeAsyncScript.mock.calls[0][0]).toMatchSnapshot()135 })...
index.js
Source:index.js
1/*2 Test the "executeAsyncScript" function with a function that waits to return a value.3 */4/* eslint-env node */5"use strict";6var fluid = require("infusion");7fluid.require("%fluid-webdriver");8fluid.webdriver.loadTestingSupport();9fluid.registerNamespace("fluid.tests.webdriver.executeAsyncScript");10fluid.tests.webdriver.executeAsyncScript.getAsyncValue = function () {11 var callback = arguments[arguments.length - 1];12 callback("Not all that asynchronous.");13};14fluid.tests.webdriver.executeAsyncScript.getAsyncValueViaTimeout = function () {15 var callback = arguments[arguments.length - 1];16 setTimeout(function () { callback("Fairly asynchronous."); }, 4000);17};18fluid.defaults("fluid.tests.webdriver.executeAsyncScript.caseHolder", {19 gradeNames: ["fluid.test.webdriver.caseHolder"],20 fileUrl: "%fluid-webdriver/tests/js/executeScript/html/executeScript.html",21 rawModules: [{22 name: "Testing the driver's `executeAsyncScript` function...",23 tests: [24 {25 name: "Get a value from an asynchronous call that immediately resolves...",26 type: "test",27 sequence: [28 {29 func: "{testEnvironment}.webdriver.get",30 args: ["@expand:fluid.test.webdriver.resolveFileUrl({that}.options.fileUrl)"]31 },32 {33 event: "{testEnvironment}.webdriver.events.onGetComplete",34 listener: "{testEnvironment}.webdriver.executeAsyncScript",35 args: [fluid.tests.webdriver.executeAsyncScript.getAsyncValue]36 },37 {38 event: "{testEnvironment}.webdriver.events.onExecuteAsyncScriptComplete",39 listener: "jqUnit.assertEquals",40 args: ["The sample function should have returned the correct value...", "Not all that asynchronous.", "{arguments}.0"]41 }42 ]43 },44 // The docs are misleading, this test demonstrates how to use the `executeAsyncScriptHelper` to ensure the45 // script actually has time to respond.46 //47 // see: https://github.com/SeleniumHQ/selenium/issues/250348 {49 name: "Get a value from an asynchronous call that takes time to respond...",50 type: "test",51 sequence: [52 {53 func: "{testEnvironment}.webdriver.get",54 args: ["@expand:fluid.test.webdriver.resolveFileUrl({that}.options.fileUrl)"]55 },56 {57 event: "{testEnvironment}.webdriver.events.onGetComplete",58 listener: "{testEnvironment}.webdriver.executeAsyncScript",59 args: [fluid.tests.webdriver.executeAsyncScript.getAsyncValueViaTimeout]60 },61 {62 event: "{testEnvironment}.webdriver.events.onExecuteAsyncScriptComplete",63 listener: "jqUnit.assertEquals",64 args: ["The sample function should have returned the correct value...", "Fairly asynchronous.", "{arguments}.0"]65 }66 ]67 }68 ]69 }]70});71fluid.defaults("fluid.tests.webdriver.executeAsyncScript.environment", {72 gradeNames: ["fluid.test.webdriver.testEnvironment"],73 components: {74 caseHolder: {75 type: "fluid.tests.webdriver.executeAsyncScript.caseHolder"76 }77 }78});...
JavascriptExecutor.js
Source:JavascriptExecutor.js
...52 before(function(){53 driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);54 });55 it('can return a WebElement', function() {56 var el = driver.executeAsyncScript(57 wrapInAsync('document.querySelector("[name=q]")')58 );59 assert(el instanceof WebElement);60 });61 it('can return an array of WebElements', function() {62 var divs = driver.executeAsyncScript(63 wrapInAsync('document.querySelectorAll("div")')64 );65 divs.forEach(function(div) {66 assert(div instanceof WebElement);67 });68 });69 it('can return numbers', function() {70 assert.equal(driver.executeAsyncScript(wrapInAsync('5')), 5);71 });72 it('can return strings', function() {73 assert.equal(driver.executeAsyncScript(wrapInAsync('"boo"')), 'boo');74 });75 it('can return objects', function() {76 var result = driver.executeAsyncScript(wrapInAsync('{asdf:5}'));77 assert.equal(result.asdf, 5);78 });79 it('can return arrays', function() {80 var result = driver.executeAsyncScript(wrapInAsync('["boo"]'));81 assert.equal(result[0], 'boo');82 });83 it('handles nested arrays and objects', function(){84 var result = driver.executeAsyncScript(85 wrapInAsync('{arr:["boo"],obj:{asdf:5}}')86 );87 assert.equal(result.arr[0]+result.obj.asdf, 'boo5');88 });89 });90 function wrapInAsync(value){91 return 'var callback = arguments[arguments.length - 1];'92 + 'setTimeout(function(){'93 + ' callback('+value+');'94 + '}, 10);';95 }...
executePromiseScript.js
Source:executePromiseScript.js
2// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html#executeAsyncScript3// This function will use executeAsyncScript to run a Promise function in an async fashion.4export default async function executePromiseScript(driver, fn, ...args) {5 // The executeAsyncScript will turn "undefined" into "null".6 const { error, result } = await driver.executeAsyncScript(7 (fn, args, callback) => {8 eval(`(${fn})`)9 .apply(null, args)10 .then(11 result => callback({ result }),12 ({ message, stack }) => callback({ error: { message, stack } })13 );14 },15 fn + '',16 args17 );18 if (error) {19 const err = new Error(error.message);20 err.stack = error.stack;...
execute-async-script.js
Source:execute-async-script.js
1import Endpoint from '..'2class ExecuteAsyncScript extends Endpoint {3 static create (req) {4 let {script, args} = req.body5 return new ExecuteAsyncScript([script, args])6 }7}8ExecuteAsyncScript.url = '/session/:sid/execute_async'9ExecuteAsyncScript.method = 'post'...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4 .init()5 .executeAsync(function (data, done) {6 var callback = arguments[arguments.length - 1];7 var script = document.createElement('script');8 document.getElementsByTagName('head')[0].appendChild(script);9 script.onload = script.onreadystatechange = function () {10 if (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') {11 callback(true);12 }13 };14 }, function (result) {15 console.log(result);16 })17 .end();
Using AI Code Generation
1describe('webdriver.io page', () => {2 it('should execute async script', () => {3 browser.executeAsync(function (done) {4 setTimeout(function () {5 done('hello world');6 }, 1000);7 }).then(function (result) {8 });9 })10})
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .executeAsync(function (done) {9 var y = document.body.scrollHeight;10 window.scroll(0, y);11 done();12 }).saveScreenshot('screenshot.png')13 .end();
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4 .init()5 .executeAsync(function(done) {6 done('hello world');7 }, function(err, result) {8 console.log(result.value);9 })10 .end();
Using AI Code Generation
1describe('Test', () => {2 it('should get data', () => {3 browser.executeAsync((done) => {4 done(data);5 });6 }).then((data) => {7 assert.equal(data.value[0].name, 'John');8 browser.saveScreenshot('screenshot.png');9 }).end().catch((err) => {10 console.log(err);11 });12 });13});
Wondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.
Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.
Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.
Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.
Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?
Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.
How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.
Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.
Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.
Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.
JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.
Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.
Get 100 minutes of automation test minutes FREE!!