How to use afterScenario method in taiko

Best JavaScript code snippet using taiko

service.test.ts

Source:service.test.ts Github

copy

Full Screen

...330 it('should increment failure reasons on non-passing statuses (strict mode off)', () => {331 service = new BrowserstackService({}, [] as any,332 { user: 'foo', key: 'bar', cucumberOpts: { strict: false } } as any)333 expect(service['_failReasons']).toEqual([])334 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'SKIPPED' } })335 expect(service['_failReasons']).toEqual([])336 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'FAILED', message: 'I am Error, most likely' } })337 expect(service['_failReasons']).toEqual(['I am Error, most likely'])338 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'SKIPPED' } })339 expect(service['_failReasons']).toEqual(['I am Error, most likely'])340 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'FAILED', message: 'I too am Error' } })341 expect(service['_failReasons']).toEqual(['I am Error, most likely', 'I too am Error'])342 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'UNDEFINED', message: 'Step XYZ is undefined' } })343 expect(service['_failReasons']).toEqual(['I am Error, most likely', 'I too am Error', 'Step XYZ is undefined'])344 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'AMBIGUOUS', message: 'Step XYZ2 is ambiguous' } })345 expect(service['_failReasons']).toEqual(346 ['I am Error, most likely',347 'I too am Error',348 'Step XYZ is undefined',349 'Step XYZ2 is ambiguous'])350 service.afterScenario({ pickle: { name: 'Can do something' }, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'PENDING' } })351 expect(service['_failReasons']).toEqual(352 ['I am Error, most likely',353 'I too am Error',354 'Step XYZ is undefined',355 'Step XYZ2 is ambiguous'])356 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'SKIPPED' } })357 expect(service['_failReasons']).toEqual([358 'I am Error, most likely',359 'I too am Error',360 'Step XYZ is undefined',361 'Step XYZ2 is ambiguous'])362 })363 it('should increment failure reasons on non-passing statuses (strict mode on)', () => {364 service = new BrowserstackService({}, [] as any,365 { user: 'foo', key: 'bar', cucumberOpts: { strict: true }, capabilities: {} })366 expect(service['_failReasons']).toEqual([])367 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'SKIPPED' } })368 expect(service['_failReasons']).toEqual([])369 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, message: 'I am Error, most likely', status: 'FAILED' } })370 expect(service['_failReasons']).toEqual(['I am Error, most likely'])371 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'SKIPPED' } })372 expect(service['_failReasons']).toEqual(['I am Error, most likely'])373 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'FAILED', message: 'I too am Error' } })374 expect(service['_failReasons']).toEqual(['I am Error, most likely', 'I too am Error'])375 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'UNDEFINED', message: 'Step XYZ is undefined' } })376 expect(service['_failReasons']).toEqual(['I am Error, most likely', 'I too am Error', 'Step XYZ is undefined'])377 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'AMBIGUOUS', message: 'Step XYZ2 is ambiguous' } })378 expect(service['_failReasons']).toEqual(379 ['I am Error, most likely',380 'I too am Error',381 'Step XYZ is undefined',382 'Step XYZ2 is ambiguous'])383 service.afterScenario({ pickle: { name: 'Can do something' }, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'PENDING' } })384 expect(service['_failReasons']).toEqual(385 ['I am Error, most likely',386 'I too am Error',387 'Step XYZ is undefined',388 'Step XYZ2 is ambiguous',389 'Some steps/hooks are pending for scenario "Can do something"'])390 service.afterScenario({ pickle: {}, result: { duration: { seconds: 0, nanos: 1000000 }, willBeRetried: false, status: 'SKIPPED' } })391 expect(service['_failReasons']).toEqual([392 'I am Error, most likely',393 'I too am Error',394 'Step XYZ is undefined',395 'Step XYZ2 is ambiguous',396 'Some steps/hooks are pending for scenario "Can do something"'])397 })398})399describe('after', () => {400 it('should call _update when session has no errors (exit code 0)', async () => {401 const updateSpy = jest.spyOn(service, '_update')402 await service.before(service['_config'], [], browser)403 service['_failReasons'] = []404 service['_fullTitle'] = 'foo - bar'405 await service.after(0)406 expect(updateSpy).toHaveBeenCalledWith(service['_browser']?.sessionId,407 {408 status: 'passed',409 name: 'foo - bar',410 reason: undefined411 })412 expect(got.put).toHaveBeenCalledWith(413 'https://api.browserstack.com/automate/sessions/session123.json',414 { json: {415 status: 'passed',416 name: 'foo - bar',417 reason: undefined418 }, username: 'foo', password: 'bar' })419 })420 it('should call _update when session has errors (exit code 1)', async () => {421 const updateSpy = jest.spyOn(service, '_update')422 await service.before(service['_config'], [], browser)423 service['_fullTitle'] = 'foo - bar'424 service['_failReasons'] = ['I am failure']425 await service.after(1)426 expect(updateSpy).toHaveBeenCalledWith(service['_browser']?.sessionId,427 {428 status: 'failed',429 name: 'foo - bar',430 reason: 'I am failure'431 })432 expect(got.put).toHaveBeenCalledWith(433 'https://api.browserstack.com/automate/sessions/session123.json',434 { json: {435 status: 'failed',436 name: 'foo - bar',437 reason: 'I am failure'438 }, username: 'foo', password: 'bar' })439 })440 describe('Cucumber only', function () {441 it('should call _update with status "failed" if strict mode is "on" and all tests are pending', async () => {442 service = new BrowserstackService({}, [] as any,443 { user: 'foo', key: 'bar', cucumberOpts: { strict: true } } as any)444 const updateSpy = jest.spyOn(service, '_update')445 await service.before(service['_config'], [], browser)446 await service.beforeFeature(null, { name: 'Feature1' })447 await service.afterScenario({ pickle: { name: 'Can do something but pending 1' }, result: { status: 'PENDING' } })448 await service.afterScenario({ pickle: { name: 'Can do something but pending 2' }, result: { status: 'PENDING' } })449 await service.afterScenario({ pickle: { name: 'Can do something but pending 3' }, result: { status: 'PENDING' } })450 await service.after(1)451 expect(updateSpy).toHaveBeenLastCalledWith(service['_browser']?.sessionId, {452 name: 'Feature1',453 reason: 'Some steps/hooks are pending for scenario "Can do something but pending 1"' + '\n' +454 'Some steps/hooks are pending for scenario "Can do something but pending 2"' + '\n' +455 'Some steps/hooks are pending for scenario "Can do something but pending 3"',456 status: 'failed',457 })458 expect(updateSpy).toHaveBeenCalled()459 })460 it('should call _update with status "passed" when strict mode is "off" and only passed and pending tests ran', async () => {461 service = new BrowserstackService({}, [] as any,462 { user: 'foo', key: 'bar', cucumberOpts: { strict: false } } as any)463 const updateSpy = jest.spyOn(service, '_update')464 await service.before(service['_config'], [], browser)465 await service.beforeFeature(null, { name: 'Feature1' })466 await service.afterScenario({ pickle: { name: 'Can do something' }, result: { status: 'PASSED' } })467 await service.afterScenario({ pickle: { name: 'Can do something' }, result: { status: 'PENDING' } })468 await service.afterScenario({ pickle: { name: 'Can do something' }, result: { status: 'PASSED' } })469 await service.after(0)470 expect(updateSpy).toHaveBeenCalled()471 expect(updateSpy).toHaveBeenLastCalledWith(service['_browser']?.sessionId, {472 name: 'Feature1',473 reason: undefined,474 status: 'passed',475 })476 })477 it('should call _update with status is "failed" when strict mode is "on" and only passed and pending tests ran', async () => {478 service = new BrowserstackService({}, [] as any,479 { user: 'foo', key: 'bar', cucumberOpts: { strict: true } } as any)480 const updateSpy = jest.spyOn(service, '_update')481 await service.before(service['_config'], [], browser)482 await service.beforeFeature(null, { name: 'Feature1' })483 await service.afterScenario({ pickle: { name: 'Can do something 1' }, result: { status: 'PASSED' } })484 await service.afterScenario({ pickle: { name: 'Can do something but pending' }, result: { status: 'PENDING' } })485 await service.afterScenario({ pickle: { name: 'Can do something 2' }, result: { status: 'PASSED' } })486 await service.after(1)487 expect(updateSpy).toHaveBeenCalled()488 expect(updateSpy).toHaveBeenCalledWith(service['_browser']?.sessionId, {489 name: 'Feature1',490 reason: 'Some steps/hooks are pending for scenario "Can do something but pending"',491 status: 'failed',492 })493 })494 it('should call _update with status "passed" when all tests are skipped', async () => {495 const updateSpy = jest.spyOn(service, '_update')496 await service.before(service['_config'], [], browser)497 await service.beforeFeature(null, { name: 'Feature1' })498 await service.afterScenario({ pickle: { name: 'Can do something skipped 1' }, result: { status: 'SKIPPED' } })499 await service.afterScenario({ pickle: { name: 'Can do something skipped 2' }, result: { status: 'SKIPPED' } })500 await service.afterScenario({ pickle: { name: 'Can do something skipped 3' }, result: { status: 'SKIPPED' } })501 await service.after(0)502 expect(updateSpy).toHaveBeenCalledWith(service['_browser']?.sessionId, {503 name: 'Feature1',504 reason: undefined,505 status: 'passed',506 })507 })508 it('should call _update with status "failed" when strict mode is "on" and only failed and pending tests ran', async () => {509 service = new BrowserstackService({}, [] as any,510 { user: 'foo', key: 'bar', cucumberOpts: { strict: true } } as any)511 const updateSpy = jest.spyOn(service, '_update')512 const afterSpy = jest.spyOn(service, 'after')513 await service.beforeSession(service['_config'] as any)514 await service.before(service['_config'], [], browser)515 await service.beforeFeature(null, { name: 'Feature1' })516 expect(updateSpy).toHaveBeenCalledWith(service['_browser']?.sessionId, {517 name: 'Feature1'518 })519 await service.afterScenario({ pickle: { name: 'Can do something failed 1' }, result: { message: 'I am error, hear me roar', status: 'FAILED' } })520 await service.afterScenario({ pickle: { name: 'Can do something but pending 2' }, result: { status: 'PENDING' } })521 await service.afterScenario({ pickle: { name: 'Can do something but passed 3' }, result: { status: 'SKIPPED' } })522 await service.after(1)523 expect(updateSpy).toHaveBeenCalledTimes(2)524 expect(updateSpy).toHaveBeenLastCalledWith(525 service['_browser']?.sessionId, {526 name: 'Feature1',527 reason:528 'I am error, hear me roar' +529 '\n' +530 'Some steps/hooks are pending for scenario "Can do something but pending 2"',531 status: 'failed',532 })533 expect(afterSpy).toHaveBeenCalledTimes(1)534 })535 it('should call _update with status "failed" when strict mode is "off" and only failed and pending tests ran', async () => {536 const updateSpy = jest.spyOn(service, '_update')537 await service.beforeSession(service['_config'] as any)538 await service.before(service['_config'], [], browser)539 await service.beforeFeature(null, { name: 'Feature1' })540 expect(updateSpy).toHaveBeenCalledWith(service['_browser']?.sessionId, {541 name: 'Feature1'542 })543 await service.afterScenario({ pickle: { name: 'Can do something failed 1' }, result: { message: 'I am error, hear me roar', status: 'FAILED' } })544 await service.afterScenario({ pickle: { name: 'Can do something but pending 2' }, result: { status: 'PENDING' } })545 await service.afterScenario({ pickle: { name: 'Can do something but passed 3' }, result: { status: 'SKIPPED' } })546 await service.after(1)547 expect(updateSpy).toHaveBeenCalledTimes(2)548 expect(updateSpy).toHaveBeenLastCalledWith(549 service['_browser']?.sessionId, {550 name: 'Feature1',551 reason: 'I am error, hear me roar',552 status: 'failed',553 }554 )555 })556 describe('preferScenarioName', () => {557 describe('enabled', () => {558 [559 { status: 'FAILED', body: {560 name: 'Feature1',561 reason: 'Unknown Error',562 status: 'failed',563 } },564 { status: 'SKIPPED', body: {565 name: 'Can do something single',566 reason: undefined,567 status: 'failed',568 } }569 /*, 5, 4, 0*/570 ].map(({ status, body }) =>571 it(`should call _update /w status failed and name of Scenario when single "${status}" Scenario ran`, async () => {572 service = new BrowserstackService({ preferScenarioName : true }, [] as any,573 { user: 'foo', key: 'bar', cucumberOpts: { strict: false } } as any)574 service.before({}, [], browser)575 const updateSpy = jest.spyOn(service, '_update')576 await service.beforeFeature(null, { name: 'Feature1' })577 await service.afterScenario({ pickle: { name: 'Can do something single' }, result: { status } })578 await service.after(1)579 expect(updateSpy).toHaveBeenLastCalledWith(service['_browser']?.sessionId, body)580 })581 )582 it('should call _update /w status passed and name of Scenario when single "passed" Scenario ran', async () => {583 service = new BrowserstackService({ preferScenarioName : true }, [] as any,584 { user: 'foo', key: 'bar', cucumberOpts: { strict: false } } as any)585 service.before({}, [], browser)586 const updateSpy = jest.spyOn(service, '_update')587 await service.beforeFeature(null, { name: 'Feature1' })588 await service.afterScenario({ pickle: { name: 'Can do something single' }, result: { status: 'SKIPPED' } })589 await service.after(0)590 expect(updateSpy).toHaveBeenLastCalledWith(service['_browser']?.sessionId, {591 name: 'Can do something single',592 reason: undefined,593 status: 'passed',594 })595 })596 })597 describe('disabled', () => {598 ['FAILED', 'AMBIGUOUS', 'UNDEFINED', 'UNKNOWN'].map(status =>599 it(`should call _update /w status failed and name of Feature when single "${status}" Scenario ran`, async () => {600 service = new BrowserstackService({ preferScenarioName : false }, [] as any,601 { user: 'foo', key: 'bar', cucumberOpts: { strict: false } } as any)602 service.before({}, [], browser)603 const updateSpy = jest.spyOn(service, '_update')604 await service.beforeFeature(null, { name: 'Feature1' })605 await service.afterScenario({ pickle: { name: 'Can do something single' }, result: { status } })606 await service.after(1)607 expect(updateSpy).toHaveBeenLastCalledWith(service['_browser']?.sessionId, {608 name: 'Feature1',609 reason: 'Unknown Error',610 status: 'failed',611 })612 })613 )614 it('should call _update /w status passed and name of Feature when single "passed" Scenario ran', async () => {615 service = new BrowserstackService({ preferScenarioName : false }, [] as any,616 { user: 'foo', key: 'bar', cucumberOpts: { strict: false } } as any)617 service.before({}, [], browser)618 const updateSpy = jest.spyOn(service, '_update')619 await service.beforeFeature(null, { name: 'Feature1' })620 await service.afterScenario({621 pickle: { name: 'Can do something single' },622 result: { status: 'PASSED' }623 })624 await service.after(0)625 expect(updateSpy).toHaveBeenLastCalledWith(service['_browser']?.sessionId, {626 name: 'Feature1',627 reason: undefined,628 status: 'passed',629 })630 })631 })632 })633 })634})

