Firefox switching to Safe Mode when using Ranorex automation

Bug reports.
JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Firefox switching to Safe Mode when using Ranorex automation

Post by JSH_QA » Fri Jul 04, 2014 2:34 pm

Whilst running tests written using the Ranorex API against Mozilla Firefox, an error occur that results in Firefox switching to Safe Mode. It reports the following message:

“Firefox closed unexpectedly while starting. This might be caused by add-ons or other problems. You can try to resolve the problem by resetting Firefox to its default state or troubleshooting in Safe Mode.”

We are using the Ranorex Automation 5.0.3.18203 extension, with Firefox 30.0, running on 64 bit Windows 7.

Is there a known problem with this configuration? If not, is there any detail we can capture from the Ranorex extension or from Firefox that will help identify the cause?

(The same tests do run successfully on Chrome and Internet Explorer).

Many thanks,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by Support Team » Tue Jul 08, 2014 2:09 pm

Hello John,

Unfortunately, we are not aware of any issues related to Firefox 30 and Ranorex 5.0.3. May I ask if it’s possible to provide a small sample which illustrates the mentioned behavior?
Thank you in advance.

Regards,
Robert
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by JSH_QA » Tue Jul 08, 2014 2:14 pm

Hi Robert,

I'll see if I can create a small example. My suspicion is that the problem occurs when the automated test is controlling more than one Firefox instance at a time.

Is there any logging done by the Ranorex plug-in for Firefox that we could look at?

Thanks,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by Support Team » Tue Jul 08, 2014 3:09 pm

Hello John,

It’s possible to enable the internal logging of Ranorex itself (as explained here). May I ask you to send the generated *.log file to [email protected]?

Additionally, you could also check the “Error Console” of your Mozilla Firefox (Tools ->Developer tools -> Console) in order to analyze the issue in more detail.

Regards,
Robert
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by JSH_QA » Wed Jul 09, 2014 10:59 am

Hi Robert,

The following piece of code demonstrates two or three problems:
(1) Without the Delay, a Win32Exception "Access is Denied" is reported.
(2) Even with the Delay, Firefox switches to safe mode, reporting an issue with a plug-in (presumably the Ranorex plug-in)
(3) In our test framework that makes this code generic to work with a configurable browser rather than just Firefox, we find the process id returned from the second OpenBrowser call is not the process id of the browser (this has been confirmed in a separate forum thread).

It would be very useful if all of these could be addressed.

For (1), what is the recommended way of preventing the exception occurring - something that can identify when an OpenBrowser or KillBrowser is fully complete would be better than a Delay that does not actually wait for something to complete, but instead just waits a period of time that slows down test runs. Ideally, OpenBrowser and KillBrowser should only return when they are complete, but we need a reliable and performant workaround in the meantime.

For (2), I would guess that this is a bug in the Ranorex plug-in for Firefox.

For (3), the API documentation needs updating to make clear that the returned process id is not reliable. In the longer term, fixing the value would be even better (or deprecate the current API and replace it with one that does not even attempt to return the pid).

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ranorex;

namespace BrowserTests
{
[TestClass]
public class BrowserTests
{
[TestMethod]
public void OpenAndCloseBrowserMultipleTimes()
{
for (int i = 0; i < 5; i++)
{
Host.Local.OpenBrowser("http://yahoo.com", "firefox", true, true);
Host.Local.OpenBrowser("http://google.com", "firefox", false, true);
Ranorex.Delay.Milliseconds(3000);
Host.Local.KillBrowser("firefox");
}
}
}
}


Thanks,

John H.

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by JSH_QA » Wed Jul 09, 2014 12:53 pm

One clarification - further investigation shows that the Delay does not prevent the problem occurring either.

Regards,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by Support Team » Fri Jul 11, 2014 3:10 pm

Hello Jon,

I was able to reproduce the mentioned behavior even with Ranorex 5.1. The problem is that the browser is not able to fully load the called websites. I have created a small code snippet, which works stable on our side. May I ask you to give it a try on your side as well? Additionally, it would be great if you could give us a short feedback whether it’s working or not. :D

Please find the code below:
//Call OpenBrowser several times
for (int i = 0; i < 5; i++)
{
   Host.Local.OpenBrowser("http://www.yahoo.com", "firefox", false, true)
   WebDocument yahoo = String.Format("/dom[@domain='www.yahoo.com'][{0}]",i+1);
   yahoo.WaitForDocumentLoaded();
   Delay.Seconds(0.5);
			
   Host.Local.OpenBrowser("http://www.google.at", "firefox", false, true)
   WebDocument google =  String.Format("/dom[@domain='www.google.at'][{0}]",i+1);
   google.WaitForDocumentLoaded();
   Delay.Seconds(0.5);	
}
			
