afterAll() in protractor?
- afterAll() block will be executed only once, after executing the all it() blocks in a describe() block
- We can write multiple it() blocks in a describe() block.
- afterAll is normally used to write the code(steps) for close browser, close DB connections, etc.,. depends upon your requirements.
Demo on afterAll():
describe('First describe block', function () {
it('First Test case - First describe block ', function () {
console.log("First Test case in First describe block");
});
it('Second Test case - First describe block ', function () {
console.log("Second Test case in First describe block");
});
afterAll(function () {
console.log("afterAll block in First describe block");
});
});
describe('Second describe block', function () {
it('First Test case - second describe block ', function () {
console.log("First Test case in second describe block");
});
it('Second Test case - second describe block ', function () {
console.log("Second Test case in second describe block");
});
afterAll(function () {
console.log("afterAll block in Second describe block");
});
});
Output:
- Here,till now afterAll() block scope is defined to specific describe() block only.
- We can also declare afterAll() block to after the all describe() blocks in the spec file.
describe('First describe block', function () {
it('First Test case - First describe block ', function () {
console.log("First Test case in First describe block");
});
it('Second Test case - First describe block ', function () {
console.log("Second Test case in First describe block");
});
afterAll(function () {
console.log("afterAll block in First describe block");
});
});
describe('Second describe block', function () {
it('First Test case - second describe block ', function () {
console.log("First Test case in second describe block");
});
it('Second Test case - second describe block ', function () {
console.log("Second Test case in second describe block");
});
afterAll(function () {
console.log("afterAll block in Second describe block");
});
});afterAll(function () {
console.log("afterAll block - after describe block(s)");
});
Output:
afterAll block in protractor |
Here, we observe that afterAll() blocks executed once after the all it() blocks.
Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.