Page 1 of 1

Conditional pass/failure within recording

Posted: Wed Aug 29, 2018 3:42 pm
by seurrep
I have some UserCodeMethods to test a web API. The functions are returning the status of the response as well as the response body acceptably. What isn't clear (to me anyway) is how I can get ranorex to register either a pass or failure within a recording by testing a local variable value that has been passed back from the method and also specify which value constitutes success since this can change from one test to another.

For example if I'm testing whether something is invalid because of lack of valid credentials being passed (intentionally in this case) then 403 would constitute a pass whereas in tests where all parameters are valid something like 200 would normally be expected.

Re: Conditional pass/failure within recording

Posted: Wed Aug 29, 2018 8:32 pm
by N612
Typically, I advise staying out of code when possible, but for this scenario, I think doing it in code is the easiest.

If you want to report the pass/fail but don't want to actually throw an exception, then use Report.Success("Success!")/Report.Failure("Failed!").

If you want to cause a real failure and have the test container error behavior go into effect, then throw an exception (i.e. throw new ValidationException()). If you are validating something, then I recommend using the Validate class (such as Validate.AreEqual).

As always, there are 100 ways to do this, but I would keep it simple and implement something like the below.

Code: Select all

Validate.AreEqual(ServerResponse, ExpectedResponse);

Re: Conditional pass/failure within recording

Posted: Thu Aug 30, 2018 8:30 am
by Stub
I don't use Recordings but I fragment my Code Modules up such that I can do something then separately validate the anticipated success or failure. I mean that I split my actions and success/failure validation into multiple separate Code Modules so I can drop in whichever one is appropriate to the test that I'm building in the Ranorex Test Suite.