Closing unexpected HTML dialogs during playback
You can use the dynamic find() API to close HTML dialogs that are displayed unexpectedly during playback, to ensure smooth playback.
HCL DevOps Test UI (Test UI) provides the unexpected window handling feature to handle unexpected windows that are displayed during playback. For more information about this feature, see Configuring how to handle unexpected windows during playback.
You can also use the dynamic find() API, modified as shown in this example, to close HTML dialogs, both Html.Dialog or Html.HtmlDialog, that are displayed unexpectedly during playback. If you use this example during playback, it takes precedence over the unexpected window handling settings in the Configure Handling of Unexpected Windows dialog.
public static void closeHtmlBrowserDialogs() {
//Get all domains and search each domain
DomainTestObject domains[] = getDomains();
for (int i = 0; i < domains.length; ++i) {
if (domains[i].getName().equals("Html")) { // Look for the HTML web domain. Once HTML is found, get the top-level test objects.
TestObject[] topLevelObjects = domains[i].getTopObjects();
if (topLevelObjects != null) {
for (int j = 0; j < topLevelObjects.length; ++j) {
String className = null;
try{
className = (String) topLevelObjects[j].getProperty(".class");
} catch (PropertyNotFoundException ex){ // Throw an exception property not found exception
// when the requested get property was not available
ex.printStackTrace(); // print the detailed exception if any
}
// If Html.HtmlDialog or Html.Dialog pop-up windows are displayed during playback, both are handled.
if((className != null) && (className.equalsIgnoreCase("Html.Dialog")
||className.equalsIgnoreCase("Html.HtmlDialog")) )
((TopLevelTestObject) topLevelObjects[j]).close(); // The HTML pop-up window is closed.
}
}
}
}
unregisterAll(); // Clean up any used test objects to prevent memory-related problems.