Multiple Browser Instances in Single Script
In a scenario like chatting, a test case may require 2 application users to be simultaneously logged in. Sahi Pro V5.1 and above provides the ability to launch new browser instances from a single script. These instances do not share cookies so they can allow multiple application users to be logged into the system simultaneously.
_launchNewBrowser
Section titled “_launchNewBrowser”- Since
- Sahi Pro 5.1.0
Modes Browser
_launchNewBrowser([$url[, $browserType]])Arguments
| Name | Type | Description |
|---|---|---|
$url | stringoptional | URL to load on opening new browser instance. If URL is null, the Start URL of the script is launched. |
$browserType | stringoptional | Browser type to launch. If null, a browser instance of the Default browser type is launched. |
Returns
string | Browser instanceId. This can be passed to _selectBrowser |
Launches a new browser instance. Note that this browser instance does not share cookies with the base browser. This new browser instance is useful for testing functionality like chat where 2 simultaneous users need to be logged in into the system. Once launched, steps can be directed to different browser instances by adding _selectBrowser function.
_navigateTo("http://myapp/login.html");// login as first user...// launch a new browser instancevar $instanceId = _launchNewBrowser("http://myapp/login.html");_wait(5000);// wait and select the new browser instance using the instanceId_selectBrowser($instanceId);// log in as second user// send a chat message to first user...
// Select the base window_selectBrowser();// view chat window and verify second user's chat message has arrived...// Examples for specifying argumentsvar $id1 = _launchNewBrowser(); // Launches a new chrome browser instance if base window is chrome.
// launch a new chrome browser instance and navigate to "http://myapp/login.html"var $id2 = _launchNewBrowser("http://myapp/login.html");// launch a new firefox browser instancevar $id3 = _launchNewBrowser(null, "firefox");// launch a new firefox browser instance and navigate to "http://myapp/login.html"var $id4 = _launchNewBrowser("http://myapp/login.html", "firefox");_selectBrowser
Section titled “_selectBrowser”- Since
- Sahi Pro 5.1.0
Modes Browser
_selectBrowser([$browserInstanceId])Arguments
| Name | Type | Description |
|---|---|---|
$browserInstanceId | stringoptional | browserInstanceId to forward further steps to. If not specified, steps are forwarded to the default browser that the script was started with. |
Returns
null |
Selects the particular browser instance. Further steps in the script will be directed to the selected instance.
_navigateTo("http://myapp/login.html");// login as first user...// launch a new browser instancevar $instanceId = _launchNewBrowser("http://myapp/login.html");_wait(5000);// wait and select the new browser instance using the instanceId_selectBrowser($instanceId);// log in as second user// send a chat message to first user...
// Select the base window_selectBrowser();// view chat window and verify second user's chat message has arrived...
