Page 1 of 1

How to close browser?

Posted: Fri Feb 01, 2013 8:22 pm
by yinghu
Hi folks,

Long time no see.:)

I am doing automation test using Ranorex APIs. Now I have a problem about closing browser windows.

Here attachment is the screenshot I got when I ran my test in Visual Studio.

Thanks alot in advance!

yinghu

Re: How to close browser?

Posted: Fri Feb 01, 2013 8:31 pm
by Ciege
How about just use

Code: Select all

wd.close
.
You should probably put it in a try/catch block to catch and handle any exceptions just in case.

Re: How to close browser?

Posted: Fri Feb 01, 2013 8:41 pm
by yinghu
Thanks for your quick reply and mentioning try/catch thing!

I just tried "wd.Close();" and it failed same as the previous screenshot I uploaded.

Ciege wrote:How about just use

Code: Select all

wd.close
.
You should probably put it in a try/catch block to catch and handle any exceptions just in case.

Re: How to close browser?

Posted: Mon Feb 04, 2013 6:22 pm
by Support Team
Hello,

Which version of Ranorex do are you using?
Here is a little code snippet which works as expected.
Host.Local.OpenBrowser("http://www.ranorex.com", "IE");
Delay.Seconds(3);
Ranorex.WebDocument wd = Host.Local.FindSingle<Ranorex.WebDocument>("/dom[@domain='www.ranorex.com' and @caption='Test Automation Tools - Ranorex Automation Framework']");
Validate.Exists(wd.GetPath());
//Host.Local.CloseApplication(wd, new Duration(0));
wd.Close();
You can use "CloseApplication" or "Close". Both of them work.
Which domain do you use to open the browser? It could be that you use e.g. http://www.yyy.com to open the browser and yyy.com to close it. Please check the RxPath of the element.

Regards,
Bernhard

Re: How to close browser?

Posted: Mon Feb 04, 2013 10:23 pm
by yinghu
I tried all the things you mentioned. There is no luck for me. I still got the same exception as before.

My Ranorex's version is 4.0.



Support Team wrote:Hello,

Which version of Ranorex do are you using?
Here is a little code snippet which works as expected.
Host.Local.OpenBrowser("http://www.ranorex.com", "IE");
Delay.Seconds(3);
Ranorex.WebDocument wd = Host.Local.FindSingle<Ranorex.WebDocument>("/dom[@domain='www.ranorex.com' and @caption='Test Automation Tools - Ranorex Automation Framework']");
Validate.Exists(wd.GetPath());
//Host.Local.CloseApplication(wd, new Duration(0));
wd.Close();
You can use "CloseApplication" or "Close". Both of them work.
Which domain do you use to open the browser? It could be that you use e.g. http://www.yyy.com to open the browser and yyy.com to close it. Please check the RxPath of the element.

Regards,
Bernhard

Re: How to close browser?

Posted: Tue Feb 05, 2013 9:51 am
by sdaly

Re: How to close browser?

Posted: Wed Feb 06, 2013 5:47 pm
by yinghu
Thanks alot for your link!

Unfortunately, it still can't close the browser.
sdaly wrote:Could be similar to this - http://www.ranorex.com/forum/browser-cl ... t3306.html

Re: How to close browser?

Posted: Thu Feb 07, 2013 5:47 pm
by Support Team
Hello,

Could you please explain exactly what you are doing in your code?
Additionally please check with Ranorex Spy if the path to the web document you are trying to close is correct.
Thank you!

Regards,
Bernhard

Re: How to close browser?

Posted: Thu Feb 07, 2013 7:30 pm
by yinghu
Actually, I track the web document path by Spy, it does exist. And this "browser" is a POPUP window which opened by javascript basically like:


<script type="text/javascript">function LoadSiteManager(){
if (GetCookie('UserID') == '') {
SetCookie('RedirectTo', '../Section/Section.aspx?DomainId=1090');
window.open("http://test.auto.schoolwires.com/defaul ... 7&SiteID=1", "sitemanager2", "status=1, toolbar=0, location=0, menubar=0, width=" + (screen.width < 1025 ? (screen.width - 5) : 1200) + ", height=" + (screen.height - 50) + ", top=0, left=0, resizable=1, scrollbars=1");
} else {
window.open("../Section/Section.aspx?DomainId=1090", "sitemanager2", "status=1, toolbar=0, location=0, menubar=0, width=" + (screen.width < 1025 ? (screen.width - 5) : 1200) + ", height=" + (screen.height - 50) + ", top=0, left=0, resizable=1, scrollbars=1");
}
}
</script>

Thanks!

Support Team wrote:Hello,

Could you please explain exactly what you are doing in your code?
Additionally please check with Ranorex Spy if the path to the web document you are trying to close is correct.
Thank you!

Regards,
Bernhard

Re: How to close browser?

Posted: Thu Feb 07, 2013 8:06 pm
by Support Team
Could you also post the complete exception message (text + stacktrace) that you get when you call Close on the window? In the screenshot you posted, you can only see the first line of the exception text.
Thank you!

Regards,
Alex
Ranorex Team

Re: How to close browser?

Posted: Mon Jan 20, 2014 1:38 pm
by Dinin
Hi Alex,

I also met with this problem. If you open a browser window from another browser - try to click any link with press CTRL button - and if it found by RR, the close() method will fail and the workarounds - mentioned here - also won't work.

Thanks

Laszlo

Re: How to close browser?

Posted: Mon Jan 20, 2014 5:08 pm
by Dinin
Hello,

I have now a quick and dirty solution which work in my case (browser window opened from another browser with CTRL+click a link). Before this I tried to call the Close method of the WebDocument.

Please let me know your experience about this:

Code: Select all

                Form f  = null;
                if (this.windowTestObject.GetType() == typeof(Ranorex.WebDocument))
                {
                    f = ((Ranorex.WebDocument)this.windowTestObject).Browser;
                } else if (windowTestObject.GetType() == typeof(Ranorex.Form)){
                    f = (Form)this.windowTestObject;
                }
                    PopupWatcher closePopupWatcher = new PopupWatcher();
                    closePopupWatcher.Watch(f.GetPath(), CloseUpdateCheckDialog);
                    closePopupWatcher.Start();
                    f.Close();
            }
....

        //Popup Closer
        public static void CloseUpdateCheckDialog(Ranorex.Core.RxPath myPath, Ranorex.Core.Element parentElement)
        {
            int processId = ((Ranorex.NativeWindow)parentElement).ProcessId;
            Process proc = Process.GetProcessById(processId);
            proc.Kill();            
        } 


Re: How to close browser?

Posted: Wed Jan 22, 2014 5:23 pm
by rprehm
Hello Dinin,

Please make sure that you have tracked the proper DOM object. The solution from “sdaly” (browser close icon) works brilliant in all of my cases.

Try to implement “CloseWithRetryOnFail()” within your project. That will resolve your issue. Many thanks again to “sdaly”.

Regards,
Robert