Of course, unit testing won’t work for every situation. In a bot, sometimes we need to perform actions that we don’t want to run over and over every time we want to run our tests. For instance, if your bot creates accounts on some website, you probably don’t want to create a bunch of accounts just for testing purposes. Don’t worry, UBot Studio still has you covered.

The Tao of Flow Testing

Flow testing has a similar purpose to unit testing, but it differs in execution. Flow tests will
occur in the main flow of your script. instead of running them separately, flow tests will run while your bot is running. Let me demonstrate.

We’ll start with our boilerplate code, including our purpose.

F1

Next, we’ll navigate to the account creation form.

 

F2

This is the first spot where we might see a problem. For instance, if your internet is having connectivity issues, or there’s a problem with the server, your bot will never see this form. We can protect against this eventuality by creating a flow test.

f3

By looking for the text “Sample Account Creation Form”, we can know beyond the shadow of a doubt that our page loaded correctly. If our bot fails to find the text it’s looking for, establish will run its child commands. So what should we put in there? We have a few options. We could put a wait command and another navigate in there, so that the bot will simply try again if it fails. We can also pause the script and alert the user to let them know what is happening. For this example, I’m going to use the latter option.

f4

This is a useful option, because if the bot is deep inside some process, it gives us an opportunity to get it back on track instead of letting it break down prematurely. Let’s play the script and see what happens.

UBot Studio 5.5 f5

Lovely! Everything worked without issue, so our establish command did nothing. That’s how we like it. Now I’m going to change the navigate command on purpose, to show you what would happen in case of an error.

UBot Studio 5.5 f6

Our flow test now pauses the script and let’s us know there’s an issue. Great, let’s move on.

UBot Studio 5.5 f8

Isn’t UBot Studio fun? I’ll finish filling these out and have my bot click the submit button.

UBot Studio 5.5 f8

Looks like my bot works like a charm. Of course, in the real world, thing are often less smooth. We want to know with certainty that our bot created the account successfully. Looks like another perfect job for a flow test!

f9

Again, we need to decide what to do if the test fails. We might want to wait 5 minutes and try again. We might want to send an angry email to the website’s technical support (please don’t actually do that). For this example, I’ll again pause the script and alert us to the situation.

 

Let’s give this a final run through and see how it looks.

UBot Studio 5.5 f11

Flow testing provides you with a failsafe, to get your bots back on track if they ever go off course. But note the secondary benefit here as well. Even though our bot ran perfectly, our establish commands are still very helpful. By looking in the log window, we actually have a story of how our bot performed. By seeing all that green, we know that our bot worked perfectly. If we had a very long bot, we could quickly scroll through our log, and if there was a problem. we’ll know immediately what it was and where it happened. You might even want to record information at the moment in question. You could, for instance, take advantage of UBot Studio’s “save browser image” command to see exactly what you bot saw.

 

Download this bot!

 

All in all, these two styles of testing offer your bots the tools to keep them running for longer and with less bugs. Unit tests are a clean and organized solution when you’re testing a piece of code that can be run over and over without issue. Flow tests are perfect for testing on the go, while your bot is working its magic. Good luck in all your ventures, and here’s to many happy, healthy, stable bots.

Published by Seth Turin

Leave a Reply

Your email address will not be published. Required fields are marked *