Full Screen

Full Screen

runnerTest.js

Source:runnerTest.js Github

copy

Full Screen

1// skipped as it should be deported in the runner test, (bin)2describe.skip('Runner process', function () {3// var run = require('../src/runner');4 var CompositeError = require('../src/error/composite');5 var _ = require('lodash');6 var chai = require('chai');7 var nock = require('nock');8 var fs = require('fs');9 var assert = chai.assert;10 beforeEach(function () {11 nock.cleanAll();12 });13 describe('browserlist filtering', function () {14 it ('should be possible to filter browsers', function (done) {15 setupConsoleResponse();16 run({17 skipCapabilitiesCheck: false,18 browsers: [{19 browserName: "internet explorer",20 version: 921 }, {22 browserName: "chrome",23 version: "latest"24 }]25 }, [{26 run: function (remote, desired, doneCb) {27 assert.deepEqual(desired, {28 browserName: "chrome",29 version: "latest"30 });31 doneCb();32 }33 }], done);34 });35 it('should be possible to bypass browser filtering', function(done) {36 done = _.after(3, done);37 var server = setupConsoleResponse();38 run({39 skipCapabilitiesCheck: true,40 browsers: [{41 browserName: "internet explorer",42 version: 943 }, {44 browserName: "internet explorer",45 version: 846 }]47 }, [{48 run: function (remote, desired, doneCb) {49 done();50 doneCb();51 }52 }], function (err) {53 assert.ok(!err);54 assert.ok(!server.isDone());55 done();56 });57 });58 it('should throw an error if console is not available', function(done) {59 setupConsoleResponse(404);60 run({61 browsers: [{62 browserName: "internet explorer",63 version: 864 }]65 }, [{66 run: function (remote, desired, doneCb) {doneCb();}67 }], function (err) {68 assert.ok(err.message);69 assert.match(err.message, /Could not connect/);70 done();71 });72 });73 it('should throw an error if no requested browser is available', function(done) {74 setupConsoleResponse();75 run({76 browsers: [{77 browserName: "internet explorer",78 version: 979 }]80 }, [{81 run: function (remote, desired, doneCb) {doneCb();}82 }], function (err) {83 assert.ok(err.message);84 assert.match(err.message, /No matching browsers/);85 done();86 });87 });88 });89 describe('lifecycle', function () {90 it('should trigger "after" callback last', function(done) {91 var calls = [];92 setupConsoleResponse();93 run({94 browsers: [{95 browserName: "chrome",96 version: 'latest'97 }],98 afterScenario: function () {99 calls.push("afterScenario");100 },101 afterBrowser: function () {102 calls.push("afterBrowser");103 }104 }, [{105 before: function () {106 calls.push("test.before");107 },108 after: function () {109 calls.push("test.after");110 },111 run: function (remote, desired, doneCb) {112 calls.push("test");113 doneCb();114 }115 }],116 function (err) {117 try {118 assert.ok(!err);119 assert.deepEqual(calls, [120 "test.before",121 "test",122 "test.after",123 "afterScenario",124 "afterBrowser"125 ]);126 } catch(e) {127 return done(e);128 }129 done();130 });131 });132 it('test.before and test.after recieve the desired browser', function(done) {133 setupConsoleResponse();134 run({135 browsers: [{136 browserName: "chrome",137 version: 'latest'138 }]139 }, [{140 before: function (desired) {141 assert.deepEqual(desired, {142 browserName: "chrome",143 version: 'latest'144 });145 },146 after: function (err, desired) {147 assert.deepEqual(desired, {148 browserName: "chrome",149 version: 'latest'150 });151 },152 run: function (remote, desired, doneCb) {153 doneCb();154 }155 }], done);156 });157 it('calls the afterScenario and afterBrowser', function(done) {158 var calls = [];159 setupConsoleResponse();160 run({161 browsers: [{162 browserName: "chrome",163 version: 'latest'164 }],165 afterScenario: function (err, test, desired) {166 assert.deepEqual(desired, {167 browserName: "chrome",168 version: 'latest'169 });170 assert.ok(test.run);171 calls.push("afterScenario");172 },173 afterBrowser: function (err, browser, desired) {174 assert.deepEqual(desired, {175 browserName: "chrome",176 version: 'latest'177 });178 calls.push("afterBrowser");179 }180 }, [{181 before: function () {182 calls.push("test.before");183 },184 after: function () {185 calls.push("test.after");186 },187 run: function (remote, desired, doneCb) {188 calls.push("test");189 doneCb();190 }191 }, {192 before: function () {193 calls.push("test.before");194 },195 after: function () {196 calls.push("test.after");197 },198 run: function (remote, desired, doneCb) {199 calls.push("test");200 doneCb();201 }202 }],203 function (err) {204 assert.ok(!err);205 assert.deepEqual(calls, [206 "test.before",207 "test",208 "test.after",209 "afterScenario",210 "test.before",211 "test",212 "test.after",213 "afterScenario",214 "afterBrowser"215 ]);216 done();217 });218 });219 });220 describe('error catching', function () {221 var message = 'something';222 var message2 = 'something new';223 it('should bubble test error', function (done) {224 setupConsoleResponse();225 run({226 browsers: [{227 browserName: "chrome",228 version: 'latest'229 }],230 after: function (err) {231 done();232 }233 }, [{234 before: function() {235 throw new Error(message);236 },237 run: function () {238 },239 after: function (err) {240 assert.equal(err.message, message);241 }242 }], function () {});243 });244 it('should bubble test.before error', function (done) {245 setupConsoleResponse();246 run({247 browsers: [{248 browserName: "chrome",249 version: 'latest'250 }],251 after: function (err) {252 done();253 }254 }, [{255 before: function() {256 throw new Error(message);257 },258 run: function () {259 },260 after: function (err) {261 assert.equal(err.message, message);262 }263 }], function () { });264 });265 it('should be possible to alter error in test.after', function (done) {266 setupConsoleResponse();267 run({268 browsers: [{269 browserName: "chrome",270 version: 'latest'271 }],272 afterScenario: function (err) {273 assert.equal(err.message, message2);274 }275 }, [{276 before: function() {277 throw new Error(message);278 },279 run: function () {280 },281 after: function(err) {282 throw new Error(message2);283 }284 }], function () {285 done();286 });287 });288 it('should bubble test error to test.after AND afterScenario', function (done) {289 setupConsoleResponse();290 run({291 browsers: [{292 browserName: "chrome",293 version: 'latest'294 }],295 afterScenario: function (err) {296 assert.equal(err.message, message);297 }298 }, [{299 before: function() {300 throw new Error(message);301 },302 run: function () {303 },304 after: function (err) {305 assert.equal(err.message, message);306 }307 }], function () {308 done();309 });310 });311 it('should bubble test error to afterScenario', function (done) {312 setupConsoleResponse();313 run({314 browsers: [{315 browserName: "chrome",316 version: 'latest'317 }],318 afterScenario: function (err) {319 assert.equal(err.message, message);320 }321 }, [{322 before: function() {323 throw new Error(message);324 },325 run: function () {326 }327 }], function () {328 done();329 });330 });331 it('should bubble test error to afterBrowser', function (done) {332 setupConsoleResponse();333 run({334 browsers: [{335 browserName: "chrome",336 version: 'latest'337 }],338 afterBrowser: function (err, browser) {339 assert.instanceOf(err, CompositeError);340 assert.equal(err.message, 'Errors where catched for this browser.');341 err.length = 1;342 assert.equal(err.errors.pop().message, message);343 }344 }, [{345 before: function() { throw new Error(message); },346 run: function () { }347 }], function () {348 done();349 });350 });351 it('should bubble test error to after', function (done) {352 setupConsoleResponse();353 run({354 browsers: [{355 browserName: "chrome",356 version: 'latest'357 }]358 }, [{359 before: function() { },360 run: function () { throw new Error(message); }361 }],362 function (err) {363 assert.equal(err.message, 'Errors were caught for this run.');364 done();365 });366 });367 });368 describe('check test cases can be run through runner', function () {369 var TestCase = require('../src/scenario/testCase');370 it('should be possible to run a TestCase', function(done) {371 var called = false;372 var Case2 = TestCase.extend({373 run: function (remote, desired, cb) {374 setTimeout(function () {375 called = true;376 cb();377 }, 10);378 }379 });380 run({381 skipCapabilitiesCheck: true,382 browsers: [{383 browserName: "chrome",384 version: 'latest'385 }]386 }, [387 new Case2()388 ], function (err) {389 assert.ok(called);390 done();391 });392 });393 });394});395function setupConsoleResponse(statuscode) {396 var html = fs.readFileSync(__dirname + '/../fixtures/html/console.html');397 return nock('http://127.0.0.1:4444')398 .get('/grid/console')399 .reply(statuscode || 200, html);...

