How to use executeHooksWithArgs method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

adapter.test.js

Source:adapter.test.js Github

copy

Full Screen

1import logger from 'wdio-logger'2import { runTestInFiberContext, executeHooksWithArgs } from 'wdio-config'3import JasmineAdapterFactory, { JasmineAdapter } from '../src'4const wdioReporter = {5 write: jest.fn(),6 emit: jest.fn(),7 on: jest.fn()8}9test('comes with a factory', async () => {10 expect(typeof JasmineAdapterFactory.run).toBe('function')11 const result = await JasmineAdapterFactory.run(12 '0-2',13 {},14 ['/foo/bar.test.js'],15 { browserName: 'chrome' },16 wdioReporter17 )18 expect(result).toBe(0)19})20test('should properly set up jasmine', async () => {21 const adapter = new JasmineAdapter(22 '0-2',23 {},24 ['/foo/bar.test.js'],25 { browserName: 'chrome' },26 wdioReporter27 )28 const result = await adapter.run()29 expect(result).toBe(0)30 expect(adapter.jrunner.addSpecFiles.mock.calls[0][0]).toEqual(['/foo/bar.test.js'])31 expect(adapter.jrunner.jasmine.addReporter.mock.calls).toHaveLength(1)32 expect(runTestInFiberContext.mock.calls).toHaveLength(7)33 expect(executeHooksWithArgs.mock.calls).toHaveLength(2)34 expect(adapter.jrunner.env.beforeAll.mock.calls).toHaveLength(1)35 expect(adapter.jrunner.env.beforeEach.mock.calls).toHaveLength(1)36 expect(adapter.jrunner.env.afterEach.mock.calls).toHaveLength(1)37 expect(adapter.jrunner.env.afterAll.mock.calls).toHaveLength(1)38 expect(adapter.jrunner.onComplete.mock.calls).toHaveLength(1)39 expect(adapter.jrunner.execute.mock.calls).toHaveLength(1)40 expect(adapter.jrunner.configureDefaultReporter.name).toBe('noop')41 adapter.jrunner.configureDefaultReporter()42})43test('set custom ', async () => {44 const config = {45 jasmineNodeOpts: { expectationResultHandler: jest.fn() }46 }47 const adapter = new JasmineAdapter(48 '0-2',49 config,50 ['/foo/bar.test.js'],51 { browserName: 'chrome' },52 wdioReporter53 )54 await adapter.run()55 adapter.jrunner.jasmine.Spec.prototype.addExpectationResult('foobar')56 expect(config.jasmineNodeOpts.expectationResultHandler).toBeCalledWith('foobar');57})58test('get data from beforeAll hook', async () => {59 const adapter = new JasmineAdapter(60 '0-2',61 {},62 ['/foo/bar.test.js'],63 { browserName: 'chrome' },64 wdioReporter65 )66 await adapter.run()67 expect(adapter.lastSpec).toBeUndefined()68 adapter.jrunner.jasmine.Suite.prototype.beforeAll.call({69 result: 'some result'70 }, 'foobar')71 expect(adapter.lastSpec).toBe('some result')72 expect(adapter.jrunner.beforeAllHook).toBeCalledWith('foobar')73})74test('get data from execute hook', async () => {75 const adapter = new JasmineAdapter(76 '0-2',77 {},78 ['/foo/bar.test.js'],79 { browserName: 'chrome' },80 wdioReporter81 )82 await adapter.run()83 expect(adapter.lastTest).toBeUndefined()84 adapter.jrunner.jasmine.Spec.prototype.execute.call({85 result: {86 text: 'some result'87 }88 }, 'barfoo')89 expect(adapter.lastTest.text).toBe('some result')90 expect(typeof adapter.lastTest.start).toBe('number')91 expect(adapter.jrunner.executeHook).toBeCalledWith('barfoo')92})93test('customSpecFilter', () => {94 const specMock = {95 getFullName: () => 'my test @smoke',96 pend: jest.fn()97 }98 const config = {99 jasmineNodeOpts: { grepMatch: '@smoke' }100 }101 const adapter = new JasmineAdapter(102 '0-2',103 config,104 ['/foo/bar.test.js'],105 { browserName: 'chrome' },106 wdioReporter107 )108 expect(adapter.customSpecFilter(specMock)).toBe(true)109 expect(specMock.pend.mock.calls).toHaveLength(0)110 adapter.jasmineNodeOpts.grep = '@random'111 expect(adapter.customSpecFilter(specMock)).toBe(true)112 expect(specMock.pend.mock.calls).toHaveLength(1)113 adapter.jasmineNodeOpts.invertGrep = true114 expect(adapter.customSpecFilter(specMock)).toBe(true)115 expect(specMock.pend.mock.calls).toHaveLength(1)116 adapter.jasmineNodeOpts.grep = '@smoke'117 adapter.jasmineNodeOpts.invertGrep = true118 expect(adapter.customSpecFilter(specMock)).toBe(true)119 expect(specMock.pend.mock.calls).toHaveLength(2)120})121test('wrapHook if successful', async () => {122 executeHooksWithArgs.mockClear()123 const config = { beforeAll: 'somehook' }124 const adapter = new JasmineAdapter(125 '0-2',126 config,127 ['/foo/bar.test.js'],128 { browserName: 'chrome' },129 wdioReporter130 )131 const wrappedHook = adapter.wrapHook('beforeAll')132 const doneCallback = jest.fn()133 executeHooksWithArgs.mockImplementation((...args) => Promise.resolve(args))134 await wrappedHook(doneCallback)135 expect(executeHooksWithArgs.mock.calls[0][0]).toBe('somehook')136 expect(executeHooksWithArgs.mock.calls[0][1].type).toBe('beforeAll')137 expect(doneCallback.mock.calls).toHaveLength(1)138})139test('wrapHook if failing', async () => {140 executeHooksWithArgs.mockClear()141 const config = { beforeAll: 'somehook' }142 const adapter = new JasmineAdapter(143 '0-2',144 config,145 ['/foo/bar.test.js'],146 { browserName: 'chrome' },147 wdioReporter148 )149 const wrappedHook = adapter.wrapHook('beforeAll')150 const doneCallback = jest.fn()151 executeHooksWithArgs.mockImplementation(() => Promise.reject(new Error('uuuups')))152 await wrappedHook(doneCallback)153 expect(executeHooksWithArgs.mock.calls[0][0]).toBe('somehook')154 expect(executeHooksWithArgs.mock.calls[0][1].type).toBe('beforeAll')155 expect(doneCallback.mock.calls).toHaveLength(1)156 expect(logger().info.mock.calls[0][0].startsWith('Error in beforeAll hook: uuuups')).toBe(true);157})158test('formatMessage', () => {159 const adapter = new JasmineAdapter(160 '0-2',161 {},162 ['/foo/bar.test.js'],163 { browserName: 'chrome' },164 wdioReporter165 )166 let message = adapter.formatMessage({ type: 'foobar' })167 expect(message).toEqual({ type: 'foobar' })168 message = adapter.formatMessage({169 type: 'foobar',170 err: new Error('foobar')171 })172 expect(message.err.message).toBe('foobar')173 adapter.lastSpec = { description: 'lasttestdesc' }174 message = adapter.formatMessage({175 type: 'afterTest',176 payload: {177 id: 'spec1',178 description: 'foodesc',179 fullName: 'foo',180 file: '/some/test.js',181 failedExpectations: [],182 start: Date.now() - 2000183 }184 })185 expect(message.duration).toBeGreaterThan(1999)186 expect(message.duration).toBeLessThan(2005)187 expect(message.passed).toBe(true)188 expect(message.parent).toBe('lasttestdesc')189 expect(message.title).toBe('foodesc')190 message = adapter.formatMessage({191 type: 'afterTest',192 payload: {193 description: 'foodesc',194 fullName: 'foo',195 file: '/some/test.js',196 start: Date.now() - 2000,197 duration: 123198 }199 })200 expect(message.duration).toBe(123)201})202test('expectationResultHandler', () => {203 const origHandler = jest.fn()204 const config = { jasmineNodeOpts: { expectationResultHandler: jest.fn() } }205 const adapter = new JasmineAdapter(206 '0-2',207 config,208 ['/foo/bar.test.js'],209 { browserName: 'chrome' },210 wdioReporter211 )212 const resultHandler = adapter.expectationResultHandler(origHandler)213 resultHandler(true, 'foobar')214 expect(config.jasmineNodeOpts.expectationResultHandler).toBeCalledWith(true, 'foobar')215 expect(origHandler).toBeCalledWith(true, 'foobar')216})217test('expectationResultHandler failing', () => {218 const origHandler = jest.fn()219 const config = { jasmineNodeOpts: { expectationResultHandler: () => {220 throw new Error('uuups')221 } } }222 const adapter = new JasmineAdapter(223 '0-2',224 config,225 ['/foo/bar.test.js'],226 { browserName: 'chrome' },227 wdioReporter228 )229 const resultHandler = adapter.expectationResultHandler(origHandler)230 resultHandler(true, 'foobar')231 expect(origHandler)232 .toBeCalledWith(false, { passed: false, message: 'expectationResultHandlerError: uuups' })233})234test('expectationResultHandler failing with failing test', () => {235 const origHandler = jest.fn()236 const config = { jasmineNodeOpts: { expectationResultHandler: () => {237 throw new Error('uuups')238 } } }239 const adapter = new JasmineAdapter(240 '0-2',241 config,242 ['/foo/bar.test.js'],243 { browserName: 'chrome' },244 wdioReporter245 )246 const resultHandler = adapter.expectationResultHandler(origHandler)247 resultHandler(false, 'foobar')248 expect(origHandler).toBeCalledWith(false, 'foobar')249})250test('prepareMessage', () => {251 const adapter = new JasmineAdapter(252 '0-2',253 {},254 ['/foo/bar.test.js'],255 { browserName: 'chrome' },256 wdioReporter257 )258 adapter.formatMessage = (params) => params259 adapter.jrunner.specFiles = ['/some/path.test.js']260 adapter.lastSpec = { foo: 'bar' }261 adapter.lastTest = { bar: 'foo' }262 const msg = adapter.prepareMessage('beforeSuite')263 expect(msg.type).toBe('beforeSuite')264 expect(msg.payload.file).toBe('/some/path.test.js')265 expect(msg.payload.foo).toBe('bar')266 const msgSpec = adapter.prepareMessage('beforeTest')267 expect(msgSpec.type).toBe('beforeTest')268 expect(msgSpec.payload.file).toBe('/some/path.test.js')269 expect(msgSpec.payload.bar).toBe('foo')270})271afterEach(() => {272 runTestInFiberContext.mockClear()273 executeHooksWithArgs.mockClear()...

Full Screen

Full Screen

wdio-sync.spec.js

Source:wdio-sync.spec.js Github

copy

Full Screen

...14 hook2 = sinon.spy()15 hook3 = sinon.spy()16 })17 it('should execute all hooks with same parameters', () => {18 executeHooksWithArgs([hook1, hook2, hook3], [1, 2, 3, 4])19 hook1.calledWith(1, 2, 3, 4).should.be.true()20 hook2.calledWith(1, 2, 3, 4).should.be.true()21 hook3.calledWith(1, 2, 3, 4).should.be.true()22 })23 it('should respect promises', async () => {24 let hook = () => {25 return new Promise((resolve) => {26 setTimeout(() => resolve('done'), 1000)27 })28 }29 let start = new Date().getTime()30 let result = await executeHooksWithArgs([hook])31 let duration = new Date().getTime() - start32 duration.should.be.greaterThan(990)33 result[0].should.be.equal('done')34 })35 it('should allow func parameter', async () => {36 let hook = () => 'done'37 let result = await executeHooksWithArgs(hook)38 result[0].should.be.equal('done')39 })40 describe('error handling', () => {41 describe('sync', () => {42 before(() => {43 global.browser = { options: { sync: true } }44 })45 it('should skip if hook returns rejected promise', async () => {46 let hookReject = () => new Promise((resolve, reject) => reject(new Error('buu')))47 const res = await executeHooksWithArgs(hookReject)48 res[0].should.be.an.instanceOf(Error)49 res[0].message.should.be.equal('buu')50 })51 it('should skip immediate errors in hooks', async () => {52 let hookThrows = () => { throw new Error('buu') }53 const res = await executeHooksWithArgs(hookThrows)54 res[0].should.be.an.instanceOf(Error)55 res[0].message.should.be.equal('buu')56 })57 after(() => {58 delete global.browser59 })60 })61 describe('async', () => {62 it('should skip if hook returns rejected promise', async () => {63 let hookReject = () => new Promise((resolve, reject) => reject(new Error('buu')))64 const res = await executeHooksWithArgs(hookReject)65 res[0].should.be.an.instanceOf(Error)66 res[0].message.should.be.equal('buu')67 })68 it('should skip immediate errors in hooks', async () => {69 let hookThrows = () => { throw new Error('buu') }70 const res = await executeHooksWithArgs(hookThrows)71 res[0].should.be.an.instanceOf(Error)72 res[0].message.should.be.equal('buu')73 })74 })75 })76 after(() => {77 /**78 * reset globals79 */80 WDIOSyncRewire.__Rewire__('commandIsRunning', false)81 WDIOSyncRewire.__Rewire__('forcePromises', false)82 })83 })84 describe('wdioSync', () => {...

Full Screen

Full Screen

testFnWrapper.js

Source:testFnWrapper.js Github

copy

Full Screen

...35 attempts: 0,36 limit: repeatTest37 };38 const beforeArgs = mochaJasmineCompatibility(beforeFnArgs(this), this);39 await (0, _errorHandler.logHookError)(`Before${type}`, (await executeHooksWithArgs(beforeFn, beforeArgs)), cid);40 let promise;41 let result;42 let error;43 if ((0, _utils.isFunctionAsync)(specFn) || !runSync) {44 promise = executeAsync.call(this, specFn, retries, specFnArgs);45 } else {46 promise = new Promise(runSync.call(this, specFn, retries, specFnArgs));47 }48 const testStart = Date.now();49 try {50 result = await promise;51 } catch (err) {52 error = err;53 }54 const duration = Date.now() - testStart;55 let afterArgs = afterFnArgs(this);56 if (!error && afterArgs[0] && afterArgs[0].failedExpectations && afterArgs[0].failedExpectations.length) {57 error = afterArgs[0].failedExpectations[0];58 }59 afterArgs.push({60 retries,61 error,62 result,63 duration,64 passed: !error65 });66 afterArgs = mochaJasmineCompatibility(afterArgs, this);67 afterArgs = mochaJasmineResultCompatibility(afterArgs, error, duration);68 afterArgs = cucumberCompatibility(afterArgs);69 await (0, _errorHandler.logHookError)(`After${type}`, (await executeHooksWithArgs(afterFn, [...afterArgs])), cid);70 if (error) {71 throw error;72 }73 return result;74};75exports.testFrameworkFnWrapper = testFrameworkFnWrapper;76const mochaJasmineCompatibility = (hookArgs, {77 test = {}78} = {}) => {79 let args = hookArgs;80 if (hookArgs.length < 4 && hookArgs[0] && typeof hookArgs[0] === 'object') {81 if (!args[0].title) {82 args[0].title = args[0].description;83 }...

Full Screen

Full Screen

testFnWrapper-async.test.js

Source:testFnWrapper-async.test.js Github

copy

Full Screen

1import * as shim from '../../src/shim'2import { testFnWrapper } from '../../src/test-framework/testFnWrapper'3jest.mock('../../src/shim', () => ({4 executeHooksWithArgs: jest.fn(),5 executeAsync: async (fn, { limit, attempts }, args = []) => fn('async', limit, attempts, ...args),6 runSync: null,7}))8const executeHooksWithArgs = shim.executeHooksWithArgs9describe('testFnWrapper', () => {10 const origFn = (mode, limit, attempts, arg) => `${mode}: Foo${arg} ${limit} ${attempts}`11 const buildArgs = (specFn, retries, beforeFnArgs, afterFnArgs) => [12 'Foo',13 { specFn, specFnArgs: ['Bar'] },14 { beforeFn: 'beforeFn', beforeFnArgs },15 { afterFn: 'afterFn', afterFnArgs },16 '0-9',17 retries18 ]19 it('should run fn in async mode if not runSync', async () => {20 const args = buildArgs(origFn, undefined, () => [], () => [])21 const result = await testFnWrapper(...args)22 expect(result).toBe('async: FooBar 0 0')23 expect(executeHooksWithArgs).toBeCalledTimes(2)24 expect(executeHooksWithArgs).toBeCalledWith('beforeFoo', 'beforeFn', [])25 expect(executeHooksWithArgs).toBeCalledWith('afterFoo', 'afterFn', [{26 duration: expect.any(Number),27 error: undefined,28 result: 'async: FooBar 0 0',29 passed: true,30 retries: {31 limit: 0,32 attempts: 033 }34 }])35 })36 it('should run fn in async mode if specFn is async', async () => {37 const args = buildArgs(async (...args) => origFn(...args), 11, () => ['beforeFnArgs'], () => ['afterFnArgs'])38 const result = await testFnWrapper(...args)39 expect(result).toBe('async: FooBar 11 0')40 expect(executeHooksWithArgs).toBeCalledTimes(2)41 expect(executeHooksWithArgs).toBeCalledWith('beforeFoo', 'beforeFn', ['beforeFnArgs'])42 expect(executeHooksWithArgs).toBeCalledWith('afterFoo', 'afterFn', ['afterFnArgs', {43 duration: expect.any(Number),44 error: undefined,45 result: 'async: FooBar 11 0',46 passed: true,47 retries: {48 limit: 11,49 attempts: 050 }51 }])52 })53 it('should throw on error', async () => {54 let expectedError55 const args = buildArgs((mode, repeatTest, arg) => {56 expectedError = new Error(`${mode}: Foo${arg} ${repeatTest}`)57 throw expectedError58 }, undefined, () => ['beforeFnArgs'], () => ['afterFnArgs'])59 let error60 try {61 await testFnWrapper(...args)62 } catch (err) {63 error = err64 }65 expect(error).toBe(expectedError)66 expect(executeHooksWithArgs).toBeCalledTimes(2)67 expect(executeHooksWithArgs).toBeCalledWith('beforeFoo', 'beforeFn', ['beforeFnArgs'])68 expect(executeHooksWithArgs).toBeCalledWith('afterFoo', 'afterFn', ['afterFnArgs', {69 duration: expect.any(Number),70 error: expectedError,71 result: undefined,72 passed: false,73 retries: {74 limit: 0,75 attempts: 076 }77 }])78 })79 afterEach(() => {80 executeHooksWithArgs.mockClear()81 })...

Full Screen

Full Screen

shim.js

Source:shim.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.runSync = exports.executeAsync = exports.executeSync = exports.hasWdioSyncSupport = exports.wrapCommand = exports.runFnInFiberContext = exports.executeHooksWithArgs = void 0;6var _logger = _interopRequireDefault(require("@wdio/logger"));7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }8const log = (0, _logger.default)('@wdio/utils:shim');9let hasWdioSyncSupport = false;10exports.hasWdioSyncSupport = hasWdioSyncSupport;11let runSync = null;12exports.runSync = runSync;13let executeHooksWithArgs = async function executeHooksWithArgsShim(hooks, args) {14 if (!Array.isArray(hooks)) {15 hooks = [hooks];16 }17 if (!Array.isArray(args)) {18 args = [args];19 }20 hooks = hooks.map(hook => new Promise(resolve => {21 let result;22 try {23 result = hook.apply(null, args);24 } catch (e) {25 log.error(e.stack);26 return resolve(e);27 }28 if (result && typeof result.then === 'function') {29 return result.then(resolve, e => {30 log.error(e.stack);31 resolve(e);32 });33 }34 resolve(result);35 }));36 return Promise.all(hooks);37};38exports.executeHooksWithArgs = executeHooksWithArgs;39let runFnInFiberContext = function (fn) {40 return function (...args) {41 return Promise.resolve(fn.apply(this, args));42 };43};44exports.runFnInFiberContext = runFnInFiberContext;45let wrapCommand = async function (commandName, fn, ...args) {46 await executeHooksWithArgs.call(this, this.options.beforeCommand, [commandName, args]);47 let commandResult;48 let commandError;49 try {50 commandResult = await fn.apply(this, args);51 } catch (err) {52 commandError = err;53 }54 await executeHooksWithArgs.call(this, this.options.afterCommand, [commandName, args, commandResult, commandError]);55 if (commandError) {56 throw commandError;57 }58 return commandResult;59};60exports.wrapCommand = wrapCommand;61let executeSync = async function (fn, retries, args = []) {62 this.retries = retries.attempts;63 try {64 let res = fn.apply(this, args);65 if (res instanceof Promise) {66 return await res;67 }68 return res;69 } catch (e) {70 if (retries.limit > retries.attempts) {71 retries.attempts++;72 return await executeSync.call(this, fn, retries, args);73 }74 return Promise.reject(e);75 }76};77exports.executeSync = executeSync;78const executeAsync = async function (fn, retries, args = []) {79 this.retries = retries.attempts;80 try {81 return await fn.apply(this, args);82 } catch (e) {83 if (retries.limit > retries.attempts) {84 retries.attempts++;85 return await executeAsync.call(this, fn, retries, args);86 }87 throw e;88 }89};90exports.executeAsync = executeAsync;91try {92 const wdioSync = require('@wdio/sync');93 exports.hasWdioSyncSupport = hasWdioSyncSupport = true;94 exports.runFnInFiberContext = runFnInFiberContext = wdioSync.runFnInFiberContext;95 exports.wrapCommand = wrapCommand = wdioSync.wrapCommand;96 exports.executeHooksWithArgs = executeHooksWithArgs = wdioSync.executeHooksWithArgs;97 exports.executeSync = executeSync = wdioSync.executeSync;98 exports.runSync = runSync = wdioSync.runSync;...

Full Screen

Full Screen

testFnWrapper-sync.test.js

Source:testFnWrapper-sync.test.js Github

copy

Full Screen

1import * as shim from '../../src/shim'2import { testFnWrapper } from '../../src/test-framework/testFnWrapper'3jest.mock('../../src/shim', () => ({4 executeHooksWithArgs: jest.fn(),5 runSync: (fn, { attempts, limit }, args = []) => async (resolve, reject) => {6 try {7 return resolve(await fn('@wdio/sync', attempts, limit, ...args))8 } catch (err) {9 reject(err)10 }11 },12 executeAsync: null,13}))14const executeHooksWithArgs = shim.executeHooksWithArgs15describe('testFnWrapper', () => {16 const origFn = (mode, attempts, limit, arg) => `${mode}: Foo${arg} ${attempts} ${limit}`17 const buildArgs = (specFn, retries, beforeFnArgs, afterFnArgs) => [18 'Foo',19 { specFn, specFnArgs: ['Bar'] },20 { beforeFn: 'beforeFn', beforeFnArgs },21 { afterFn: 'afterFn', afterFnArgs },22 '0-9',23 retries24 ]25 it('should run fn in sync mode with mocha or jasmine', async () => {26 const args = buildArgs(origFn, undefined, () => ['beforeFnArgs'], () => [{ foo: 'bar', description: 'foo' }, 'context'])27 const result = await testFnWrapper.call({ test: { fullTitle: () => 'full title' } }, ...args)28 expect(result).toBe('@wdio/sync: FooBar 0 0')29 expect(executeHooksWithArgs).toBeCalledTimes(2)30 expect(31 Object.prototype.hasOwnProperty.call(32 executeHooksWithArgs.mock.calls[1][2][2],33 'duration'34 )35 ).toBe(true)36 delete executeHooksWithArgs.mock.calls[1][2][2].duration37 expect(executeHooksWithArgs.mock.calls).toMatchSnapshot()38 })39 it('should propagate jasmine failed expecations as errors', async () => {40 const failedExpectation = {41 matcherName: 'toEqual',42 message: 'Expected true to equal false.',43 stack: 'Error: Expected true to equal false.\n at <Jasmine>\n at UserContext.it',44 passed: false,45 expected: false,46 actual: true47 }48 const args = buildArgs(origFn, undefined, () => ['beforeFnArgs'], () => [{ foo: 'bar', description: 'foo', failedExpectations: [failedExpectation] }, 'context'])49 const error = await testFnWrapper.call({ test: { fullTitle: () => 'full title' } }, ...args).catch((err) => err)50 expect(executeHooksWithArgs.mock.calls[1][1]).toMatchSnapshot()51 expect(error).toMatchSnapshot()52 })53 it('should run fn in sync mode with cucumber', async () => {54 const args = buildArgs(origFn, undefined, () => ['beforeFnArgs'], () => [{ foo: 'bar' }, 2, 3, 4])55 const result = await testFnWrapper(...args)56 expect(result).toBe('@wdio/sync: FooBar 0 0')57 expect(executeHooksWithArgs).toBeCalledTimes(2)58 delete executeHooksWithArgs.mock.calls[1][1][2].duration59 expect(executeHooksWithArgs.mock.calls).toMatchSnapshot()60 })61 afterEach(() => {62 executeHooksWithArgs.mockClear()63 })...

Full Screen

Full Screen

wrapCommand.js

Source:wrapCommand.js Github

copy

Full Screen

...12 /**13 * helper method that runs the command with before/afterCommand hook14 */15 const runCommand = async function (...args) {16 await executeHooksWithArgs(17 this.options.beforeCommand,18 [commandName, args]19 )20 let commandResult21 let commandError22 try {23 commandResult = await fn.apply(this, args)24 } catch (e) {25 commandError = e26 }27 await executeHooksWithArgs(28 this.options.afterCommand,29 [commandName, args, commandResult, commandError]30 )31 if (commandError) {32 throw commandError33 }34 return commandResult35 }36 return function (...args) {37 const future = new Future()38 const result = runCommand.apply(this, args)39 result.then(::future.return, ::future.throw)40 try {41 return future.wait()...

Full Screen

Full Screen

hookRunner.js

Source:hookRunner.js Github

copy

Full Screen

...12 .on('after-scenario', this.handleAfterScenario.bind(this))13 .on('after-feature', this.handleAfterFeature.bind(this))14 }15 handleBeforeFeature (uri, feature) {16 return executeHooksWithArgs(this.config.beforeFeature, feature)17 }18 handleBeforeScenario (uri, feature, scenario) {19 return executeHooksWithArgs(this.config.beforeScenario, scenario)20 }21 handleBeforeStep (uri, feature, scenario, step) {22 return executeHooksWithArgs(this.config.beforeStep, step)23 }24 handleAfterStep (uri, feature, scenario, step, result) {25 return executeHooksWithArgs(this.config.afterStep, {...step, feature: feature.name, scenario: scenario.name, status: result.status}, result)26 }27 handleAfterScenario (uri, feature, scenario) {28 return executeHooksWithArgs(this.config.afterScenario, scenario)29 }30 handleAfterFeature (uri, feature) {31 return executeHooksWithArgs(this.config.afterFeature, feature)32 }33}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .title(function(err, res) {9 console.log('Title was: ' + res.value);10 })11 .end();12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17var client = webdriverio.remote(options);18 .init()19 .title(function(err, res) {20 console.log('Title was: ' + res.value);21 })22 .end();23var webdriverio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28var client = webdriverio.remote(options);29 .init()30 .title(function(err, res) {31 console.log('Title was: ' + res.value);32 })33 .end();34var webdriverio = require('webdriverio');35var options = {36 desiredCapabilities: {37 }38};39var client = webdriverio.remote(options);40 .init()

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12exports.config = {13 mochaOpts: {14 },15 before: function(capabilities, specs) {16 console.log('before');17 },18 beforeSession: function(config, capabilities, specs) {19 console.log('beforeSession');20 },21 beforeSuite: function(suite) {22 console.log('beforeSuite');23 },24 beforeHook: function() {25 console.log('beforeHook');26 },27 beforeTest: function(test) {28 console.log('beforeTest');29 },30 beforeCommand: function(commandName, args) {31 console.log('beforeCommand');32 },33 afterCommand: function(commandName, args, result, error) {34 console.log('afterCommand');35 },36 afterTest: function(test) {37 console.log('afterTest');38 },39 afterHook: function(currentTest, context, { error, result, duration, passed, retries }) {40 console.log('afterHook');41 },42 afterSuite: function(suite) {43 console.log('afterSuite');44 },45 afterSession: function(config, capabilities, specs) {46 console.log('afterSession');47 },48 after: function(capabilities, specs) {49 console.log('after');50 },51 onComplete: function(exitCode, config, capabilities, results) {52 console.log('onComplete');53 },54 onReload: function(oldSessionId, newSessionId) {55 console.log('onReload');56 }57};58exports.config = {59 mochaOpts: {60 },61 before: function(capabilities, specs) {62 console.log('before');63 },64 beforeSession: function(config, capabilities, specs) {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 }6 })7 await browser.executeHooksWithArgs('myHook', 1, 2, 3)8})()9exports.config = {10 hooks: {11 myHook: (a, b, c) => {12 }13 }14}15const { remote } = require('webdriverio');16(async () => {17 const browser = await remote({18 capabilities: {19 }20 })21 await browser.executeAsyncScript(function (done) {22 setTimeout(function () {23 done('foobar')24 }, 1000)25 }).then((result) => {26 })27})()28const { remote } = require('webdriverio');29(async () => {30 const browser = await remote({31 capabilities: {32 }33 })34 await browser.execute(function (a, b) {35 }, 1, 2).then((result) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const wdio = require('webdriverio');3const options = {4 desiredCapabilities: {5 }6};7const client = webdriverio.remote(options);8client.init().then(() => {9 client.executeHooksWithArgs('beforeTest', { title: 'test' })10 .then(() => {11 return client.execute('mobile: shell', {12 });13 })14 .then(() => {15 return client.executeHooksWithArgs('before', { title: 'test' });16 })17 .then(() => {18 return client.executeHooksWithArgs('after', { title: 'test' });19 })20 .then(() => {21 return client.executeHooksWithArgs('afterTest', { title: 'test' });22 })23 .then(() => {24 return client.end();25 });26});

Full Screen

Using AI Code Generation

copy

Full Screen

1const executeHooksWithArgs = require('webdriverio/build/runner').executeHooksWithArgs;2const config = require('./wdio.conf.js').config;3const wdio = require('webdriverio');4async function run() {5 const browser = await wdio.remote(config);6 await executeHooksWithArgs('before', config, [browser.capabilities, config.specs, browser]);7 await executeHooksWithArgs('after', config, [browser.capabilities, config.specs, browser]);8}9run();

Full Screen

WebdriverIO Tutorial

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.

Chapters

  1. 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.

  2. Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.

  3. 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?

  4. 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.

  5. 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.

  6. 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.

  7. Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.

  8. 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.

  9. JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.

  10. 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.

Run Webdriverio 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