Pages

Write multiple test cases in protractor

How to Write multiple test cases in protractor?

Before writing multiple test cases in protractor, learn how to write a protractor test case here

We can write multiple test cases using describe() and it() blocks which are from jasmine syntax.


Protractor Multiple test cases
Protractor Multiple test cases

Demo on writing protractor multiple test cases:


multipleTestcaseSpec.js
describe('Keep learners - Learn Protractor - Basics', function () {
    it('This is my First Test case - Basics', function () {
        browser.get('https://keeplearners.blogspot.com/2018/03/Angular-elements.html');
        expect(browser.getTitle()).toEqual('Keep Learning: Learn Protractor');
        console.log("Verified title");
    });
    it('This is my second Test case- Basics', function () {
        expect(browser.getTitle()).toContain('Keep Learning:');
        console.log("Verified title text");
    });
});

describe('Keep learners - Learn Protractor - Advanced', function () {
    it('This is my First Test case - Advanced', function () {
        expect(browser.getCurrentUrl()).toEqual('https://keeplearners.blogspot.com/2018/03/Angular-elements.html');
        console.log("Verified page url");
    });
    it('This is my second Test case - Advanced', function () {
        expect(browser.getCurrentUrl()).toContain('keeplearners.blogspot.com');
        console.log("Verified url text");
    });
});
Here, we observe every describe() block has multiple test cases. Based on your requirements we can create multiple describe() and it() blocks.

Run the above spec File (click here learn how to execute):

Protractor Multiple Test cases
Protractor Multiple Test cases
Another example, Let's say we have login functionality and logout functionality in an application. so, we can create 2 describe blocks for each functionality (login, logout).In login describe block we write login functionality test cases and in logout describe block we write logout test cases
describe('Keep learners - Login functionality', function () {
    it('Login functionality - First Test case', function () {
        //write code here    });
    it('Login functionality - Second Test case', function () {
        //write code here    });
});
describe('Keep learners - Logout functionalty', function () {
    it('logout functionality - First Test case', function () {
        //write code here    });
    it('logout functionality - Second Test case', function () {
        //write code here    });
});
Likewise we can write and execute multiple test cases in protractor.
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.