How to exit the recording based on some condition

Ask general questions here.
amrita.thakur123
Posts: 4
Joined: Tue Jun 19, 2018 3:58 am

How to exit the recording based on some condition

Post by amrita.thakur123 » Fri Jul 20, 2018 5:27 am

I am trying to do some validation on the code module level, if the validation passes I want to exit the current recording module( not run the remaining steps) and move to the next module. I don't want to fail the test, I just to skip the remaining steps and move to next module.

I tried using Report.End, which ends the reporting part but the recording is still running. Can someone please share a command or a step which based on return value from the above validation code module ends the running test ?

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: How to exit the recording based on some condition

Post by McTurtle » Tue Jul 24, 2018 1:41 pm

Hello amrita,

Then you can't really use the Validate() method. This method will fail the test case. For example, the following code will validate the attribute "AccessibleName" of the start button. If it equals "Start", then it will end the code method by calling return. If it fails, then it will execute the rest of the code. However, the status of the code method will still be "Failed":
void ITestModule.Run()
        {
        	var repo = AmritaTestRepository.Instance;
        	var start = repo.Explorer.Start;

        	if(Validate.Attribute(start,"AccessibleName","Start","Checking if {1} of {0} equals {2}.",false))
        	{
        		return;
        	}
        	else
        	{
        		//Do the rest of the actions.
        		start.Click();
        		return;
        	}
        }
If you don't use the validate method, but manually compare the values of the attributes, then the status of the code module will not be failed even if the statement withing the brackets after the "if" is false:
void ITestModule.Run()
		{
			var repo = AmritaTestRepository.Instance;
			var start = repo.Explorer.Start;

			if(start.GetAttributeValue<string>("AccessibleName")=="Start")
			{
				Report.Success("Checking if AccessibleName of Start equals Start.");
				return;
			}
			else
			{
				//Do the rest of the actions.
				start.Click();
				return;
			}
 }
Is this what you were looking for?

Regards,
McTurtle

amrita.thakur123
Posts: 4
Joined: Tue Jun 19, 2018 3:58 am

Re: How to exit the recording based on some condition

Post by amrita.thakur123 » Thu Jul 26, 2018 3:26 am

Thanks for your response McTurtle :)

Yes I was looking for something similar. I added the validation I wanted to for my test case and if the validation fails, I am throwing validation exception and in the catch block I explicitly fail the test by using Validate.fail();

I hope that's the right way to do this.