0% Complete

Introduction

Before taking this lesson

Make sure you feel comfortable with the following lessons:

  • mabl App Intro
  • mabl Trainer Intro

Learning Objectives 🧠

To understand:

  • The different variable types available in mabl
  • How to create and use them
  • When to use what type of variables

Key benefits of Variables 💰

  • Test scenarios that require dynamic values
  • Keep tests short by passing variables in-between tests

Common Variable use cases 👍

  • Creating new users for application sign-up
  • Fill form with dynamic values instead of static values

Getting started

What are variables?

Variables act as containers for values that:

  • Might be unknown during test development
  • Made to vary across iterations
  • Retrieved from a previous step or a test, or
  • Returned from a user-defined action

What are the different types of variables?

When working with variables in mabl, you can think about them in four different categories:

  • Test-generated variables: The value is generated during a test run, as for example extracting it from an element property like innerText.
  • Plan variables: Include system-reserved variables (e.g. app.url and app.username).
  • Environment variables: Are defined at the environment level.
  • Data-driven variables: Variable that has a default value that can be overriden by a data table or shared variable from a previous test run.

How to create variables?

 

Adding test-generated variables

(1) Open the mabl Trainer

(2) Click on the "{x}" button at the bottom, and click to "Create" a variable

(3) You will be brought to a new screen where you can assign a dynamic value source to the variable and give it a name

At present, you can generate variables from:

  • String template
  • Element property
  • JavaScript
  • mabl mailbox address
  • Data source

Creating variables with string template

  • Select the “string template” option available under the create variable form
  • Used for creating strings from constant values, random values, variables, and/or mathematical expressions
  • Supports certain macros in the string templates
  • faker.js helps in generating realistic random data
  • In mabl, the syntax has to be in the format like
    • Eg. will generate a value like 112.3

Creating variables from Element property

(1) Select the "Element property" option available under the create variable form

(2) Click the mouse icon

(3) Select an element on the page

(4) From the Property selector, choose what element property you would like to set the variable to. e.g. innerText, class, tagName

(5) Click the "Save" button to store your Element property variable

Creating variables from Javascript

(1) Select the “Javascript” option available under the create variable form

(2) Open the code editor to write the JS code and after saving it, the value will be stored in a variable

Note:

  • It is possible to use other variables inside the JS code
  • For referencing a user-created variable inside the JS code, the syntax will be mablInputs.variables.user.VariableName
  • If you write console.log(mablInputs) in the JS editor and open the console tab in dev tools, you can check all the different variable types supported

Creating variables from mabl mailbox address

(1) Select the “mabl mailbox address” option available under the create variable form

(2) Provide it with a name and you are done!

Creating data-driven variables

(1) Click on the "{x}" button at the bottom, and click on "Manage"

(2) Click on add variable

(3) You must assign a default value to a data-driven variable in case there isn't any value passed on to the test from a data table


Note: When creating a test, if the Train with DataTable is toggled on, it will pre-fill the data-driven variables with the first row from the data table.

Adding Environment variables

(1) Go to Configuration > Applications

(2) Click the name of an environment to edit it

(3) Click on the add Environment Variable button

How to use the variables

(1) You can use the variables in your test by clicking on the "{x}" button and then clicking on "Use" in the menu that pops up

(2) Select an input field or text area where you would like to use the variable

Note:

  • You can also enter the variable value into a field using custom find
  • The syntax to reference a variable is

Recap

What did we learn?

  • Different variables types available in mabl
  • How to create and use them
  • Test different scenarios using realistic data

Feedback

Was this helpful?

Take this 2 minute survey to let us know how we can make mablU better!