CST Popup windows/lookup fields/new windows handling and switching.

Updated 2 months ago ​by CST

"popup" windows (we are not referring about javascript dialogs, the ones with yes/no or ok buttons, nor open/save file dialogs) are sometimes troublesome to handle, because once there is more than a window, we need to specify in the test case which of the possibly several windows open should receive the clicks and be typed on.

For that, CST has a special command, copadoPopup, to supplement the standard Selenium commands selectPopUp/selectWindow.

The perfect example of a popup window is a Salesforce Lookup field, when clicking on the magnifying glass to search for a record.

In order to open a popup, the command "copadoPopup copado=popup:Account Name" will:

- search for the magnifying glass related to the field "Account Name"
- click it
- wait for and select the newly opened popup, so subsequent commands are executed there.

Once searching for an Account and clicking the name, we need to "focus" the attention back to the main window... we do this with the "copadoPopup" command, without any other parameter. 

So, a typical fragment of a test case dealing with Lookup windows would be: 

commandparameter 1parameter 2result
clickcopado=popup:Account Name[success]
clickcopado=button: Go![success]
comment... continue in the main window

Which, for Salesforce Classic Lookup fields and values that we can rely on are unique (Account#10), we can simply use a single command, and Copado will run almost like executing all those steps:

commandparameter 1parameter 2result
typecopado=field:Account NameAccount#10[success]

Similar results can be achieved in a more general fashion with the standard Selenium commands:

commandparameter 1parameter 2result
commentClick on the locator that points to the magnifying glass[success]
clickcss=TR:nth-of-type(4) > TD.dataCol.col02:nth-of-type(2) > SPAN.lookupInput > A[success]
comment... other commands here, that affect the popup, but not the main window.
comment... continue in the main screen.[success]

"close" might not be necessary, since some popups close automatically after performing an action (such as clicking "done", or choosing an item).

How did we do?