Advanced Virtual User design

This third OctoPerf’s tutorial guides you trough the following steps:

  1. Validating a server HTTP response using a Response Assertion,
  2. Make your Virtual User even more realistic thanks to Login actions:

    • Flow Control containers: lets you control how often the contained actions are executed,
    • If containers: to control whether the actions below it (its children) are run or not,
    • For Each containers: to loop through the values of a input variable and execute children Action for each successive value,
  3. Validating the Virtual User and looking at the many server responses for a single HTTP Request in a loop.

Transcript

0s

Hello and welcome to this third tutorial video.

3s

This is still Guillaume speaking and today we will have a look at an advanced user design.

8s

We will start over from where we left last time, with our petstore user we created using datasets and correlations.

16s

We've seen after the validation that the HTTP response code will be automatically checked, but that's not always enough.

23s

In particular when the response code is OK (200, 302, etc ...) but in some part of the page there is an error message.

32s

This is when Assertions are useful.

35s

An assertion works quite like a regex, we just drag and drop it on a request.

40s

Then we can use the search feature to locate the text to validate.

44s

And we just have to select it for the assertion to be created.

48s

In case we want to do more, the advanced tab lets us control several values, or control that there isn't a particular text like an error message.

58s

And at runtime, this assertion will of course let us know in case it fails.

63s

Next, I propose we make this user a bit more realistic using some logic actions.

69s

For instance as we are dealing with a webstore we know that the conversion rate is not 100%

76s

meaning not all visitors will end up purchasing a product.

80s

The flow control allows us to run a particular section of the virtual user only a fraction of the time.

86s

So in our case let's say we run the cart validation and purchase only 10% of the time.

93s

We have to drag and drop the Flow control here, then we put inside it the actions we want to run only 10 percent of the time.

102s

We now specify only 10 percent instead of 50.

106s

Ok, this is a great first step, we can also make sure that the login went well before we continue with the purchase.

112s

To do so let's first identify what makes a succesful login.

117s

Back to the application, if we login again, we can see that on the first page there is a welcome message.

123s

Now if we try to do unsuccessful login we notice an error message instead and no welcome message of course.

132s

It means we can do this two ways, either search for the welcome message or make sure the error message is not there.

139s

To do that we will use a regexp post processor again.

143s

From what I remember our login attempt was successful when we recorded,

147s

we will then search for the welcome message to find out which response contains it.

155s

Now that we have identified it we can add the regexp, proceed to extract the welcome message and call it loginOk.

171s

The way regexp work is that if they can't find the pattern, they will take the default value instead which in our case is "NotFound".

180s

So now we just have to add a If logic action, put all the rest of the virtual user inside it and use the following condition:

195s

If "${loginOk}" != "NotFound", note how I used the double quotes because we are comparing strings.

205s

For integers the syntax is the same with no double quotes, this is of course all detailed in our documentation.

212s

So if loginOk can extract the welcome message then we continue because we are logged in.

218s

That's a good way to make sure we don't generate errors on the application because our user continues where it should not.

225s

Another interesting step on this application would be to purchase not only one but several products picked randomly.

232s

To do that we must first locate the moment we add a product to the cart.

236s

Thankfully the request is easy to identify thanks to its path and as a parameter it sends the ID of the product.

245s

First we must find out in which response we can find this productID using the search.

256s

Now we are also going to use a regex to extract all the products in the page and add them to the cart.

263s

The regexp definition is the same as usual, we'll call it products but then we will ask to extract all occurrences.

278s

In the check we can clearly see the different values extracted.

283s

Now to loop on all these values, let's put the add to cart section in a For Each loop.

289s

The foreach loop needs to know from which regex or variable to extract the values, which would be products in our case.

297s

Note that since the input is always a variable there is no need for ${} in here.

303s

Now for the working variable that we will use at every iteration of the loop, let's call it product.

310s

The last step is to replace the static productId with our product working variable, whose value will change everytime the loop runs.

319s

Now before we finish, a validation is in order to make sure this all works fine.

324s

But just before that I will switch the flow control back to 100% to be sure we run all the virtual user.

332s

I will fast forward a bit to the moment when the validation is finished.

340s

Now we see from the green dots that the validation has run the entire user with no issues.

346s

This means that the login was successful, also if we look at the add to cart request,

352s

in the response section we have several responses in the list.

355s

One response for each time the loop ran, which is a good sign.

359s

I will just put the flow control back to 10% and we are now ready to run a test with this virtual user.

365s

This tutorial is now finished, I hope it was helpful!

369s

Feel free to comment if anything is unclear and keep in mind the build in chat is the shortest way to us for any question.

376s

Next time we will talk about how to install an on-premise agent prior to the test.

381s

Thanks for watching, take care, bye.