Question

Optional buffer in WebService response

  • 15 March 2024
  • 3 replies
  • 21 views

Hi all,

 

following situation: I execute some WebService calls and buffer all related items from the response. Some of them are optional. That means that in some cases I try to buffer item which is not available and my script fails. Is there maybe a way to “mark” it a optinal so that the execution does not fail?

 

Thanks a lot


3 replies

Userlevel 3
Badge +1

It sounds like the design of your test may be too loose if you are trying to buffer things that may or may not be there. e.g. If you don’t want it to fail if those items aren’t there, then why do you need to buffer them at all? If you just want to capture them for evidence/debugging purposes later, you would be better off just logging the entire response.

There are ways of making steps conditional, if they are part of a reusable test step block or a template. That requires you to plan for the variations and test them separately, which should be your aim assuming that both cases warrant testing,

It’s not a loose but how the SUT works. I need to buffer the optionale value because I need to react accoringly. However is there a way to make them optional?

Userlevel 3
Badge +1

It’s not a loose but how the SUT works. I need to buffer the optionale value because I need to react accoringly. However is there a way to make them optional?

OK, if you don’t have a way to control/predict their existence, but you need to handle them when they do exist, it gets a bit more complex but it should be possible.

The basic approach would be to use an If-Then statement. In the Condition, you verify if the elements exist. In the Then, you buffer the values. Depending what action you need to take if they exist and when you need to perform that action, you may be able to do that inside the Then as well, or you might need another If-Then later on, conditional on whether the elements/buffers exist.

This means you are going to need multiple steps to handle the response. One to check if the elements exist, and one to buffer them if they do. (As well as any additional steps to handle any other elements that always get returned.) By default you can’t do this since you can only have one Response step for each Request step with the API engine.

So you have 2 options there:
1. you could repeat the Request each time, if you're sure it will return the same Response each time (e.g. a GET) and it won't take too much time.
2. you can rescan the Response body using the File Scan to create an XML/JSON module. For every step where you need to reuse the initial Response you use this module instead, with the Resource value set to {RES[LastResponseResource]}

So your steps would end up looking something like this:

If
-> Condition
  -> Webservice Request step
  -> Webservice Response step (verify element existence)
-> Then
  -> JSON/XML Response step (buffer element values)

 

Reply