//Savely close running FireFox processes/tabs
IList<WebDocument> webDocs  = Host.Local.Find<WebDocument>("/dom[@browsername='Mozilla']");
			
for (int i=0;i < webDocs.Count ;i++ ) {
   webDocs.Close();
}


Regards,
Robert
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by JSH_QA » Tue Jul 15, 2014 12:05 pm

Hi Robert,

That piece of code wasn't doing the same as the original (mine opens two browsers, then closes them, then repeats the whole thing), so I tweaked it to make it as follows:

for (int i = 0; i < 5; i++)
{
Host.Local.OpenBrowser(url1, "firefox", true, true);
WebDocument wd1 = String.Format("/dom[@domain='{0}'][{1}]", domain, 1);
wd1.WaitForDocumentLoaded();
Delay.Seconds(0.5);

Host.Local.OpenBrowser(url2, "firefox", false, true);
WebDocument wd2 = String.Format("/dom[@domain='{0}'][{1}]", domain, 2);
wd2.WaitForDocumentLoaded();
Delay.Seconds(0.5);

IList<WebDocument> webDocs = Host.Local.Find<WebDocument>("/dom[@browsername='Mozilla']");
for (int j = 0; j < webDocs.Count; j++)
{
webDocs[j].Close();
}
}

Even with the Delays present, this still results in Firefox switching to Safe Mode.

Regards,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by Support Team » Fri Jul 18, 2014 2:17 pm

Hello John,

I’m sorry for misinterpreting your requirement. Please ensure that the browser fully loads the requested page before starting the next instance. Additionally, the browser needs to be “completely” closed before opening a new instance of the browser (add short delay when closing browser instances, if the browser is started again right after closing it). If that’s not case the browser instance crashes and you will end up in the “Save Mode” of Firefox. Please find a short sample below:
for(int i = 0;i<5;i++)
			{
				Host.Local.OpenBrowser(url1,"firefox");
				
				WebDocument wd1 = String.Format("/dom[@domain='{0}']", url1);
				wd1.WaitForDocumentLoaded();
				
			    Host.Local.OpenBrowser(url2,"firefox");
				
				WebDocument wd2 = String.Format("/dom[@domain='{0}']", url2);
				wd2.WaitForDocumentLoaded();
				
				wd1.Close();
				wd2.Close();

				string procName = "firefox";
				
				Process[] processes = Process.GetProcessesByName(procName);
				foreach (Process proc in processes)
				{
					proc.CloseMainWindow();
					proc.WaitForExit(1000);
				}
				
			}
Regards,
Robert
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by JSH_QA » Fri Jul 18, 2014 2:24 pm

Thanks Robert.

Is there a reliable way through the Ranorex API of waiting for the browser to close, or reliably identifying if it is not yet closed. Using a fixed Delay is not ideal. It would be better to wait for an event, if possible (at Windows SDK level I would probably wait on a process handle).

Also, if the browser has fully loaded the requested page when WaitForDocumentLoaded() returns, is there any reason to have the Delays after WaitForDocumentLoaded that are shown in your example?

Thanks again,

John H.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by Support Team » Mon Jul 21, 2014 3:28 pm

Hello Jon,

I have updated my sample, please let me if it's working for you.

Regards,
Robert
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by JSH_QA » Tue Jul 22, 2014 4:59 pm

Hi Robert,

Your sample, as written, seems to be ok. However, if I add a third argument to the first OpenBrowser call, setting that third argument to true, the problem then recurs very quickly. I would like to use that third argument to close any instances of the browser that are open when my first test starts.

Can you confirm that the third argument is the trigger for the problem please? If that is the case, I will close any existing instances by a different mechanism before my first test starts.

Thanks again,

John

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by Support Team » Fri Jul 25, 2014 3:08 pm

Hi John,

I've analyzed this behavior on my machine and i can confirm that the "killExisting" argument is the trigger for this problem.

Unfortunately you have to use another method to close the running instances of FireFox

Regards,
Markus (S).
.
Image

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Firefox switching to Safe Mode when using Ranorex automation

Post by JSH_QA » Fri Jul 25, 2014 5:02 pm

Thanks Marcus. I'll remove use of that argument from our code.

Regards,

John H.