How to handle unexpected sign-in dialogs?

Class library usage, coding and language questions.
GeosoftRep
Posts: 6
Joined: Thu May 17, 2012 1:50 pm

How to handle unexpected sign-in dialogs?

Post by GeosoftRep » Thu May 17, 2012 2:03 pm

Hello,
I'll first provide you with this information: Ranorex version is 3.2.3.16825 and OS is Win 7 x64 SP1.

I've followed your tutorial on handling unexpected pop-up dialogs, but the functionality I am looking for now is how to handle a spontaneous appearance of a form that requires signing in, and then handling it. The code snippet for the ClosePopUpDialog() method is as shown below:
public static void ClosePopUpDialog()
		{
			RanorexTrainingRepository repo = new RanorexTrainingRepository();
			while (true)
			{
				if (repo.FormAutosave.SelfInfo.Exists() )
				{
					Thread.Sleep(300);
					Report.Screenshot(repo.FormAutosave.Self);
					repo.FormAutosave.ButtonNo.Click();
				}
				if(repo.FormGeosoft_Connect_Sign_In.SelfInfo.Exists())
				{
					Thread.Sleep(300);
					
					Report.Screenshot(repo.FormGeosoft_Connect_Sign_In.Self);
					
					repo.FormGeosoft_Connect_Sign_In.TextSign_In_with_your_Geosof.Click("293;15");
					
					
					repo.FormGeosoft_Connect_Sign_In.ContainerPART_ContentHost.Click("133;8");
					
					
					repo.FormGeosoft_Connect_Sign_In.TextGeosoftIDBox.PressKeys("email{LShiftKey down}@{LShiftKey up}geosoft.com");
					
					
					repo.FormGeosoft_Connect_Sign_In.ContainerPART_ContentHost1.Click("96;8");
					
					
					repo.FormGeosoft_Connect_Sign_In.TextPasswordBox.PressKeys("password");
					
					
					repo.FormGeosoft_Connect_Sign_In.TextSign_In.Click("22;9");
				}
				
				Thread.Sleep(1000);
				
				
			}
		}
This does not work. The form pops up, yet the test case continues and ignores the form. Yet I've noticed that should the test case be stalled for maybe about 10 seconds (usually because this form wasn't dealt with on time), then it will go ahead and do this ClosePopUpDialog method. I need the functionality to be implemented such that the form is dealt with immediately and the plan is put on hold until it is dealt with

Thank you for your help. A ranorex snapshot of the form is attached.
Attachments
application.zip
(1.58 MiB) Downloaded 261 times

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to handle unexpected sign-in dialogs?

Post by Ciege » Thu May 17, 2012 4:31 pm

Is this sign in dialog really unexpected?
Typically a sign on dialog should only occur in certain places and in certain circumstances, like when you first open the AUT and the user is not logged in. Rather than unexpected is this dialog just a matter of circumstance? Or is it really that the sign on dialog can appear at anytime and anyplace within your AUT?

If it is the former, I would suggest following the path of checking for the sign in dialog in the places that you would expect it to possibly appear. Deal with it if it appears or continue if it doesn't

If it is the latter, I would suspect that the AUT is not designed properly. Would you really expect a user to be working in the AUT and suddenly, unexpectedly and for no reason be presented with a new sign in dialog after they had already properly signed in...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

GeosoftRep
Posts: 6
Joined: Thu May 17, 2012 1:50 pm

Re: How to handle unexpected sign-in dialogs?

Post by GeosoftRep » Thu May 17, 2012 5:27 pm

Ciege wrote:Is this sign in dialog really unexpected?
Typically a sign on dialog should only occur in certain places and in certain circumstances, like when you first open the AUT and the user is not logged in. Rather than unexpected is this dialog just a matter of circumstance? Or is it really that the sign on dialog can appear at anytime and anyplace within your AUT?

If it is the former, I would suggest following the path of checking for the sign in dialog in the places that you would expect it to possibly appear. Deal with it if it appears or continue if it doesn't

If it is the latter, I would suspect that the AUT is not designed properly. Would you really expect a user to be working in the AUT and suddenly, unexpectedly and for no reason be presented with a new sign in dialog after they had already properly signed in...
To your point, there are certain instances where it is expected, in other instances it could be random (loss of internet connection).

