8

The Question:

What is the canonical way to write multi browser window tests in Protractor - the tests that involve multiple sessions fired up interacting with one another?

The Story:

The main concern is: when you fork a new browser via browser.forkNewDriverInstance(true), all of the global Protractor objects like element() and element.all() are still tied to the first/parent browser. This makes it difficult to follow the Page Object pattern since all of the definitions there are using global element and element.all(). For instance, we cannot use this page object for the forked browsers:

var MyPageObject = function () {
    this.tabs = element.all(by.repeater("caseHistoryItem in caseViewCtrl.caseHistory"));
    this.activeCaseTab = element(by.css("ul#casesList li.active tab-heading.ap-tab-heading"));
}

The Test Case:

Just to make this a bit clearer, here is one of test cases we need to implement. A regular user logs into the application. Then, in a different browser an admin user logs into the application. An admin user closes the regular user's session through the admin tools. Confirm that regular user's session was properly closed.

3
  • 1
    The test case you got here could be implemented using two work stations, as how likely it is for an admin and a user to use the same PC?
    – Yu Zhang
    Commented Dec 21, 2016 at 20:12
  • @YuZhang good point. Well, different browsers would work for us too for the purposes of these kind of tests. Thanks.
    – alecxe
    Commented Dec 21, 2016 at 20:14
  • Multi-browser tests (the original question title) usually refers to different browsers, e.g. Firefox, Chrome, Safari, IE, etc. Your question details are actually about multi-session issues for one browser so I've updated the title and details to reflect that. Commented Apr 28, 2017 at 10:48

2 Answers 2

2

The test you describe is perhaps not as much about two different windows but about session management.

One solution would be to use two different browsers, e.g. chromdriver and firefox. Use one of the browsers for the regular user and the other for the admin user.

As for Page objects you may need to split them up and use one set for each browser.

1

Your problem might be solved by using the .switchTo() between two tabs.

You can also verify whether the user session is closed or not by checking the handles.length:

browser.getAllWindowHandles().then(function (handles) {
    browser.driver.switchTo().window(handles[1]).then(function () {
        expect(browser.getCurrentUrl()).toMatch(URL_REGEX);
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.