Conditional Logic (if/else)

Why use conditional logic?

Tests should be independent, repeatable, and consistent. That's the theory. Practice sometimes is a bit trickier.

Example scenario

Let's say your app limits user sessions to one per e-mail address. If something breaks and you do not log out properly from the app via the Logout action, the next login will show you that another session exists, and you have to click "Force" to log in and ignore the existing one.

This is an exact example we had with one of our customers, and the solution is simple: if the modal with the "Force" action exists, just click that button and continue the test.

To handle this and similar situations, BugBug lets you add a condition step.

When you click it, you see a list of options to validate and, based on the result, perform (or not) an action.

Available options:

  • Element

    • Element is visible

    • Element is not visible

    • Element has text

    • Element is disabled

    • Element is not disabled

  • Forms

    • Form input has value

    • Form input is checked

    • Form input is not checked

  • Page

    • Page shows specific text

    • Page does not show specific text

    • Page has title

    • URL address

    • Download started

  • Advanced

    • Custom Javascript

    • DOM element exists

    • DOM element does not exist

    • Number of elements in the DOM

    • Variable value

    • Clipboard value

For example, if you would like to check that the text "Force" exists on the page and then click the button with that text, an example would look like:

You can edit the if condition as a normal step with additional configuration (e.g., setting a timeout, waiting for conditions, and so on).

You can treat the condition as a block where you can put multiple steps

Execution of the condition

During execution if could be resolved as true or false. Depends on the result, the steps inside the if block will be executed and marked as passed or omitted and marked as skipped.

Where is else and else if?

By design, BugBug doesn't support else and else if blocks. We believe the current implementation covers the most popular scenarios, and at the same time, we still think tests should be linear, without complex logic.

It's still possible to do this complex logic inside BugBug using different checks, like:

  • If "Element is visible" do this

  • if "Element is not vislble" do that

or by setting a variable and checking the result of it:

Please let us know if there's a scenario you can't cover with the current implementation.

Recording if condition

During recording, there is currently no option to add an if condition using our BugBug overlay. We plan to add this feature, but this is not a priority. You can easily add it manually when you pause the test. Edit & Rewind functionality would be helpful here.

Last updated

Was this helpful?