In which case I'd wonder if the following were reasonable/possible to implement:
Anywhere the dialog could potentially (expectedly) appear - look for it and handle it before moving to the next part of the Test Plan. But then using the same functionality as with the ClosePopUpDialog method, if it were detected for any reason unexpectedly, that the test plan would close/fail? Does this implementation sound reasonable?

Another question I had is I could only get the recognition of the form to work by placing a Sleep timer in the Init() part of a recording, then using an If statement looking for the form and dealing with it before that recording started. However, I'd rather have an implementation where a while loop or something of the sort runs much like it does in the ClosePopUpDialog() method (once every second) for a maximum of ten repeats, and if it finds the form within those ten seconds it deals with it immediately (rather than waiting 10 in case of detection or no detection). However, trying this implementation in an init step simply freezes the TP at that point. Is there any reasonable way to implement this?

Thank you very much for your help, it is valuable to a new user like myself.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to handle unexpected sign-in dialogs?

Post by Ciege » Thu May 17, 2012 5:49 pm

I would certainly follow the path of implementing the code to deal with the possible dialog in expected scenarios. Such as check for the dialog for 10 seconds (as you put it) if it find it within 10 seconds, deal with it. If it doesn't find it within 10 seconds continue testing...

To truly get to a place where you would be looking for that (or any) dialog anywhere, at any time, you would need to create a second thread in your code that does just the looking for the dialog. If it appears, then have the second thread report to the main thread that the dialog has appeared in an unexpected instance and it should quit testing.

Unless you are specifically planning on writing tests for the fringe cases (such as your example of loss of internet connection) you have probably surpassed the point of diminishing returns. In other words, it is going to probably cost you too much (in terms of time and effort as well as money) to get all those scenarios automated (at this time) rather than doing your automated testing with the expectation that the test environment is stable. That is a determination that you will need to make with your team if it would just make more sense to (occasionally) have a manual tester verify that if they pull the network cable (causing a loss of internet connection) then replace it, does the log in dialog appear as expected (or not expected). This seems like a very fringe case that would be put very low on my list of wants for an automated test suite.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

GeosoftRep
Posts: 6
Joined: Thu May 17, 2012 1:50 pm

Re: How to handle unexpected sign-in dialogs?

Post by GeosoftRep » Thu May 17, 2012 6:49 pm

Ciege wrote:I would certainly follow the path of implementing the code to deal with the possible dialog in expected scenarios. Such as check for the dialog for 10 seconds (as you put it) if it find it within 10 seconds, deal with it. If it doesn't find it within 10 seconds continue testing...

To truly get to a place where you would be looking for that (or any) dialog anywhere, at any time, you would need to create a second thread in your code that does just the looking for the dialog. If it appears, then have the second thread report to the main thread that the dialog has appeared in an unexpected instance and it should quit testing.

Unless you are specifically planning on writing tests for the fringe cases (such as your example of loss of internet connection) you have probably surpassed the point of diminishing returns. In other words, it is going to probably cost you too much (in terms of time and effort as well as money) to get all those scenarios automated (at this time) rather than doing your automated testing with the expectation that the test environment is stable. That is a determination that you will need to make with your team if it would just make more sense to (occasionally) have a manual tester verify that if they pull the network cable (causing a loss of internet connection) then replace it, does the log in dialog appear as expected (or not expected). This seems like a very fringe case that would be put very low on my list of wants for an automated test suite.
Thank you for the continued assistance. I'll take these comments into consideration when implementing a solution.

I agree with most of what you are saying, I suppose the only thing I could think of then to still ask is whether there was any better implementation, in Expected cases, aside from adding a 10 second sleep timer. The while loop method doesn't seem to work:

Code: Select all

private void Init()
{

int count = 0;			
while(count<10)
   {
       if(repo.FormGeosoft_Connect_Sign_In.SelfInfo.Exists())
             {
             OpenMontaj.Start(); 
             break;
             }
       count++;
       Thread.Sleep(1000);
   }

}
vs this, which does work...

Code: Select all

private void Init()
{
			Thread.Sleep(5000);
			if(repo.FormGeosoft_Connect_Sign_In.SelfInfo.Exists())
			{
				OpenMontaj.Start();
			}
}
edit: sorry, had to make some changes. Post is finished with editing.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to handle unexpected sign-in dialogs?

