Solving this issue is made possible by Protractor through the utilization of the
browser.forkNewDriverInstance(opt_useSameUrl, opt_copyMockModules)
method. This method allows for the creation of an independent browser object. In accordance with the Protractor API overview available at
this link, you can find the official documentation below:
In scenarios where interaction between two browsers is required (e.g., chat systems), Protractor enables this functionality by enabling the dynamic creation of browsers during testing. The browser object in Protractor includes a function designed to facilitate this process:
browser.forkNewDriverInstance(opt_useSameUrl, opt_copyMockModules)
. Invoking this function will result in a new independent browser object being returned. The first parameter indicates whether the new browser should start with the same URL as the original browser it was forked from. The second parameter signifies if the new browser should replicate the mock modules from its predecessor.
browser.get('http://www.angularjs.org');
browser.addMockModule('moduleA', "angular.module('moduleA', []).value('version', '3');");
// Creating a new browser instance.
var browser2 = browser.forkNewDriverInstance();
// Creating a new browser instance with 'http://www.angularjs.org' as the URL:
var browser3 = browser.forkNewDriverInstance(true);
// Creating a new browser instance with injected mock modules:
var browser4 = browser.forkNewDriverInstance(false, true);
// Creating a new browser instance with 'http://www.angularjs.org' as the URL and
injected mock modules:
var browser4 = browser.forkNewDriverInstance(true, true);`
For your specific scenario, you can specify the relevant browser object on which you want to perform actions - such as verifying a message in the second instance using methods like
//get element text in second browser
var element2=browser2.element;
element2.getText().then(function(){
//use an expect to verify the text
});
Refer to the provided link for further details and clarifications.