Closing active browsers before playback

You can use the dynamic find() API to find and close all active browsers before you play back a script to ensure that there are no active browser instances before playback.
This example shows you how to use the dynamic find() API to search through the active domains, find all active instances of the Microsoft Internet Explorer browser and close them. You can also modify this example to find and close active Mozilla Firefox browsers.
	public void closeAllBrowsers() {
		DomainTestObject dom[] = getDomains(); // Get all domains
		for (int i = 0; i < dom.length; i++) {
			try {
				String s = (dom[i].getImplementationName()).toString();
				if ("MS Internet Explorer".equals(s)) { // If browser name equals MS Internet Explorer
					(dom[i].getProcess()).kill(); // Shut down the process 
			} catch (TargetGoneException e) {

			unregisterAll(); // Ensure that you clean up the used test objects to prevent memory-related problems.
You can also use the dynamic find() API to directly find and close active instances of active browsers (Microsoft Internet Explorer or Mozilla Firefox), as shown in this example:
public void closeAllBrowserUsingfind(){
	// Find browser objects using the HCL OneTest UI find function and store into test object
	TestObject[] browsers = find(atChild(".class", "Html.HtmlBrowser"));
	if(browsers.length ==0){ 
		System.out.println("Found no Html.HtmlBrowser");

	// Close each browser object found, after casting it to a BrowserTestObject
	for (TestObject browser:browsers) {
	    ((com.rational.test.ft.object.interfaces.BrowserTestObject) browser).close();

	// Unregister the test objects. 

The two examples shown above can be used as utility functions in a script helper superclass. For more information about script helper superclasses, see Script helper superclass/base class.