Secondary Windows (Popup Windows)
Applications may open secondary windows as a new window or in a new tab. This section shows how to automate secondary windows.
We handle secondary windows using 2 APIs.
_selectWindow
Section titled “_selectWindow”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
- SAP Engine 9.0.0
Modes BrowserWindowsJavaSAP
_selectWindow([$windowIdentifier])Arguments
| Name | Type | Description |
|---|---|---|
$windowIdentifier | stringoptional | the windowIdentifier can be the window name, the window title, or the window URL, or a regular expression of any of these. To reference the base window, omit this parameter or use null. The windowIdentifier can also be the sahiWinId. |
Returns
null |
This function allows selecting a window before performing further actions.
// switch to popWin popup window_selectWindow("popWin");// perform actions on popWin_assertEqual("Link Test", _getText(_link(0))); // no mention of popWin neededvar $href;_set($href, _link(0).href); // no mention of popWin needed...// switch back to base window_selectWindow();// perform actions on base window_click(_link("Window Open Test"));_wait(2000);var $recentWindowId = _getRecentWindow().sahiWinId;_selectWindow($recentWindowId);// perform actions on popWin_click(_link("Form Test"));_click(_link("Close Self"));// switch back to base window_selectWindow();// perform actions on base window_popup
Section titled “_popup”- Since
- Sahi Pro 3.5
- Desktop Engine 7.0.0
Modes BrowserWindowsJava
_popup([$windowIdentifier])Arguments
| Name | Type | Description |
|---|---|---|
$windowIdentifier | stringoptional | the windowIdentifier can be the window name, the window title, or the window URL, or a regular expression of any of these. To reference the base window, omit this parameter or use null. The windowIdentifier can also be the sahiWinId. |
Returns
null |
This was the default way of accessing secondary windows. Any step to be executed on a particular secondary window would be prefixed by _popup("windowIdentifier").
// clicks link on popup of name popupWindow_popup("popupWindow")._click(_link(0));// popup by name regular expression_popup("/pop.*Win/")._click(_link(0));// popup by title_popup("Popup Title")._click(_link(0));// popup by title regular expression_popup("/pup Tit/")._click(_link(0));// popup by URL_popup("http://sahi.co.in")._click(_link(0));// poppu by URL regular expression_popup("/sahi[.]co[.]in/")._click(_link(0));To fetch a value or asserting. this needs to be used a particular way.
_popup("popWin")._assertEqual("Link Test", _getText(_link(0))); // CORRECT_assertEqual("Link Test", _popup("popWin")._getText(_link(0))); // WRONG
var $href;_popup("popWin")._set($href, _link(0).href); // CORRECT_set($href, _popup("popWin")._link(0).href); // WRONG_getWindows
Section titled “_getWindows”- Since
- Sahi Pro 5.1.0
- Desktop Engine 7.5.0
Modes BrowserWindowsJava (8.0.0)
_getWindows([$activePeriod[, $includeIframes]])Arguments
| Name | Type | Description |
|---|---|---|
$activePeriod | integeroptional | time in milliseconds to return windows within the time. Default is 0, which returns all windows. This argument is valid only in Browser Mode. |
$includeIframes | booleanoptional | flag to get all windows including iframes. Default is false, which returns non-iframe windows. This argument is valid only in Browser Mode. This argument is available since Sahi Pro v9.1.0. |
Returns
li_mp | Array of window-property objects |
Returns an array of window-property objects. A window-property is just an associative array with the following attributes:
| Attribute | Description |
|---|---|
| windowName | window name |
| windowTitle | window title |
| windowURL | URL of top window |
| wasOpened | ‘0’ or ‘1’ as string. 0 means base window, 1 means popup window |
| domain | document.domain of window, if set |
| isIFrame | ‘0’ or ‘1’ as string. 1 means iframe window |
| initialTime | Timestamp when window was opened |
| lastTime | Timestamp of last ping from that window |
| sahiWinId | sahiWinId for that window |
// Example:_navigateTo("http://sahi.co.in/demo/");_click(_link("Window Open Test With Title"));_wait(2000);var $windows = _getWindows();_assertEqual(2, $windows.length);_assertEqual('With Title', $windows[1].windowTitle);_assertEqual("1", $windows[1].wasOpened);_windowExists
Section titled “_windowExists”- Since
- Sahi Pro 6.0.0
- Desktop Engine 7.5.0
Modes BrowserWindowsJava (9.0.0)
_windowExists($windowIdentifier[, $activePeriod])Arguments
| Name | Type | Description |
|---|---|---|
$windowIdentifier | string | The windowIdentifier can be the window name, the window title, the window URL or the sahiWinId, or a regular expression of any of these. |
$activePeriod | integeroptional | Time interval in milliseconds within which the specified window is checked for activity. Default is -1, which means the specified window is checked amongst all windows opened during the session. Available only for browser. |
Returns
boolean | true if the window exists, else false |
Returns true if the window exists.
// Example:_navigateTo("/demo/");_click(_link("Window Open Test"));_wait(3000);var $exists = _windowExists("/demo/");var $exists2 = _windowExists("popWin");_assertTrue($exists);_assertTrue($exists2);var $recentWindowId = _getRecentWindow().sahiWinId;var $exists3 = _windowExists($recentWindowId);_assertTrue($exists3);_selectWindow("popWin");_closeWindow(); // Closes the popup window_selectWindow();_wait(3000); // Wait for 3 secondsvar $exists3 = _windowExists("popWin", 3000); // Now _windowExists returns false._assertFalse($exists3);_getRecentWindow
Section titled “_getRecentWindow”- Since
- Sahi Pro 6.0.0
Modes Browser
_getRecentWindow()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
mp | Most recent (last opened) window |
Returns the most recent (last opened) window. Refer to _getWindows for all properties of window object returned.
// Example:_navigateTo("/demo/");_click(_link("Window Open Test"));_click(_link("Window Open Test With Title"));_wait(2000);var $recentWindow = _getRecentWindow();_assertEqual('With Title', $recentWindow.windowTitle); // This is the window opened by clicking the link "Window Open Test With Title"._assertEqual("1", $recentWindow.wasOpened);
