Tuesday, November 11, 2008

Selenium close all Firefox windows in profile when finish run

There is a Chrome URL parameter &close=true in Selenium-IDE. When set to true, it will automatically close Selenium Firefox windows when finish run. However, if application window has popuped child windows like ads, selenium can't close these popup windows when quit.

This has risk to lock Firefox profile when multiple Firefox profiles running simuteniously. Please refer to "Firefox is aleady running issue"
Enhance Selenium-IDE by XPCOM API: close all Firefox windows under current profile. Add logic when Selenium quit(close=true).
Sample code:
var windowManager = Components
var windowManagerInterface = windowManager
  .QueryInterface( Components.interfaces.nsIWindowMediator);
var enumerator = windowManagerInterface.getEnumerator( null );
var appStartup = Components
while ( enumerator.hasMoreElements()  )
  var domWindow = enumerator.getNext();
  if (("tryToClose" in domWindow) 
       && !domWindow.tryToClose())
    return false;

No comments:

Post a Comment