locked
Close All IE Browsers to clear/clean desktop of windows RRS feed

  • Question

  • I am trying to figure out a way of closing all open browsers in a Coded UI Test on a desktop.

    Image you want to start a test on a test agent and you want to ensure the agents desktop is at as clean/clear state as possible. How can you locate all IE browsers and close them ALL irrespective of what state the browser is (minimised/maximised) or what page it is on. I understand how to use search criteria to locate a specific browser but in this case i don't want to have to care about specific browsers.

    Thanks
    Wednesday, February 17, 2010 11:18 AM

Answers

  • Try out following code in your Test Init. (note this won't work if you have multiple tabs opened in same browser)

    BrowserWindow
    window = new BrowserWindow();
    window.SearchProperties[
    BrowserWindow.PropertyNames.ClassName] = "IEFrame"; 

    UITestControlCollection windows = window.FindMatchingControls();  

    foreach (UITestControl control in windows)
    { 
    if (control is BrowserWindow)
    {
    ((
    BrowserWindow)control).Close();
    }
    }

     

    • Proposed as answer by Aditya_msft Wednesday, February 17, 2010 12:15 PM
    • Marked as answer by Madmaximillion Wednesday, February 17, 2010 1:54 PM
    Wednesday, February 17, 2010 12:13 PM

All replies

  • Try out following code in your Test Init. (note this won't work if you have multiple tabs opened in same browser)

    BrowserWindow
    window = new BrowserWindow();
    window.SearchProperties[
    BrowserWindow.PropertyNames.ClassName] = "IEFrame"; 

    UITestControlCollection windows = window.FindMatchingControls();  

    foreach (UITestControl control in windows)
    { 
    if (control is BrowserWindow)
    {
    ((
    BrowserWindow)control).Close();
    }
    }

     

    • Proposed as answer by Aditya_msft Wednesday, February 17, 2010 12:15 PM
    • Marked as answer by Madmaximillion Wednesday, February 17, 2010 1:54 PM
    Wednesday, February 17, 2010 12:13 PM
  • Thank you.

    I believe that what you have put is not for Beta 2 version which we are still working with but i was able to adapt and reproduced the following with a small tweak:

     

     

     

    BrowserWindow window = new BrowserWindow(); 
    window.SearchProperties[
     
    UITestControlProperties.Common.ClassName] = "IEFrame"; 
     
    UITestControlCollection windows = window.FindMatchingControls(); 
      
    foreach (UITestControl control in windows) 
    {
    if (control is BrowserWindow) 
    {
    ((BrowserWindow)control).Close(); 
    }
    }

     

    Wednesday, February 17, 2010 1:56 PM