Many a times when working with Oracle EBS forms, automation test engineer wants to bring forms to base state and continue with next steps, this can be achieved very easily using OATS. There is an api given as part of forms object, which is getAllOpenWindows(), this method in forms returns List of AbstractWindows, you can write a for loop to navigate through all windows and check if the name attribute is not navigator and close all the forms other than navigator.
For users convenience we are giving a ready made function for the above purpose.
Code Snippet for bringing Oracle EBS Forms to Base state by closing all open windows except for Navigator Window
public void formsBaseState() throws Exception
// get all open windows in the current state of execution
//iterate through all windows and close all the windows except for the navigator window
// check if the current window is not a navigator window
if(allwindows[i].getAttribute("name")!=null && !allwindows[i].getAttribute("name").equals("NAVIGATOR"))
Note: the above code snippet works for a pure positive case when there wont be any issues in closing each window, you could add additional code to handle situations where windows like Caution Window / Alert Window / Decision Window might appear whenever each window is closed. Just make sure that the function may not get delayed.