simple loop with validation

Class library usage, coding and language questions.
ecohen
Posts: 17
Joined: Thu May 09, 2013 10:42 am

simple loop with validation

Post by ecohen » Tue Jun 18, 2013 5:53 pm

hi i trying to do a very simple loop but i don't know exactly how.
my goal is to refresh a web page and check if specific text exists (validation) and if the validation fails i want the record to go out of the loop and proccess the next recording.
this is the basic user code i'm getting after convert this two steps
public partial class Recording2
{
/// <summary>
/// This method gets called right after the recording has been started.
/// It can be used to execute recording specific initialization code.
/// </summary>
private void Init()
{
// Your recording specific initialization code goes here.
}

public void Key_Sequence2()
{
}

public void Validate_SignUpHereForInformationOnUpcoming()
{
}

public void Validate_SignUpHereForInformationOnUpcoming2()
{
Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'NBAFinalsMiamiHeatVsSanAntonioSp.SignUpHereForInformationOnUpcoming'.", repo.NBAFinalsMiamiHeatVsSanAntonioSp.SignUpHereForInformationOnUpcomingInfo);
Validate.Exists(repo.NBAFinalsMiamiHeatVsSanAntonioSp.SignUpHereForInformationOnUpcomingInfo);
}

public void Key_Sequence3()
{
Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '{F5}'.");
Keyboard.Press("{F5}");
}

public void Key_Sequence()
{
Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '{F5}'.");
Keyboard.Press("{F5}");
}

public void MergedUserCodeMethod()
{
#region --- Merged from "Key_Sequence()" ---
Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '{F5}'.");
Keyboard.Press("{F5}");
#endregion
#region --- Merged from "Key_Sequence3()" ---
Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '{F5}'.");
Keyboard.Press("{F5}");
#endregion
#region --- Merged from "Validate_SignUpHereForInformationOnUpcoming2()" ---
Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'NBAFinalsMiamiHeatVsSanAntonioSp.SignUpHereForInformationOnUpcoming'.", repo.NBAFinalsMiamiHeatVsSanAntonioSp.SignUpHereForInformationOnUpcomingInfo);
Validate.Exists(repo.NBAFinalsMiamiHeatVsSanAntonioSp.SignUpHereForInformationOnUpcomingInfo);
#endregion

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: simple loop with validation

Post by Support Team » Thu Jun 20, 2013 4:34 pm

Hello,

In general, we don't recommend to change the workflow of a Test Case.

You could use the Validation.Exists() (see API documentation) method to return a boolean value and start the Recording again if the validation succeeded. Please take a look at the short example below:
bool validate = Validate.Exists(repo.Calculator.SelfInfo, "Validate Page", false);
if (validate)
{
	Recording1.Start();
}
Regards,
Markus (T)

ecohen
Posts: 17
Joined: Thu May 09, 2013 10:42 am

Re: simple loop with validation

Post by ecohen » Mon Jun 24, 2013 4:31 pm

ok
what do i have to put in the string value? you wrote "Validate Page" but i need to validate only if some repository item exists

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: simple loop with validation

Post by Support Team » Tue Jun 25, 2013 1:50 pm

Hello,

The string 'Validate Page' is just the message that is shown in the report.
You could rename it to whatever you want.

The important part of the method is the RepoItemInfo object that you want to validate.
In the following example, a button is validated:
bool validate = Validate.Exists(repo.Calculator.Button135Info, "Validate Button", false);
Regards,
Markus (T)