How to close browser without abort session

Best practices, code snippets for common functionality, examples, and guidelines.
Sergii.Pankrashyn
Posts: 7
Joined: Mon Sep 10, 2018 9:17 am

How to close browser without abort session

Post by Sergii.Pankrashyn » Mon Sep 10, 2018 9:33 am

Hi folk, I have a question.
Image
In my test the last step is closing browser, for this action I use core merthod

Code: Select all

Host.Current.CloseApplication(repo.CmdHtml.Self, 1000);
and my browser shows me alert with approving close page website, Ranorex close browser with forcing and next opening browser start with alert in restore session
Image
How in this case close browser correct?
You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to close browser without abort session

Post by Support Team » Tue Sep 11, 2018 9:38 pm

Hi Sergii,

Here are two options to handle this scenario:
  • Use KillApplication instead. The downside to this is that it will close any other tabs open and not allow the browser to shut down properly.

    Code: Select all

    Host.Current.KillApplication(repo.MyAUT.Self);
  • After using the CloseApplication action, click the button in the prompt preventing the browser from closing (just a user would need to). Note, this could be implemented as a popup watcher if you cannot predict when message box occurs.

    Code: Select all

    Host.Current.CloseApplication(repo.MyAUT.Self, new Duration(0));
    repo.ChromeForm.Leave.Click();
    
    repo.ChromeForm.Leave:

    Code: Select all

    /form[@processname='chrome']//button[@accessiblename='Leave']
I hope this helps!

Cheers,
Ned