How to handle repeated dialog.

Ask general questions here.
User avatar
felixk91
Posts: 20
Joined: Wed Feb 10, 2016 11:16 pm

How to handle repeated dialog.

Post by felixk91 » Wed Mar 11, 2020 11:48 pm

Hi everyone,

I have test that got repeatable steps which is depending of result of one step.
Test flow as following:
1. Open designer
2. Run design
3a. If warning dialog for validation errors appeared and yes button is disabled:
  • click OK button
    resolve validation errors
    repeat step 2
3b, If warning dialog for validation errors appeared and yes button is enabled click Yes button
4. finish design

Right now I inherited the following code for step 3:
Code:
        public static void doDesignValidationRoutine(string strModule, string strName)
        {
        	
			string buttonBasePath="/form[@title>'{0}']/?/?/?/?/?/button[@text='{1}' and @visible='True']";
			
        	try
        	{
        		string strYesButton = string.Format(buttonBasePath,"Design validation","&Yes");
        		Element menuItem = Host.Local.FindSingle(strYesButton,10000);
        		
	        	if(menuItem.Enabled)
	        	{
	        		Mouse.Click(menuItem);
	        		
	        		//disabled button, go rerun the
					buttonBasePath="/form[@title>'{0}']/?/?/?/?/?/button[@text='{1}' and @visible='True']";
					string strNoButton = string.Format(buttonBasePath,"Design validation","&Yes");
					if(Host.Local.TryFindSingle(strNoButton, 10000, out menuItem))
                    {
                    	Mouse.Click(menuItem);	  	
                  	}
	        	}
	        	else
	        	{
	        		//disabled button, go rerun the
					buttonBasePath="/form[@title>'{0}']/?/?/?/?/?/button[@text='{1}' and @visible='True']";
					string strNoButton = string.Format(buttonBasePath,"Design validation","&No");
		        	menuItem = Host.Local.FindSingle(strNoButton,10000);   
					Mouse.Click(menuItem);	

					clickShowLowPriorityValidations(strLayoutModule, strJobName);
					tickWarningValidations(strLayoutModule, strJobName);
					
					//recursive, so good luck
					doDesignValidationRoutine(strLayoutModule, strJobName);
	        	}	
        	}
        	catch
        	{
        		
        	}
        }
code
I don't like idea of using recursive function.
Could someone give me better idea how I should handle this.
All ideas are highly appreciated.

Thanks,
Felix.

User avatar
Stub
Posts: 373
Joined: Fri Jul 15, 2016 1:35 pm

Re: How to handle repeated dialog.

Post by Stub » Thu Mar 12, 2020 9:21 am

Is it possible to break up each step into a set of much smaller, more precise functions that you can re-use?

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

Re: How to handle repeated dialog.

Post by odklizec » Thu Mar 12, 2020 9:49 am

Hi,

Could you please post a Ranorex snapshot of the dialog, ideally, post snapshots of both states. Also, what's inside strModule and strName? Thanks.

The first thing I would suggest, is to avoid hardcoded xpaths in code. It's way better to pass RepoItemInfo to method. This will make your method much more stable and reliable in long term use. So the method should look like this:

Code: Select all

public static void doDesignValidationRoutine(string strModule, string strName, RepoItemInfo repoElement)   
{
    string strYesButton =repoElement.AbsolutePath;
...
}
Now please post the snapshots, so we can eventually suggest other improvements. Thanks.
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
felixk91
Posts: 20
Joined: Wed Feb 10, 2016 11:16 pm

Re: How to handle repeated dialog.

Post by felixk91 » Fri Mar 13, 2020 4:30 am

Hi everyone,

I attached snapshot of this dialog.
Parameter strModule contains string with form title where design is happening and strName contains string with job design name which can be part of title.

This dialog wasn't included within repository when I inherited it. So, most of modules contains "User code" actions and actual object repository wasn't used.

Thanks,
Felix.
Attachments
ValidationDialogSnapshot.rxsnp
(17.29 KiB) Downloaded 3 times

User avatar
felixk91
Posts: 20
Joined: Wed Feb 10, 2016 11:16 pm

Re: How to handle repeated dialog.

Post by felixk91 » Fri Mar 13, 2020 4:37 am

Hi Stub,
Stub wrote:
Thu Mar 12, 2020 9:21 am
Is it possible to break up each step into a set of much smaller, more precise functions that you can re-use?
Unfortunately, I can't make it happen due to nature of user operations flow.