Skip to content
Get Free Trial

Parameters and Data Generators

Turn a keyword's recorded values into parameters, so each test run can use new data from a data generator or a test data file.

Say you record signing up a user called john. The keyword now enters john on every test run. The first run works, but the next one fails if the application doesn’t allow the same username twice. To avoid this, replace the recorded values with parameters, so each run can use different data. The data comes from one of two places:

  • A data generator makes a new value on every test run, such as a new username each time. This page shows how.
  • A test data file holds the exact values to use, one row per test run. Loop Through a Test Data File shows how.

On this page, you record a keyword that registers a user on the sample application, and let data generators fill in the form.

  1. Create a scenario file named register, the same way you created books.
  2. Add a test case named Register New User, with one keyword, Register User. Select the keyword and keep the suggested keyword file.
  3. With Register User selected, click Automate. Set Start URL to https://sahitest.com/demo/training/register.htm and click Launch Controller.
  4. Click Record, then fill in the form in the browser:
    • Username: john
    • Password and Confirm Password: secret123
    • Address: 12th main street
    • the terms checkbox
  5. Click Register, then click Stop Recording and Save in the Controller.

Sahi Pro records the passwords encrypted. It also records a check that the Registered Successfully message appeared.

You can parameterize a keyword in the Controller, right after you record it, or later in the No-Code Test Editor. Both have a Parameterize button and open the same dialog. Here, you use the Controller.

  1. In the Controller, with Register User selected, click Parameterize.

    The Controller on the Register User keyword, with its recorded steps for the username, both passwords, the address, the terms checkbox, Register, and the check for the Registered Successfully message, and the Parameterize button highlighted
  2. The Parameterize dialog lists each recorded value, with a parameter name that Sahi Pro suggests, such as $Username. You can rename any of them.

    The Parameterize dialog for Register User, listing the recorded values john, the encrypted password twice and 12th main street, with the suggested parameters Username, Password, Password1 and Address
  3. Select the Data Generators checkbox. It’s off by default. A Data Generator column appears, and each parameter gets a generator, such as Text. Each parameter still uses its recorded value until you choose which ones should use their generator.

    The Parameterize dialog with the Data Generators checkbox selected and highlighted, and a Data Generator column showing Text for each parameter
  4. In Pass from Scenario File, choose where each parameter’s value comes from:

    • Yes, with Step Value uses the recorded value. Every row starts here.
    • Yes, with Scenario Value uses a value you pass to the keyword from the scenario file.
    • No Value, using Data Generator uses a new value from the generator on every test run. You can choose it when Data Generators is selected.

    Open the list in the john row.

    The Pass from Scenario File list open in the john row, highlighted, showing Yes, with Step Value, Yes, with Scenario Value and No Value, using Data Generator

    Choose No Value, using Data Generator. The recorded value john is struck through, because the generator replaces it. Leave the other rows on Yes, with Step Value, so only the username changes on each test run.

    The john row set to No Value, using Data Generator, highlighted, with the recorded value john struck through
  5. Select Remove Duplicates. The two password fields have the same value, so they now share one parameter, $Password, and always get the same value.

    The Parameterize dialog with Remove Duplicates selected and highlighted: one Password row remains, and the Registered Successfully row is now visible
  6. A value that never needs to change doesn’t need a parameter. For example, the last step checks for the message Registered Successfully, which never changes. Clear the checkbox on its row.

    The Parameterize dialog with the checkbox on the Registered Successfully row cleared and highlighted
  7. To shape the values a generator makes, click the pencil icon in its Data Generator cell. For example, for $Username, set Prefix to user_ and Include Timestamp to Yes, then click Apply. Sample Value shows what a generated username looks like.

    The Data Generator dialog for Username, with Data Type Text, Prefix user_ and Include Timestamp Yes highlighted, and a sample value that starts with user_
  8. Click Parameterize. The parameters appear above the steps, and the steps use them in place of the recorded values. Modified steps get an orange dot until you save.

  9. Click Save.

    The Controller after parameterizing: the parameters Username, Password and Address above the steps, steps 1 to 4 using them with orange unsaved dots, step 7 still expecting Registered Successfully, and the orange Save button highlighted

In the Controller, hover over Run and choose Run this testcase. Run it again, and open Reports after each run.

Each test run uses a new username, such as user_sMz3MHR17944704147700 in one run and user_kSeFh8zE7x2017944704281100 in the next. The report shows the value used in each step.

The report for Register.s.csv: the Register New User test case passed, and step 1 of Register User entered the generated username user_sMz3MHR17944704147700

In the next run, the same step enters a different username:

The steps of Register User in the next run's report, where step 1 entered the generated username user_kSeFh8zE7x2017944704281100