How to Validate Time Gaps

Class library usage, coding and language questions.
martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

How to Validate Time Gaps

Post by martinsw » Mon Dec 12, 2011 2:28 pm

Hi,

My SUT has a diary page which can either be in 30 minute mode or 1 hour mode. When in 30 minute mode there is a gap of 30 mins between each of the TRs in the table body. See below:

TR1 12am
TR2 (no innertext)
TR3 1am
TR4 (no innertext)
TR5 2am
etc...etc...

When the diary is in 1 hour mode there is a gap of 1 hour between each TR, see below:

TR1 12am
TR2 (no innertext)
TR3 2am
TR4 (no innertext)
TR5 4am
etc...etc...

What I need to do is set up a test that will validate that the diary is in 1 hour mode when the user selects that this should be the case. This would be an easy test to create if the starting point of the diary was always 12AM (in such a case I would just validate that TR3 equals 2am, or that TR5 equals 4am) but it won't be. The start time will be dependent on the start time of the user's first appointment (i.e. it will change all the time). Hence, what I need to check is that the innertext value of TR3 is 2 hours more than the innertext value in TR1. But the inner text of TR1 will not be known until runtime. Is there a way I can do this? If not, can you suggest another means by which I can test this scenario?

Thanks in advance.

Martin
You do not have the required permissions to view the files attached to this post.

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: How to Validate Time Gaps

Post by sdaly » Mon Dec 12, 2011 3:39 pm

How about something like this -

Code: Select all

Validate.IsTrue(GetInterval() == 1, "Validating diary is in 1 hour mode.");

		public static int GetInterval(){
			IList<DivTag> times = Host.Local.Find<DivTag>("/dom//div//th//div[@innertext!='all day']");
			
			int diff = 0;
			if(times.Count > 2){
				int time1 = int.Parse(times[0].InnerText);
				int time2 = int.Parse(times[1].InnerText);
				diff = time2 - time1;
			}
			
			return diff;
		}

martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

Re: How to Validate Time Gaps

Post by martinsw » Mon Dec 12, 2011 5:02 pm

Thanks for the response.

I should have said, is there anyway to create this diary test soley through the use of the Ranorex GUI tools rather than having to write a piece of user code? I want to try and avoid manipulating user code if at all possible.

Thanks!

Martin

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: How to Validate Time Gaps

Post by sdaly » Tue Dec 13, 2011 9:15 am

It is possible - you would prob have to restore your DB to a known state in your global set up then use a known user where you know what their start time is. If you want to do any clever dynamic things, you are going to have to learn a bit of programming imo....that is automation!

martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

Re: How to Validate Time Gaps

Post by martinsw » Thu Dec 15, 2011 10:33 am

OK Many thanks! :D