Conditional pass/failure within recording

Ranorex Spy, Recorder, and Studio.
Posts: 41
Joined: Tue Aug 07, 2018 10:19 am

Conditional pass/failure within recording

Post by seurrep » Wed Aug 29, 2018 3:42 pm

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.

User avatar
Posts: 135
Joined: Mon Jul 11, 2016 4:01 pm

Re: Conditional pass/failure within recording

Post by N612 » Wed Aug 29, 2018 8:32 pm

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);

User avatar
Posts: 439
Joined: Fri Jul 15, 2016 1:35 pm

Re: Conditional pass/failure within recording

Post by Stub » Thu Aug 30, 2018 8:30 am

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.