Post by Ciege » Thu May 17, 2012 7:00 pm

Well, I don't use the repository, but I will share with you a code snippet I do use to check for window existence... I just use the FindSingle method with a timeout. If the FindSingle finds the window (or any element for that matter) within the timeout, it starts working on it. If FindSingle does not find that element within the timeout, it throws an exception that you must handle.

This code will search for a form with the title or control name set to the variable WindowName for 10 seconds.

Code: Select all

Ranorex.Form MyForm = Host.Local.FindSingle("/form[@title='" + WindowName + "' or @controlname='" + WindowName + "']", 10000);
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

GeosoftRep
Posts: 6
Joined: Thu May 17, 2012 1:50 pm

Re: How to handle unexpected sign-in dialogs?

Post by GeosoftRep » Thu May 17, 2012 7:05 pm

Ciege wrote:Well, I don't use the repository, but I will share with you a code snippet I do use to check for window existence... I just use the FindSingle method with a timeout. If the FindSingle finds the window (or any element for that matter) within the timeout, it starts working on it. If FindSingle does not find that element within the timeout, it throws an exception that you must handle.

This code will search for a form with the title or control name set to the variable WindowName for 10 seconds.

Code: Select all

Ranorex.Form MyForm = Host.Local.FindSingle("/form[@title='" + WindowName + "' or @controlname='" + WindowName + "']", 10000);
This is something like what I was looking for. For now I am going to say my issues have been resolved, as per your signature.

Thank you.

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to handle unexpected sign-in dialogs?

Post by Ciege » Thu May 17, 2012 7:22 pm

Good deal... If I can be of any more help, feel free to post...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

orbistest
Posts: 23
Joined: Mon Oct 17, 2011 5:31 pm

Re: How to handle unexpected sign-in dialogs?

Post by orbistest » Fri Sep 14, 2012 5:07 pm

I had a similar problem and i found that I could find the item IF it existed and then call the relevant (recorded) user code to fill in the dialog and close it.

The script does what it should; if the dialog exists it fills it and if not just ignores and carries on. You could put this wherever the user may be changing to a form which requires a data query or whatever when the connection might have been broken while viewing previous screen/form.

Anyway, here is the code: -
Public Sub CheckIFLoginExists()
If repo2.MyDialogs.Login.SelfInfo.Exists() then
  Login.Instance.varPassword = Password ' this puts a bound value to the password value in the login script
  Login.Start()
else
  ' no action
end if
The Login script was recorded and then bound to a variable. Then it is removed from the suite.

If this helps let me know.

orbistest
Posts: 23
Joined: Mon Oct 17, 2011 5:31 pm

Re: How to handle unexpected sign-in dialogs?

Post by orbistest » Fri Dec 07, 2012 10:35 am

Just a further question.

I now want to write a user code library function which will check if ANY TYPE of object exists with a particular Ranorex Path and stop the playback if it does.
The closest I got is
Public Sub Verify_Not_Exists(RepositoryObject As String)
Dim bExists As Boolean
bExists = true
Try
Host.Local.FindSingle(Of Ranorex.Unknown)(RepositoryObject)
Catch
bExists = false
End Try
If bExists Then
Throw new Ranorex.ValidationException("The object " & RepositoryObject & " should not exist.")
End If
End Sub
BUT this locks up the playback. I'm guessing its the Ranorex.Unknown which is locking.

I would like a sub which I could pass any Repository Path to it and it will fail the script if this exists.
I could use this to check for error boxes which should not show or , as in previous post, for the login box presence but using the same call with the respective paths, thus I would not need to know the type of the object just the Ranorex Path.

Can someone help me?
Thanks,
orbistest

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

Re: How to handle unexpected sign-in dialogs?

Post by Support Team » Fri Dec 07, 2012 1:22 pm

Hi,

If I got you correctly this should work for you:
Public Sub Verify_Not_Exists(RepositoryObject As String)
Dim bExists As Boolean
bExists = true
Try
Host.Local.FindSingle(RepositoryObject)
Catch
bExists = false
End Try
If bExists Then
Throw new Ranorex.ValidationException("The object " & RepositoryObject & " should not exist.")
End If
End Sub
Regards,
Markus
.
Image