handling unexpected dialogs - can't make it to work

Ask general questions here.
User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

handling unexpected dialogs - can't make it to work

Post by odklizec » Thu Aug 30, 2012 10:17 am

Hi folks,

While evaluating Ranorex, I have a problem with implementing unexpected dialog/popup handling (as described here).

The problem I'm experiencing is that my implementation of ClosePopUpDialogs (which waits for two separate dialogs) does not work in case there are enabled multiple conditions. If I comment all conditions except one, the remaining one works OK. I'm sure it's something trivial in my dialog handling implementation ;)

And another question, where are stored the screenshots taken by Report.Screenshot(repo.xyz.Self) code used in the ClosePopUpDialogs routine? Is there a way to display these screenshots (with warning) in the main test case report?

Thank you in advance!

Please see the code...

Code: Select all

   
class Program
    {
    	public static QSpectorRepository repo = QSpectorRepository.Instance;
        [STAThread]
        public static int Main(string[] args)
        {
            Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
            int error = 0;						
            try
            {
            	// Creates and starts a new thread  
            	// which handles unexpected dialogs  
            	Thread dialogWatcher = new Thread(ClosePopUpDialogs);  
            	dialogWatcher.IsBackground = true;  
            	dialogWatcher.SetApartmentState(ApartmentState.STA);  
            	dialogWatcher.Start(); 
               error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
            }
            catch (Exception e)
            {
                Report.Error("Unexpected exception occurred: " + e.ToString());
                error = -1;
            }
            return error;
        }
        
        public static void ClosePopUpDialogs()  
	{  
        while (true)  
            {  
            	if (repo.Warning.SelfInfo.Exists() )  
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.Warning.Self);  
                	repo.Warning.Warning3.ButtonOK2.Click();
            	}  
            	if (repo.FileNotSupported.SelfInfo.Exists())  
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.FileNotSupported.Self);  
                	repo.FileNotSupported.FileNotSupported3.ButtonOK2.Click();
            	}  
            	Thread.Sleep(1000);  
    
            }  
    	}  
    }
Pavel Kudrys
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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: handling unexpected dialogs - can't make it to work

Post by odklizec » Thu Aug 30, 2012 1:24 pm

OK small update. I just found that the ClosePopUpDialogs works even with multiple enabled IF conditions. The problem is that it takes way too long from the appearance of the unexpected dialog to its closure. In other words, if there is just one condition enabled, it takes about 1 sec from the dialog appearance to its closure. But if there are two conditions enabled, it takes (for exactly the same dialog) about 23 seconds to its closure. Any idea what could be the reason of such delay?
Pavel Kudrys
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

zator
Posts: 53
Joined: Wed Jul 04, 2012 1:44 pm
Location: Kraków, POLAND

Re: handling unexpected dialogs - can't make it to work

Post by zator » Fri Aug 31, 2012 3:14 pm

Well, i think that every time you invoke Exists() method Ranorex waits time equals to DefaultSearchTimeout value and then goes to next IF statement. Thats why is takes longer than you expected.

Check this out: http://www.ranorex.com/Documentation/Ra ... imeout.htm
and
http://www.ranorex.com/Documentation/Ra ... sts_13.htm

Paweł

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: handling unexpected dialogs - can't make it to work

Post by odklizec » Mon Sep 03, 2012 2:22 pm

Hi Paweł,

Thank you for your help! You are probably right. I tried to debug he ClosePopUpDialogs and it really waits 30 secs (DefaultSearchTimeout) per each IF.

Now the question is, how to overcome this issue? I tried to add Adapter.DefaultSearchTimeout = 1000; right at the ClosePopUpDialogs start (just before the "while" loop) but unfortunately, it does not work. It still waits 30 secs per IF. I also tried to change the Global Settings >> Repository Defaults to 1000ms, but no luck either. Any idea? Ideally, it would be nice if I could set the DefaultSearchTimeout different for ClosePopUpDialogs thread and for main test script. But I guess it's not possible?

Thank you in advance for any suggestion! ;)

Here is my actual ClosePopUpDialogs code:

Code: Select all

        public static void ClosePopUpDialogs()  
		{  
        Adapter.DefaultSearchTimeout = 1000;
        while (true)  
        	{  
            	if (repo.Warning.SelfInfo.Exists() )  
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.Warning.Self);  
                	repo.Warning.Warning3.ButtonOK2.Click();               	
            	}  
            	if (repo.FileNotSupported.SelfInfo.Exists())  
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.FileNotSupported.Self);  
                	repo.FileNotSupported.FileNotSupported3.ButtonOK2.Click();
            	}  
            	if (repo.InsufficientFileversion.SelfInfo.Exists())
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.InsufficientFileversion.Self);  
                	repo.InsufficientFileversion.QWidget5.Abort.Click();
            	}          	
            	Thread.Sleep(1000);  
              	          	
        	}  
    	} 
Pavel Kudrys
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

MarekN
Posts: 4
Joined: Mon May 21, 2012 11:35 am

Re: handling unexpected dialogs - can't make it to work

Post by MarekN » Mon Sep 03, 2012 3:20 pm

There is an article on multi threaded waiting for "expected" dialogs:
http://soft-test-tech.co.uk/2011/09/use ... our-tests/
I am using repeated very short Exists searches in a loop with a common timeout. Funny thing is that, even when I set the timeout for each Exists call to, say, 100ms, it often takes seconds to complete the search. I suspect that accessing repository is rather slow.

mats
Certified Professional
Certified Professional
Posts: 27
Joined: Tue May 18, 2010 12:58 pm

Re: handling unexpected dialogs - can't make it to work

Post by mats » Mon Sep 03, 2012 3:41 pm

As the API documentation for that property points out, the timeout is only used when adapters are searched by assigning a path to an adapter variable.

refer to http://www.ranorex.com/forum/what-defau ... t2054.html

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: handling unexpected dialogs - can't make it to work

Post by artur_gadomski » Tue Sep 04, 2012 6:22 am

Try setting Search Timeout on repository elements you are searching for.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: handling unexpected dialogs - can't make it to work

Post by odklizec » Tue Sep 04, 2012 6:52 am

Thank you for all suggestion guys! I will try to implement them. I will keep you informed.
Pavel Kudrys
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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: handling unexpected dialogs - can't make it to work

Post by odklizec » Thu Sep 06, 2012 7:52 pm

So the solution was as simple as suggested by Artur. Setting short search timeout for repository items helped ;) Thanks again!
Pavel Kudrys
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