How to use afterEach method in Puppeteer

Best JavaScript code snippet using puppeteer

SpecRunningSpec.js

Source:SpecRunningSpec.js Github

copy

Full Screen

...66 var actions = [];67 env.beforeEach(function () {68 actions.push('topSuite beforeEach');69 });70 env.afterEach(function () {71 actions.push('topSuite afterEach');72 });73 env.describe('Something', function() {74 env.beforeEach(function() {75 actions.push('outer beforeEach');76 });77 env.afterEach(function() {78 actions.push('outer afterEach');79 });80 env.it('does it 1', function() {81 actions.push('outer it 1');82 });83 env.describe('Inner 1', function() {84 env.beforeEach(function() {85 actions.push('inner 1 beforeEach');86 });87 env.afterEach(function() {88 actions.push('inner 1 afterEach');89 });90 env.it('does it 2', function() {91 actions.push('inner 1 it');92 });93 });94 env.it('does it 3', function() {95 actions.push('outer it 2');96 });97 env.describe('Inner 2', function() {98 env.beforeEach(function() {99 actions.push('inner 2 beforeEach');100 });101 env.afterEach(function() {102 actions.push('inner 2 afterEach');103 });104 env.it('does it 2', function() {105 actions.push('inner 2 it');106 });107 });108 });109 var assertions = function() {110 var expected = [111 "topSuite beforeEach",112 "outer beforeEach",113 "outer it 1",114 "outer afterEach",115 "topSuite afterEach",116 "topSuite beforeEach",117 "outer beforeEach",118 "inner 1 beforeEach",119 "inner 1 it",120 "inner 1 afterEach",121 "outer afterEach",122 "topSuite afterEach",123 "topSuite beforeEach",124 "outer beforeEach",125 "outer it 2",126 "outer afterEach",127 "topSuite afterEach",128 "topSuite beforeEach",129 "outer beforeEach",130 "inner 2 beforeEach",131 "inner 2 it",132 "inner 2 afterEach",133 "outer afterEach",134 "topSuite afterEach"135 ];136 expect(actions).toEqual(expected);137 done();138 };139 env.addReporter({jasmineDone: assertions});140 env.execute();141 });142 it("should run multiple befores and afters ordered so functions declared later are treated as more specific", function(done) {143 var actions = [];144 env.beforeEach(function () {145 actions.push('runner beforeEach1');146 });147 env.afterEach(function () {148 actions.push('runner afterEach1');149 });150 env.beforeEach(function () {151 actions.push('runner beforeEach2');152 });153 env.afterEach(function () {154 actions.push('runner afterEach2');155 });156 env.describe('Something', function() {157 env.beforeEach(function() {158 actions.push('beforeEach1');159 });160 env.afterEach(function() {161 actions.push('afterEach1');162 });163 env.beforeEach(function() {164 actions.push('beforeEach2');165 });166 env.afterEach(function() {167 actions.push('afterEach2');168 });169 env.it('does it 1', function() {170 actions.push('outer it 1');171 });172 });173 var assertions = function() {174 var expected = [175 "runner beforeEach1",176 "runner beforeEach2",177 "beforeEach1",178 "beforeEach2",179 "outer it 1",180 "afterEach2",181 "afterEach1",182 "runner afterEach2",183 "runner afterEach1"184 ];185 expect(actions).toEqual(expected);186 done();187 };188 env.addReporter({jasmineDone: assertions});189 env.execute();190 });191 it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function(done) {192 var actions = [];193 env.beforeAll(function() {194 actions.push('runner beforeAll');195 });196 env.afterAll(function() {197 actions.push('runner afterAll');198 });199 env.beforeEach(function () {200 actions.push('runner beforeEach');201 });202 env.afterEach(function () {203 actions.push('runner afterEach');204 });205 env.describe('Something', function() {206 env.beforeEach(function() {207 actions.push('inner beforeEach');208 });209 env.afterEach(function() {210 actions.push('inner afterEach');211 });212 env.beforeAll(function() {213 actions.push('inner beforeAll');214 });215 env.afterAll(function() {216 actions.push('inner afterAll');217 });218 env.it('does something or other', function() {219 actions.push('it');220 });221 });222 var assertions = function() {223 var expected = [224 "runner beforeAll",225 "inner beforeAll",226 "runner beforeEach",227 "inner beforeEach",228 "it",229 "inner afterEach",230 "runner afterEach",231 "inner afterAll",232 "runner afterAll"233 ];234 expect(actions).toEqual(expected);235 done();236 };237 env.addReporter({jasmineDone: assertions});238 env.execute();239 });240 it('should run beforeAlls and afterAlls in the order declared when runnablesToRun is provided', function(done) {241 var actions = [],242 spec,243 spec2;244 env.beforeAll(function() {245 actions.push('runner beforeAll');246 });247 env.afterAll(function() {248 actions.push('runner afterAll');249 });250 env.beforeEach(function () {251 actions.push('runner beforeEach');252 });253 env.afterEach(function () {254 actions.push('runner afterEach');255 });256 env.describe('Something', function() {257 env.beforeEach(function() {258 actions.push('inner beforeEach');259 });260 env.afterEach(function() {261 actions.push('inner afterEach');262 });263 env.beforeAll(function() {264 actions.push('inner beforeAll');265 });266 env.afterAll(function() {267 actions.push('inner afterAll');268 });269 spec = env.it('does something', function() {270 actions.push('it');271 });272 spec2 = env.it('does something or other', function() {273 actions.push('it2');274 });275 });276 var assertions = function() {277 var expected = [278 "runner beforeAll",279 "inner beforeAll",280 "runner beforeEach",281 "inner beforeEach",282 "it2",283 "inner afterEach",284 "runner afterEach",285 "runner beforeEach",286 "inner beforeEach",287 "it",288 "inner afterEach",289 "runner afterEach",290 "inner afterAll",291 "runner afterAll"292 ];293 expect(actions).toEqual(expected);294 done();295 };296 env.addReporter({jasmineDone: assertions});297 env.execute([spec2.id, spec.id]);298 });299 it('only runs *Alls once in a focused suite', function(done){300 var actions = [];301 env.fdescribe('Suite', function() {302 env.beforeAll(function(){303 actions.push('beforeAll');304 });305 env.it('should run beforeAll once', function() {306 actions.push('spec');307 });308 env.afterAll(function(){309 actions.push('afterAll');310 });311 });312 var assertions = function() {313 expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);314 done();315 };316 env.addReporter({jasmineDone: assertions});317 env.execute();318 });319 describe('focused runnables', function() {320 it('runs the relevant alls and eachs for each runnable', function(done) {321 var actions = [];322 env.beforeAll(function() {actions.push('beforeAll')});323 env.afterAll(function() {actions.push('afterAll')});324 env.beforeEach(function() {actions.push('beforeEach')});325 env.afterEach(function() {actions.push('afterEach')});326 env.fdescribe('a focused suite', function() {327 env.it('is run', function() {328 actions.push('spec in fdescribe')329 });330 });331 env.describe('an unfocused suite', function() {332 env.fit('has a focused spec', function() {333 actions.push('focused spec')334 });335 });336 var assertions = function() {337 var expected = [338 'beforeAll',339 'beforeEach',340 'spec in fdescribe',341 'afterEach',342 'beforeEach',343 'focused spec',344 'afterEach',345 'afterAll'346 ];347 expect(actions).toEqual(expected);348 done();349 };350 env.addReporter({jasmineDone: assertions});351 env.execute();352 });353 it('focused specs in focused suites cause non-focused siblings to not run', function(done){354 var actions = [];355 env.fdescribe('focused suite', function() {356 env.it('unfocused spec', function() {357 actions.push('unfocused spec')358 });359 env.fit('focused spec', function() {360 actions.push('focused spec')361 });362 });363 var assertions = function() {364 var expected = ['focused spec'];365 expect(actions).toEqual(expected);366 done();367 };368 env.addReporter({jasmineDone: assertions});369 env.execute();370 });371 it('focused suites in focused suites cause non-focused siblings to not run', function(done){372 var actions = [];373 env.fdescribe('focused suite', function() {374 env.it('unfocused spec', function() {375 actions.push('unfocused spec')376 });377 env.fdescribe('inner focused suite', function() {378 env.it('inner spec', function() {379 actions.push('inner spec');380 });381 });382 });383 var assertions = function() {384 var expected = ['inner spec'];385 expect(actions).toEqual(expected);386 done();387 };388 env.addReporter({jasmineDone: assertions});389 env.execute();390 });391 it('focused runnables unfocus ancestor focused suites', function() {392 var actions = [];393 env.fdescribe('focused suite', function() {394 env.it('unfocused spec', function() {395 actions.push('unfocused spec')396 });397 env.describe('inner focused suite', function() {398 env.fit('focused spec', function() {399 actions.push('focused spec');400 });401 });402 });403 var assertions = function() {404 var expected = ['focused spec'];405 expect(actions).toEqual(expected);406 done();407 };408 env.addReporter({jasmineDone: assertions});409 env.execute();410 });411 });412 it("shouldn't run disabled suites", function(done) {413 var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),414 suite = env.describe('A Suite', function() {415 env.xdescribe('with a disabled suite', function(){416 env.it('spec inside a disabled suite', specInADisabledSuite);417 });418 });419 var assertions = function() {420 expect(specInADisabledSuite).not.toHaveBeenCalled();421 done();422 };423 env.addReporter({jasmineDone: assertions});424 env.execute();425 });426 it("should allow top level suites to be disabled", function() {427 var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),428 otherSpec = jasmine.createSpy("otherSpec");429 env.xdescribe('A disabled suite', function() {430 env.it('spec inside a disabled suite', specInADisabledSuite);431 });432 env.describe('Another suite', function() {433 env.it('another spec', otherSpec);434 });435 var assertions = function() {436 expect(specInADisabledSuite).not.toHaveBeenCalled();437 expect(otherSpec).toHaveBeenCalled();438 done();439 };440 env.addReporter({jasmineDone: assertions});441 env.execute();442 });443 it("should set all pending specs to pending when a suite is run", function(done) {444 var pendingSpec,445 suite = env.describe('default current suite', function() {446 pendingSpec = env.it("I am a pending spec");447 });448 var assertions = function() {449 expect(pendingSpec.status()).toBe("pending");450 done();451 };452 env.addReporter({jasmineDone: assertions});453 env.execute();454 });455 it("should recover gracefully when there are errors in describe functions", function(done) {456 var specs = [],457 reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);458 reporter.specDone.and.callFake(function(result) {459 specs.push(result.fullName);460 });461 reporter.jasmineDone.and.callFake(function() {462 expect(specs).toContain('outer1 inner1 should thingy');463 expect(specs).toContain('outer1 inner1 encountered a declaration exception');464 expect(specs).toContain('outer1 inner2 should other thingy');465 expect(specs).toContain('outer1 encountered a declaration exception');466 expect(specs).toContain('outer2 should xxx');467 done();468 });469 expect(function() {470 env.describe("outer1", function() {471 env.describe("inner1", function() {472 env.it("should thingy", function() {473 this.expect(true).toEqual(true);474 });475 throw new Error("fake error");476 });477 env.describe("inner2", function() {478 env.it("should other thingy", function() {479 this.expect(true).toEqual(true);480 });481 });482 throw new Error("fake error");483 });484 }).not.toThrow();485 env.describe("outer2", function() {486 env.it("should xxx", function() {487 this.expect(true).toEqual(true);488 });489 });490 env.addReporter(reporter);491 env.execute();492 });493 it("re-enters suites that have no *Alls", function(done) {494 var actions = [],495 spec1, spec2, spec3;496 env.describe("top", function() {497 spec1 = env.it("spec1", function() {498 actions.push("spec1");499 });500 spec2 = env.it("spec2", function() {501 actions.push("spec2");502 });503 });504 spec3 = env.it("spec3", function() {505 actions.push("spec3");506 });507 env.addReporter({508 jasmineDone: function() {509 expect(actions).toEqual(["spec2", "spec3", "spec1"]);510 done();511 }512 });513 env.execute([spec2.id, spec3.id, spec1.id]);514 });515 it("refuses to re-enter suites with a beforeAll", function() {516 var actions = [],517 spec1, spec2, spec3;518 env.describe("top", function() {519 env.beforeAll(function() {});520 spec1 = env.it("spec1", function() {521 actions.push("spec1");522 });523 spec2 = env.it("spec2", function() {524 actions.push("spec2");525 });526 });527 spec3 = env.it("spec3", function() {528 actions.push("spec3");529 });530 env.addReporter({531 jasmineDone: function() {532 expect(actions).toEqual([]);533 done();534 }535 });536 expect(function() {537 env.execute([spec2.id, spec3.id, spec1.id]);538 }).toThrowError(/beforeAll/);539 });540 it("refuses to re-enter suites with a afterAll", function() {541 var actions = [],542 spec1, spec2, spec3;543 env.describe("top", function() {544 env.afterAll(function() {});545 spec1 = env.it("spec1", function() {546 actions.push("spec1");547 });548 spec2 = env.it("spec2", function() {549 actions.push("spec2");550 });551 });552 spec3 = env.it("spec3", function() {553 actions.push("spec3");554 });555 env.addReporter({556 jasmineDone: function() {557 expect(actions).toEqual([]);558 done();559 }560 });561 expect(function() {562 env.execute([spec2.id, spec3.id, spec1.id]);563 }).toThrowError(/afterAll/);564 });565 it("should run the tests in a consistent order when a seed is supplied", function(done) {566 var actions = [];567 env.randomizeTests(true);568 env.seed('123456');569 env.beforeEach(function () {570 actions.push('topSuite beforeEach');571 });572 env.afterEach(function () {573 actions.push('topSuite afterEach');574 });575 env.describe('Something', function() {576 env.beforeEach(function() {577 actions.push('outer beforeEach');578 });579 env.afterEach(function() {580 actions.push('outer afterEach');581 });582 env.it('does it 1', function() {583 actions.push('outer it 1');584 });585 env.describe('Inner 1', function() {586 env.beforeEach(function() {587 actions.push('inner 1 beforeEach');588 });589 env.afterEach(function() {590 actions.push('inner 1 afterEach');591 });592 env.it('does it 2', function() {593 actions.push('inner 1 it');594 });595 });596 env.it('does it 3', function() {597 actions.push('outer it 2');598 });599 env.describe('Inner 2', function() {600 env.beforeEach(function() {601 actions.push('inner 2 beforeEach');602 });603 env.afterEach(function() {604 actions.push('inner 2 afterEach');605 });606 env.it('does it 2', function() {607 actions.push('inner 2 it');608 });609 });610 });611 var assertions = function() {612 var expected = [613 'topSuite beforeEach',614 'outer beforeEach',615 'outer it 2',616 'outer afterEach',617 'topSuite afterEach',...

Full Screen

Full Screen

SpecRunningSpec-836403183fdd79d7c6a85caa1875c36cf801d68feef3dc6f791569016414af22.js

Source:SpecRunningSpec-836403183fdd79d7c6a85caa1875c36cf801d68feef3dc6f791569016414af22.js Github

copy

Full Screen

...66 var actions = [];67 env.beforeEach(function () {68 actions.push('topSuite beforeEach');69 });70 env.afterEach(function () {71 actions.push('topSuite afterEach');72 });73 env.describe('Something', function() {74 env.beforeEach(function() {75 actions.push('outer beforeEach');76 });77 env.afterEach(function() {78 actions.push('outer afterEach');79 });80 env.it('does it 1', function() {81 actions.push('outer it 1');82 });83 env.describe('Inner 1', function() {84 env.beforeEach(function() {85 actions.push('inner 1 beforeEach');86 });87 env.afterEach(function() {88 actions.push('inner 1 afterEach');89 });90 env.it('does it 2', function() {91 actions.push('inner 1 it');92 });93 });94 env.it('does it 3', function() {95 actions.push('outer it 2');96 });97 env.describe('Inner 2', function() {98 env.beforeEach(function() {99 actions.push('inner 2 beforeEach');100 });101 env.afterEach(function() {102 actions.push('inner 2 afterEach');103 });104 env.it('does it 2', function() {105 actions.push('inner 2 it');106 });107 });108 });109 var assertions = function() {110 var expected = [111 "topSuite beforeEach",112 "outer beforeEach",113 "outer it 1",114 "outer afterEach",115 "topSuite afterEach",116 "topSuite beforeEach",117 "outer beforeEach",118 "inner 1 beforeEach",119 "inner 1 it",120 "inner 1 afterEach",121 "outer afterEach",122 "topSuite afterEach",123 "topSuite beforeEach",124 "outer beforeEach",125 "outer it 2",126 "outer afterEach",127 "topSuite afterEach",128 "topSuite beforeEach",129 "outer beforeEach",130 "inner 2 beforeEach",131 "inner 2 it",132 "inner 2 afterEach",133 "outer afterEach",134 "topSuite afterEach"135 ];136 expect(actions).toEqual(expected);137 done();138 };139 env.addReporter({jasmineDone: assertions});140 env.execute();141 });142 it("should run multiple befores and afters ordered so functions declared later are treated as more specific", function(done) {143 var actions = [];144 env.beforeEach(function () {145 actions.push('runner beforeEach1');146 });147 env.afterEach(function () {148 actions.push('runner afterEach1');149 });150 env.beforeEach(function () {151 actions.push('runner beforeEach2');152 });153 env.afterEach(function () {154 actions.push('runner afterEach2');155 });156 env.describe('Something', function() {157 env.beforeEach(function() {158 actions.push('beforeEach1');159 });160 env.afterEach(function() {161 actions.push('afterEach1');162 });163 env.beforeEach(function() {164 actions.push('beforeEach2');165 });166 env.afterEach(function() {167 actions.push('afterEach2');168 });169 env.it('does it 1', function() {170 actions.push('outer it 1');171 });172 });173 var assertions = function() {174 var expected = [175 "runner beforeEach1",176 "runner beforeEach2",177 "beforeEach1",178 "beforeEach2",179 "outer it 1",180 "afterEach2",181 "afterEach1",182 "runner afterEach2",183 "runner afterEach1"184 ];185 expect(actions).toEqual(expected);186 done();187 };188 env.addReporter({jasmineDone: assertions});189 env.execute();190 });191 it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function(done) {192 var actions = [];193 env.beforeAll(function() {194 actions.push('runner beforeAll');195 });196 env.afterAll(function() {197 actions.push('runner afterAll');198 });199 env.beforeEach(function () {200 actions.push('runner beforeEach');201 });202 env.afterEach(function () {203 actions.push('runner afterEach');204 });205 env.describe('Something', function() {206 env.beforeEach(function() {207 actions.push('inner beforeEach');208 });209 env.afterEach(function() {210 actions.push('inner afterEach');211 });212 env.beforeAll(function() {213 actions.push('inner beforeAll');214 });215 env.afterAll(function() {216 actions.push('inner afterAll');217 });218 env.it('does something or other', function() {219 actions.push('it');220 });221 });222 var assertions = function() {223 var expected = [224 "runner beforeAll",225 "inner beforeAll",226 "runner beforeEach",227 "inner beforeEach",228 "it",229 "inner afterEach",230 "runner afterEach",231 "inner afterAll",232 "runner afterAll"233 ];234 expect(actions).toEqual(expected);235 done();236 };237 env.addReporter({jasmineDone: assertions});238 env.execute();239 });240 it('should run beforeAlls and afterAlls in the order declared when runnablesToRun is provided', function(done) {241 var actions = [],242 spec,243 spec2;244 env.beforeAll(function() {245 actions.push('runner beforeAll');246 });247 env.afterAll(function() {248 actions.push('runner afterAll');249 });250 env.beforeEach(function () {251 actions.push('runner beforeEach');252 });253 env.afterEach(function () {254 actions.push('runner afterEach');255 });256 env.describe('Something', function() {257 env.beforeEach(function() {258 actions.push('inner beforeEach');259 });260 env.afterEach(function() {261 actions.push('inner afterEach');262 });263 env.beforeAll(function() {264 actions.push('inner beforeAll');265 });266 env.afterAll(function() {267 actions.push('inner afterAll');268 });269 spec = env.it('does something', function() {270 actions.push('it');271 });272 spec2 = env.it('does something or other', function() {273 actions.push('it2');274 });275 });276 var assertions = function() {277 var expected = [278 "runner beforeAll",279 "inner beforeAll",280 "runner beforeEach",281 "inner beforeEach",282 "it2",283 "inner afterEach",284 "runner afterEach",285 "runner beforeEach",286 "inner beforeEach",287 "it",288 "inner afterEach",289 "runner afterEach",290 "inner afterAll",291 "runner afterAll"292 ];293 expect(actions).toEqual(expected);294 done();295 };296 env.addReporter({jasmineDone: assertions});297 env.execute([spec2.id, spec.id]);298 });299 it('only runs *Alls once in a focused suite', function(done){300 var actions = [];301 env.fdescribe('Suite', function() {302 env.beforeAll(function(){303 actions.push('beforeAll');304 });305 env.it('should run beforeAll once', function() {306 actions.push('spec');307 });308 env.afterAll(function(){309 actions.push('afterAll');310 });311 });312 var assertions = function() {313 expect(actions).toEqual(['beforeAll', 'spec', 'afterAll']);314 done();315 };316 env.addReporter({jasmineDone: assertions});317 env.execute();318 });319 describe('focused runnables', function() {320 it('runs the relevant alls and eachs for each runnable', function(done) {321 var actions = [];322 env.beforeAll(function() {actions.push('beforeAll')});323 env.afterAll(function() {actions.push('afterAll')});324 env.beforeEach(function() {actions.push('beforeEach')});325 env.afterEach(function() {actions.push('afterEach')});326 env.fdescribe('a focused suite', function() {327 env.it('is run', function() {328 actions.push('spec in fdescribe')329 });330 });331 env.describe('an unfocused suite', function() {332 env.fit('has a focused spec', function() {333 actions.push('focused spec')334 });335 });336 var assertions = function() {337 var expected = [338 'beforeAll',339 'beforeEach',340 'spec in fdescribe',341 'afterEach',342 'beforeEach',343 'focused spec',344 'afterEach',345 'afterAll'346 ];347 expect(actions).toEqual(expected);348 done();349 };350 env.addReporter({jasmineDone: assertions});351 env.execute();352 });353 it('focused specs in focused suites cause non-focused siblings to not run', function(done){354 var actions = [];355 env.fdescribe('focused suite', function() {356 env.it('unfocused spec', function() {357 actions.push('unfocused spec')358 });359 env.fit('focused spec', function() {360 actions.push('focused spec')361 });362 });363 var assertions = function() {364 var expected = ['focused spec'];365 expect(actions).toEqual(expected);366 done();367 };368 env.addReporter({jasmineDone: assertions});369 env.execute();370 });371 it('focused suites in focused suites cause non-focused siblings to not run', function(done){372 var actions = [];373 env.fdescribe('focused suite', function() {374 env.it('unfocused spec', function() {375 actions.push('unfocused spec')376 });377 env.fdescribe('inner focused suite', function() {378 env.it('inner spec', function() {379 actions.push('inner spec');380 });381 });382 });383 var assertions = function() {384 var expected = ['inner spec'];385 expect(actions).toEqual(expected);386 done();387 };388 env.addReporter({jasmineDone: assertions});389 env.execute();390 });391 it('focused runnables unfocus ancestor focused suites', function() {392 var actions = [];393 env.fdescribe('focused suite', function() {394 env.it('unfocused spec', function() {395 actions.push('unfocused spec')396 });397 env.describe('inner focused suite', function() {398 env.fit('focused spec', function() {399 actions.push('focused spec');400 });401 });402 });403 var assertions = function() {404 var expected = ['focused spec'];405 expect(actions).toEqual(expected);406 done();407 };408 env.addReporter({jasmineDone: assertions});409 env.execute();410 });411 });412 it("shouldn't run disabled suites", function(done) {413 var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),414 suite = env.describe('A Suite', function() {415 env.xdescribe('with a disabled suite', function(){416 env.it('spec inside a disabled suite', specInADisabledSuite);417 });418 });419 var assertions = function() {420 expect(specInADisabledSuite).not.toHaveBeenCalled();421 done();422 };423 env.addReporter({jasmineDone: assertions});424 env.execute();425 });426 it("should allow top level suites to be disabled", function() {427 var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),428 otherSpec = jasmine.createSpy("otherSpec");429 env.xdescribe('A disabled suite', function() {430 env.it('spec inside a disabled suite', specInADisabledSuite);431 });432 env.describe('Another suite', function() {433 env.it('another spec', otherSpec);434 });435 var assertions = function() {436 expect(specInADisabledSuite).not.toHaveBeenCalled();437 expect(otherSpec).toHaveBeenCalled();438 done();439 };440 env.addReporter({jasmineDone: assertions});441 env.execute();442 });443 it("should set all pending specs to pending when a suite is run", function(done) {444 var pendingSpec,445 suite = env.describe('default current suite', function() {446 pendingSpec = env.it("I am a pending spec");447 });448 var assertions = function() {449 expect(pendingSpec.status()).toBe("pending");450 done();451 };452 env.addReporter({jasmineDone: assertions});453 env.execute();454 });455 it("should recover gracefully when there are errors in describe functions", function(done) {456 var specs = [],457 reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);458 reporter.specDone.and.callFake(function(result) {459 specs.push(result.fullName);460 });461 reporter.jasmineDone.and.callFake(function() {462 expect(specs).toContain('outer1 inner1 should thingy');463 expect(specs).toContain('outer1 inner1 encountered a declaration exception');464 expect(specs).toContain('outer1 inner2 should other thingy');465 expect(specs).toContain('outer1 encountered a declaration exception');466 expect(specs).toContain('outer2 should xxx');467 done();468 });469 expect(function() {470 env.describe("outer1", function() {471 env.describe("inner1", function() {472 env.it("should thingy", function() {473 this.expect(true).toEqual(true);474 });475 throw new Error("fake error");476 });477 env.describe("inner2", function() {478 env.it("should other thingy", function() {479 this.expect(true).toEqual(true);480 });481 });482 throw new Error("fake error");483 });484 }).not.toThrow();485 env.describe("outer2", function() {486 env.it("should xxx", function() {487 this.expect(true).toEqual(true);488 });489 });490 env.addReporter(reporter);491 env.execute();492 });493 it("re-enters suites that have no *Alls", function(done) {494 var actions = [],495 spec1, spec2, spec3;496 env.describe("top", function() {497 spec1 = env.it("spec1", function() {498 actions.push("spec1");499 });500 spec2 = env.it("spec2", function() {501 actions.push("spec2");502 });503 });504 spec3 = env.it("spec3", function() {505 actions.push("spec3");506 });507 env.addReporter({508 jasmineDone: function() {509 expect(actions).toEqual(["spec2", "spec3", "spec1"]);510 done();511 }512 });513 env.execute([spec2.id, spec3.id, spec1.id]);514 });515 it("refuses to re-enter suites with a beforeAll", function() {516 var actions = [],517 spec1, spec2, spec3;518 env.describe("top", function() {519 env.beforeAll(function() {});520 spec1 = env.it("spec1", function() {521 actions.push("spec1");522 });523 spec2 = env.it("spec2", function() {524 actions.push("spec2");525 });526 });527 spec3 = env.it("spec3", function() {528 actions.push("spec3");529 });530 env.addReporter({531 jasmineDone: function() {532 expect(actions).toEqual([]);533 done();534 }535 });536 expect(function() {537 env.execute([spec2.id, spec3.id, spec1.id]);538 }).toThrowError(/beforeAll/);539 });540 it("refuses to re-enter suites with a afterAll", function() {541 var actions = [],542 spec1, spec2, spec3;543 env.describe("top", function() {544 env.afterAll(function() {});545 spec1 = env.it("spec1", function() {546 actions.push("spec1");547 });548 spec2 = env.it("spec2", function() {549 actions.push("spec2");550 });551 });552 spec3 = env.it("spec3", function() {553 actions.push("spec3");554 });555 env.addReporter({556 jasmineDone: function() {557 expect(actions).toEqual([]);558 done();559 }560 });561 expect(function() {562 env.execute([spec2.id, spec3.id, spec1.id]);563 }).toThrowError(/afterAll/);564 });565 it("should run the tests in a consistent order when a seed is supplied", function(done) {566 var actions = [];567 env.randomizeTests(true);568 env.seed('123456');569 env.beforeEach(function () {570 actions.push('topSuite beforeEach');571 });572 env.afterEach(function () {573 actions.push('topSuite afterEach');574 });575 env.describe('Something', function() {576 env.beforeEach(function() {577 actions.push('outer beforeEach');578 });579 env.afterEach(function() {580 actions.push('outer afterEach');581 });582 env.it('does it 1', function() {583 actions.push('outer it 1');584 });585 env.describe('Inner 1', function() {586 env.beforeEach(function() {587 actions.push('inner 1 beforeEach');588 });589 env.afterEach(function() {590 actions.push('inner 1 afterEach');591 });592 env.it('does it 2', function() {593 actions.push('inner 1 it');594 });595 });596 env.it('does it 3', function() {597 actions.push('outer it 2');598 });599 env.describe('Inner 2', function() {600 env.beforeEach(function() {601 actions.push('inner 2 beforeEach');602 });603 env.afterEach(function() {604 actions.push('inner 2 afterEach');605 });606 env.it('does it 2', function() {607 actions.push('inner 2 it');608 });609 });610 });611 var assertions = function() {612 var expected = [613 'topSuite beforeEach',614 'outer beforeEach',615 'outer it 2',616 'outer afterEach',617 'topSuite afterEach',...

Full Screen

Full Screen

Order.js

Source:Order.js Github

copy

Full Screen

...156 afterAll(function() {157 order.push('foo afterAll');158 });159 160 afterEach(function() {161 order.push('foo afterEach 1');162 });163 164 afterEach(function() {165 order.push('foo afterEach 2');166 });167 168 it("foo 1", function() {169 runs(function() {170 order.push('foo it 1-2');171 });172 173 order.push('foo it 1-1');174 175 // If there is a problem this waits() will break async flow176 waits(1);177 178 runs(function() {179 order.push('foo it 1-3');180 });181 });182 183 spec = todo().184 it("foo 2", function() {185 // This is going to time out after 1 invocation186 waitsFor(function() {187 order.push('foo it 2-2');188 return false;189 }, 'foo 2 to run', 1, 10);190 191 order.push('foo it 2-1');192 // Don't try to do this at home!193 this.queue.insertNext(new jasmine.Block(this.env, function() {194 order.push('foo it 2-3');195 }, this), true);196 });197 198 spec = todo().199 it("foo 3", function() {200 order.push('foo it 3-1');201 202 // This is going to time out after 2 invocations203 waitsFor(function() {204 order.push('foo it 3-2');205 return false;206 }, 'foo 3 to run', 20, 10);207 208 this.queue.insertNext(new jasmine.Block(this.env, function() {209 order.push('foo it 3-3');210 }, this), true);211 });212 213 describe("bar", function() {214 beforeAll(function() {215 order.push('bar beforeAll');216 });217 218 beforeEach(function() {219 runs(function() {220 order.push('bar beforeEach runs');221 });222 223 waitsFor(function(done) {224 order.push('bar beforeEach waitsFor');225 done();226 });227 });228 229 afterEach(function() {230 order.push('bar afterEach');231 });232 233 afterAll(function() {234 order.push('bar afterAll');235 });236 237 it("bar 1", function() {238 waitsFor(function() {239 order.push('bar it 1-2');240 return true;241 }, 'bar 1 to run', 10, 10);242 243 runs(function() {244 order.push('bar it 1-3');245 });246 247 order.push('bar it 1-1');248 });249 250 it("bar 2", function() {251 this.counter = 0;252 253 waitsFor(function() {254 order.push('bar it 2-2');255 return this.counter++;256 }, 'bar 1 to run', 100, 10);257 258 runs(function() {259 order.push('bar it 2-3');260 });261 262 order.push('bar it 2-1');263 });264 265 describe("qux", function() {266 beforeEach(function() {267 runs(function() {268 order.push('qux beforeEach 1');269 });270 271 waits(1);272 273 runs(function() {274 order.push('qux beforeEach 2');275 });276 });277 278 afterEach(function() {279 order.push('qux afterEach');280 });281 282 afterAll(function() {283 order.push('qux afterAll');284 });285 286 todo().287 it("qux 1", function() {288 var spy = jasmine.createSpy('qux 1');289 290 order.push('qux it 1');291 292 // This is going to time out...

Full Screen

Full Screen

SinonQunitBridge.qunit.js

Source:SinonQunitBridge.qunit.js Github

copy

Full Screen

...10 baz : function () {}11 };12 // QUnit.todo does not exist in QUnit 1. Use QUnit.test instead -> the errors will be visible.13 QUnit.todo = QUnit.todo || QUnit.test;14 function afterEach() {15 sinon.assert.pass("pass");16 }17 function beforeEach() {18 this.mock(foo).expects("bar").withExactArgs("baz").returns(42);19 }20 var oHooks = {21 beforeEach : beforeEach,22 afterEach : afterEach23 };24 function useMock(assert) {25 assert.strictEqual(foo.bar("baz"), 42, "use mock");26 }27 // QUnit.module("nested 1", function () {});28 // QUnit.module("nested 2", {}, function () {});...

Full Screen

Full Screen

abstract-history.spec.js

Source:abstract-history.spec.js Github

copy

Full Screen

...7 const router = new VueRouter({ mode: 'abstract' })8 const afterEach = jasmine.createSpy('afterEach')9 const onReady = jasmine.createSpy('ready')10 const onError = jasmine.createSpy('error')11 router.afterEach(afterEach)12 router.onReady(onReady, onError)13 router.push('/').finally(() => {14 expect(onReady).toHaveBeenCalled()15 expect(onError).not.toHaveBeenCalled()16 expect(afterEach).toHaveBeenCalled()17 done()18 })19 })20 it('run afterEach after router.go', done => {21 const router = new VueRouter({ mode: 'abstract' })22 const afterEach = jasmine.createSpy('afterEach')23 router24 .push('/')25 .then(() => router.push('/foo'))26 .then(() => {27 router.afterEach(afterEach)28 router.go(-1)29 return delay(30)30 })31 .finally(() => {32 expect(afterEach).toHaveBeenCalled()33 done()34 })35 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1afterEach(async () => {2 await page.close()3})4afterAll(async () => {5 await browser.close()6})7describe('My first test', () => {8 it('should launch the browser', async () => {9 await expect(browser).toBeDefined()10 })11})12describe('My first test', () => {13 it('should launch the browser', async () => {14 await expect(browser).toBeDefined()15 })16})17describe('My first test', () => {18 it('should launch the browser', async () => {19 await expect(browser).toBeDefined()20 })21})22describe('My first test', () => {23 it('should launch the browser', async () => {24 await expect(browser).toBeDefined()25 })26})27describe('My first test', () => {28 it('should launch the browser', async () => {29 await expect(browser).toBeDefined()30 })31})32describe('My first test', () => {33 it('should launch the browser', async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2describe('Test', () => {3 let browser;4 let page;5 beforeEach(async () => {6 browser = await puppeteer.launch({7 });8 page = await browser.newPage();9 });10 afterEach(async () => {11 await browser.close();12 });13 test('should work', async () => {14 await page.screenshot({ path: 'example.png' });15 });16});17const puppeteer = require('puppeteer');18describe('Test', () => {19 let browser;20 let page;21 beforeAll(async () => {22 browser = await puppeteer.launch({23 });24 page = await browser.newPage();25 });26 afterAll(async () => {27 await browser.close();28 });29 test('should work', async () => {30 await page.screenshot({ path: 'example.png' });31 });32});33const puppeteer = require('puppeteer');34describe('Test', () => {35 let browser;36 let page;37 beforeAll(async () => {38 browser = await puppeteer.launch({39 });40 page = await browser.newPage();41 });42 afterAll(async () => {43 await browser.close();44 });45 test('should work', async () => {46 await page.screenshot({ path: 'example.png' });47 });48});49const puppeteer = require('puppeteer');50describe('Test', () => {51 let browser;52 let page;53 beforeAll(async () => {54 browser = await puppeteer.launch({55 });56 page = await browser.newPage();57 });58 afterAll(async () => {59 await browser.close();60 });61 test('should work', async () => {62 await page.screenshot({ path: 'example.png' });63 });64});65const puppeteer = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2describe('Puppeteer Test', () => {3 let browser;4 let page;5 beforeAll(async () => {6 browser = await puppeteer.launch({7 });8 page = await browser.newPage();9 });10 afterAll(() => {11 browser.close();12 });13 afterEach(async () => {14 const screenshot = await page.screenshot();15 this.attach(screenshot, 'image/png');16 });17 test('should display "example.com" text on page', async () => {18 await expect(page).toMatch('Example Domain');19 });20});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Google', () => {2 beforeAll(async () => {3 });4 afterAll(async () => {5 await browser.close();6 });7 afterEach(async () => {8 await page.screenshot({ path: 'screenshots/google.png' });9 });10 it('should be titled "Google"', async () => {11 await expect(page.title()).resolves.toMatch('Google');12 });13});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Puppeteer', () => {2 let browser;3 let page;4 beforeEach(async () => {5 browser = await puppeteer.launch({6 });7 page = await browser.newPage();8 await page.setDefaultTimeout(10000);9 await page.setDefaultNavigationTimeout(20000);10 });11 afterEach(async () => {12 await browser.close();13 });14 test('Launch Browser', async () => {15 await page.waitForSelector('h1');16 });17});

Full Screen

Using AI Code Generation

copy

Full Screen

1afterEach(async () => {2 await page.close();3});4afterAll(async () => {5 await browser.close();6});

Full Screen

Using AI Code Generation

copy

Full Screen

1afterEach(async () => {2 await page.screenshot({ path: 'example.png' });3 });4 afterAll(async () => {5 await browser.close();6 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const expect = require('chai').expect;3const fs = require('fs');4var page;5var browser;6var width = 1280;7var height = 800;8const username = "username";9const password = "password";10beforeEach(async function () {11 browser = await puppeteer.launch({12 args: [`--window-size=${width},${height}`]13 });14 page = await browser.newPage();15 await page.setDefaultTimeout(10000);16 await page.setDefaultNavigationTimeout(20000);17});18afterEach(async function () {19 await browser.close();20});21describe('Login Test', () => {22 it('should display login form', async () => {23 await page.goto(baseURL);24 await page.waitForSelector('#signin_button');25 await page.click('#signin_button');26 });27 it('should login to application', async () => {28 await page.waitForSelector('#login_form');29 await page.type('#user_login', username);30 await page.type('#user_password', password);31 await page.click('.btn-primary');32 });33 it('should have correct username', async () => {34 await page.waitForSelector('.nav-tabs');35 const userElement = await page.$('.nav-tabs');36 const userText = await page.evaluate(userElement => userElement.textContent, userElement);37 expect(userText).to.contain('username');38 });39});40describe('Online Banking Test', () => {41 it('should display online banking content', async () => {42 await page.goto(onlineBankingURL);43 await page.waitForSelector('#online_banking_features');44 });45 it('should display feedback form', async () => {46 await page.click('#feedback');47 await page.waitForSelector('form');48 });49 it('should submit feedback form', async () => {50 await page.type('#name', 'John Smith');51 await page.type('#email', 'johnsmith@gmail');52 await page.type('#subject', 'Test');53 await page.type('#comment', 'Test Comment');54 await page.click('input[type

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 Puppeteer 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