Full Screen

Full Screen

HookRegistryTests.ts

Source:HookRegistryTests.ts Github

copy

Full Screen

1import { HookMethod } from '../../src/models/HookMethod';2import hookRegistry from '../../src/models/HookRegistry';3import { HookType } from '../../src/models/HookType';4import { Operator } from '../../src/public/Operator';5describe('HookRegistry', () => {6 // eslint-disable-next-line @typescript-eslint/no-empty-function7 const DUMMY_FUNC = () => { };8 const FILE = 'HookImpl.ts';9 afterEach(() => {10 hookRegistry.clear();11 });12 describe('.add', () => {13 it('should add a given hook', () => {14 hookRegistry.addHook(HookType.BeforeSuite, new HookMethod(DUMMY_FUNC, FILE));15 expect(hookRegistry.get(HookType.BeforeSuite, []).length).toEqual(1);16 });17 });18 describe('.get', () => {19 it('should give empty list if there is not hooks', () => {20 expect(hookRegistry.get(HookType.AfterScenario, [])).toStrictEqual([]);21 });22 it('should give empty list if there is not hooks for given tag', () => {23 hookRegistry.addHook(HookType.AfterScenario, new HookMethod(DUMMY_FUNC, FILE, { tags: ['scenario'] }));24 expect(hookRegistry.get(HookType.AfterScenario, ["spec"])).toStrictEqual([]);25 });26 it('should give hooks for given tag', () => {27 const hook = new HookMethod(DUMMY_FUNC, FILE, { tags: ['scenario'] });28 hookRegistry.addHook(HookType.AfterScenario, hook);29 expect(hookRegistry.get(HookType.AfterScenario, ['scenario'])).toStrictEqual([hook]);30 });31 it('should give hooks for given tag with default operator if not given', () => {32 const hook = new HookMethod(DUMMY_FUNC, FILE, { tags: ['scenario', 'spec'] });33 hookRegistry.addHook(HookType.AfterScenario, hook);34 expect(hookRegistry.get(HookType.AfterScenario, ['scenario'])).toStrictEqual([]);35 });36 it('should give hooks for given tag with given operator', () => {37 const hook = new HookMethod(DUMMY_FUNC, FILE, { tags: ['scenario', 'spec'], operator:Operator.Or });38 hookRegistry.addHook(HookType.AfterScenario, hook);39 expect(hookRegistry.get(HookType.AfterScenario, ['scenario'])).toStrictEqual([hook]);40 });41 it('should give hooks for given all hooks if no tag is given', () => {42 const hook = new HookMethod(DUMMY_FUNC, FILE);43 hookRegistry.addHook(HookType.AfterScenario, hook);44 expect(hookRegistry.get(HookType.AfterScenario, ['spec'])).toStrictEqual([hook]);45 expect(hookRegistry.get(HookType.AfterScenario, [])[0].getMethod()).toEqual(DUMMY_FUNC);46 expect(hookRegistry.get(HookType.AfterScenario, [])[0].getFilePath()).toEqual(FILE);47 });48 });49 describe('.setInstanceForMethodsIn', () => {50 it('shooud set the instance for all methods of a given FILE', () => {51 const FILE_1 = 'HookImpl1.ts';52 hookRegistry.addHook(HookType.BeforeSuite, new HookMethod(DUMMY_FUNC, FILE));53 hookRegistry.addHook(HookType.AfterSuite, new HookMethod(DUMMY_FUNC, FILE_1));54 hookRegistry.setInstanceForMethodsIn(FILE, {});55 expect(hookRegistry.get(HookType.BeforeSuite, [])[0].getInstance()).toBeDefined();56 expect(hookRegistry.get(HookType.AfterSuite, [])[0].getInstance()).toBeDefined();57 });58 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { afterScenario } = require('taiko');2const { openBrowser, closeBrowser } = require('taiko');3const assert = require("assert");4const headless = process.env.headless_chrome.toLowerCase() === 'true';5module.exports = async function () {6 afterScenario(async function () {7 await closeBrowser();8 });9};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, write, click, closeBrowser } = require('taiko');2const assert = require("assert");3const headless = process.env.headless_chrome.toLowerCase() === 'true';4module.exports = function () {5 this.Before(async function () {6 await openBrowser({ headless: headless });7 });8 this.Given(/^I open Google page$/, async function () {9 await goto("google.com");10 await write("Taiko");11 await click("Taiko");12 });13 this.Then(/^the title is "(.*?)"$/, async function (title) {14 assert.equal(title, await title());15 });16 this.After(async function () {17 await closeBrowser();18 });19}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { afterScenario } = require('taiko');2const { openBrowser, closeBrowser } = require('taiko');3const { createHtmlReport } = require('taiko-reporter');4const { setDefaultConfig } = require('taiko-reporter');5setDefaultConfig({6 metadata: {7 }8});9step("Open Browser", async function() {10 await openBrowser();11});12step("Close Browser", async function() {13 await closeBrowser();14});15afterScenario(async function(result) {16 await createHtmlReport();17});18setDefaultConfig({19 metadata: {20 }21});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { afterScenario } = require('taiko');2const { openBrowser, closeBrowser } = require('taiko');3const assert = require("assert");4const { createHtmlReport } = require('taiko-reporter');5afterScenario(async function (scenario) {6 if (scenario.result.status === 'failed') {7 await createHtmlReport();8 }9 await closeBrowser();10});11"scripts": {12 },13 "devDependencies": {14 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { afterScenario } = require('taiko');2afterScenario(async () => {3 await openBrowser();4 await screenshot({ path: 'screenshot.png' });5 await closeBrowser();6});7const { afterScenario } = require('taiko');8afterScenario(async () => {9 await openBrowser();10 await screenshot({ path: 'screenshot.png' });11 await closeBrowser();12});13const { afterScenario } = require('taiko');14afterScenario(async () => {15 await openBrowser();16 await screenshot({ path: 'screenshot.png' });17 await closeBrowser();18});19const { afterScenario } = require('taiko');20afterScenario(async () => {21 await openBrowser();22 await screenshot({ path: 'screenshot.png' });23 await closeBrowser();24});25const { afterScenario } = require('taiko');26afterScenario(async () => {27 await openBrowser();28 await screenshot({ path: 'screenshot.png' });29 await closeBrowser();30});31const { afterScenario } = require('taiko');32afterScenario(async () => {33 await openBrowser();34 await screenshot({ path: 'screenshot.png' });35 await closeBrowser();36});37const { afterScenario } = require('taiko');38afterScenario(async () => {39 await openBrowser();40 await screenshot({ path: 'screenshot.png' });41 await closeBrowser();42});43const { afterScenario } = require('taiko');44afterScenario(async () => {45 await openBrowser();46 await screenshot({ path

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, write, closeBrowser, click, text, toRightOf, below, $, toLeftOf, closeTab } = require('taiko');2const assert = require("assert");3const headless = process.env.headless_chrome.toLowerCase() === 'true';4const { After } = require('cucumber');5const { openBrowser, goto, write, closeBrowser, click, text, toRightOf, below, $, toLeftOf, closeTab } = require('taiko');6const assert = require("assert");7const headless = process.env.headless_chrome.toLowerCase() === 'true';8const { After } = require('cucumber');9After(async function () {10 await closeBrowser();11 await closeTab();12});13const { setDefaultTimeout } = require('cucumber');14setDefaultTimeout(60 * 1000);15const { openBrowser, goto, write, closeBrowser, click, text, toRightOf, below, $, toLeftOf, closeTab } = require('taiko');16const assert = require("assert");17const headless = process.env.headless_chrome.toLowerCase() === 'true';18const { After } = require('cucumber');19const { openBrowser, goto, write, closeBrowser, click, text, toRightOf, below, $, toLeftOf, closeTab } = require('taiko');20const assert = require("assert");21const headless = process.env.headless_chrome.toLowerCase() === 'true';22const { After } = require('cucumber');23After(async function () {24 await closeBrowser();25 await closeTab();26});27const { setDefaultTimeout } = require('cucumber');28setDefaultTimeout(60 * 1000);29After(async function () {30 await closeBrowser();31 await closeTab();32});33const { setDefaultTimeout } = require('cucumber');34setDefaultTimeout(60 * 1000);35After(async function () {36 await closeBrowser();37 await closeTab();38});39const { setDefaultTimeout } = require('cucumber');40setDefaultTimeout(60 * 1000);41After(async function () {42 await closeBrowser();43 await closeTab();44});45const { setDefaultTimeout } = require('cucumber');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, closeBrowser, write, press, link, button, into, $, text, click, below, image, toRightOf, evaluate, focus, toLeftOf, near, radioButton, dropDown, checkBox, textBox, clear, accept, dismiss, reload, setConfig } = require('taiko');2const assert = require("assert");3const headless = process.env.headless_chrome.toLowerCase() === 'true';4const { After, Before, Status } = require('cucumber');5var fs = require('fs');6const { defaultConfig } = require('taiko/lib/config');7const { openBrowserArgs } = require('taiko/lib/taiko');8const { getOptions } = require('taiko/lib/taiko');9const { getOpenBrowserOptions } = require('taiko/lib/taiko');10const { getOpenBrowserOptions } = require('taiko/lib/taiko');11const { openBrowserArgs } = require('taiko/lib/taiko');12const { getOptions } = require('taiko/lib/taiko');13const { getOpenBrowserOptions } = require('taiko/lib/taiko');14Before({timeout: 100 * 1000}, async function () {15 await openBrowser({ headless: headless, args: ['--start-maximized', '--disable-infobars', '--disable-notifications', '--disable-web-security', '--disable-features=site-per-process', '--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage', '--disable-setuid-sandbox', '--allow-running-insecure-content', '--ignore-certificate-errors', '--ignore-certificate-errors-spki-list', '--disable-web-security', '--allow-insecure-localhost', '--allow-insecure-localhost=true', '--allow-insecure-localhost --allow-running-insecure-content --disable-web-security --disable-features=IsolateOrigins,site-per-process', '--allow-insecure-localhost --allow-running-insecure-content --disable-web-security --disable-features=IsolateOrigins,site-per-process --ignore-certificate-errors --ignore-certificate-errors-spki-list --disable-dev-shm-usage --disable-setuid-sandbox', '--allow-insecure-localhost --allow-running-insecure-content --disable-web-security --disable-features=IsolateOrigins,site-per-process --ignore-certificate-errors --ignore-certificate-errors-spki-list --disable-dev-sh

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

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

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