How to close all windows

Class library usage, coding and language questions.
generalecaster
Posts: 20
Joined: Thu May 09, 2013 10:44 am

How to close all windows

Post by generalecaster » Tue Jul 23, 2013 10:31 am

Hi all,

I'm using Ranorex ver. 4.0.4 for my automation test.
We have a web application witch open popups to fill some fields (for other information).
I'm wondering if there is a way to close all windows on fail.
Can someone help me?

Thanx
Max

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to close all windows

Post by Ciege » Tue Jul 23, 2013 4:15 pm

You could get an IList of all Forms on the Host, then loop that list closing each.

Make a Google search of this "c# close all open windows" and you will get many other answers to your question.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

generalecaster
Posts: 20
Joined: Thu May 09, 2013 10:44 am

Re: How to close all windows

Post by generalecaster » Tue Jul 23, 2013 4:23 pm

thanx a lot ... :D
I'll try immediately

generalecaster
Posts: 20
Joined: Thu May 09, 2013 10:44 am

Re: How to close all windows

Post by generalecaster » Wed Jul 24, 2013 10:59 am

ok, now I have this method in my test:

Code: Select all

private void closeAllWindows()
{
    System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName(browser);
    for (int i=0; i<process.Length; i++)
    {
        try
        {
            System.Diagnostics.Process p = (System.Diagnostics.Process)process.GetValue(i);
            p.Kill();
            p.WaitForExit(); // possibly with a timeout
        }catch (Exception e){
            Report.Error(e.StackTrace);
        }
    }
}
it works, but it kill process bound to my browser (we have a multi-browser application).
It's fine, but now, on error, the error behavior, setted on "Continue with iteration", is not working.
It's because I don't invoke the "Close Application" on my teardown anymore?!?

tnx
Max

mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: How to close all windows

Post by mzperix » Thu Aug 08, 2013 3:50 pm

You can try to use xpath to search for the open browser windows, and use the close method on them.

Code: Select all

        	
IList<Ranorex.WebDocument> webList = Host.Local.Find<Ranorex.WebDocument>("/dom[@dom='yoursite']");
			
foreach (Ranorex.WebDocument webdoc in webList)
{  
    webdoc.Close();
}

generalecaster
Posts: 20
Joined: Thu May 09, 2013 10:44 am

Re: How to close all windows

Post by generalecaster » Thu Aug 08, 2013 4:09 pm

wow ... it seems to be better ...

I'll try then I'll tell you

Thanx
Max