Hi.
I have a problem. I am running HTML test cases on IE 11. I am running Ranorex Studio 5.4.4 (cannot update for the time being) and Windows 7.
At the beginning of my test cases, I would like to:
- check if there is already an instance of IE open on the website I need to test and close it
- start again IE on the website I need to test
How can I achieve this? I am not sure what elements of the page might be present at the beginning, so I would just look for the repo.client, but I do not know how to do this.
Thanks!!!
Close IE before the start
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: Close IE before the start
Hi,
I'm using something like this in my tests (using code module placed in "Setup" section of each TC):
And you need to add this at start of code module:
I'm using something like this in my tests (using code module placed in "Setup" section of each TC):
Code: Select all
try
{
IList<Ranorex.WebDocument> webList = Host.Local.Find<Ranorex.WebDocument>("/dom[@domain='your.domain.name']");
Report.Log(ReportLevel.Info, "Application", "Closing all IE instances.");
foreach (Ranorex.WebDocument webdoc in webList)
{
webdoc.Close();
}
}
catch(Exception exBrowserClose)
{
Report.Warn("An error occured while an attempt to close browser: " + exBrowserClose.ToString());
// try kill iexplore process
try
{
foreach (var procIE in Process.GetProcessesByName("iexplore"))
{
procIE.Kill();
Report.Warn("Process Kill", "Process " + procIE.ToString() + " found and killed.");
}
}
catch(Exception exProcKill)
{
Report.Warn("Process Kill failed", "Process iexplore found but Process Kill failed... " + exProcKill.Message);
}
}
Code: Select all
using System.Diagnostics;
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: Close IE before the start
Thanks! I will try it!!!
Re: Close IE before the start
The easiest way is to use your existing DOM object and check if it exists and then close it.
You don't need the '10000' if you want to use the repo item's default timeout.
I would add " and state='complete'" to your XPath as well as this will help with timing issues.
Code: Select all
if (repo.myDom.SelfInfo.Exists(10000)) repo.myDom.Self.Close();
I would add " and state='complete'" to your XPath as well as this will help with timing issues.
Code: Select all
/dom[@domain='www.mydomain.com' and state='complete']
Shortcuts usually aren't...
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: Close IE before the start
It works! Thanks everyone
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: Close IE before the start
Sorry I'm late to the party, but is there any reason you can't just use the overloads in OpenBrowser?
The first true is the "KillExisting" parameter.
Code: Select all
Host.Local.OpenBrowser(URL, browser,"", True, True, True, False, False)
Doug Vaughan
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
Re: Close IE before the start
Hi!
How does one specify IE as the browser? but it does look interesting, thanks!
How does one specify IE as the browser? but it does look interesting, thanks!
Re: Close IE before the start
Hi,
to giuseppe.lacagnina:
You should replace the "browser" string with browser name (IE, chrome, firefox, etc...)
to Vaughan.Douglas:
Thanks for the info! I'm using OpenBrowser action from recording modules and there is no such option available, so it never occurred to me to even try it from code. I will give it a try and see if it works as expected so I can get rid of my slightly over-complicated code
to giuseppe.lacagnina:
You should replace the "browser" string with browser name (IE, chrome, firefox, etc...)
to Vaughan.Douglas:
Thanks for the info! I'm using OpenBrowser action from recording modules and there is no such option available, so it never occurred to me to even try it from code. I will give it a try and see if it works as expected so I can get rid of my slightly over-complicated code
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
- giuseppe.lacagnina
- Posts: 113
- Joined: Fri Sep 18, 2015 10:25 am
- Location: Brunn am Gebirge, Vienna, Austria
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: Close IE before the start
"browser" is the argument set in the module UI that would carry the specific browser type. I bind this to a global parameter so I can easily change the browser type.giuseppe.lacagnina wrote:Hi!
How does one specify IE as the browser? but it does look interesting, thanks!
Thanks!! I was pretty surprised that the OpenBrowser method contained overload arguments that are not available through the GUI. I strive to create all automation in recorded modules for ease of maintenance by less experienced automation folks, so it is pretty frustrating that I have to convert this method to user code each time someone wants to open a browser.odklizec wrote:Thanks for the info! I'm using OpenBrowser action from recording modules and there is no such option available, so it never occurred to me to even try it from code. I will give it a try and see if it works as expected so I can get rid of my slightly over-complicated code
Also when I do feel the need to break into actual code, I tend to edit the solution in Visual Studio as it gives me more real time information on my code. Although SharpDevelop is coming along.
Doug Vaughan
Re: Close IE before the start
Yeah, I completely forgot about OpenBrowser having the close existing option, and I use it myself...
Nice catch Vaughan!
Nice catch Vaughan!
Shortcuts usually aren't...