Sahi Pro - 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

Since Sahi Pro: 5.1.0
Since Sahi OS: NA

_launchNewBrowser([$url[, $browserType]])

Arguments
$urlstring optional URL to load on opening new browser instance
$browserTypestring optional BrowserType to open a new browser instance of a specific type eg. ie, firefox or chrome. Default browserType is same as the browser type of the base window. Since Sahi Pro 6.2.1

Details

Returns the browserInstanceId
Launches a new browser instance. This instance does not share cookies with the base browser.
This allows testing functionality like chat where 2 simultaneous users need to be logged in into the system.

// Suppose base window is chrome.
// launch a new chrome browser instance
var $id1 = _launchNewBrowser();
// 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 instance
var $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");

Sahi tries to get a browser instance from a separate pool of instances (defined by browserType capacity in browser_types.xml).
If one is available it will return immediately. If not, Sahi will wait and retry x number of times.
x is defined by property browser.max_wait_count_for_available_thread_from_dashboard in sahi.properties
If an instance is still not available, _launchNewBrowser will fail and throw an exception with appropriate message.

Once launched, steps can be directed to different browser instances via _selectBrowser

_selectBrowser

Since Sahi Pro: 5.1.0
Since Sahi OS: NA

_selectBrowser([$browserInstanceId])

Arguments
$browserInstanceIdstring optional browserInstanceId to forward further steps to. If not specified, steps are forwarded to base window.

Details

Selects the particular browser instance. Further steps in the script will be directed to the selected instance.

Sample code

_navigateTo("http://myapp/login.html");
// login as first user
...
// launch a new browser instance
var $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
...