You can use so-called data tables to execute a specific Behavior-Driven Development (BDD) GUI test scenario in a data-driven way. Create tables to define test data and use this data to drive your test. Since Squish 6.5.0, it is possible to refer an external file for such data.

Data tables as shown below work with all Squish editions and applications. In this blog, we’re going to a use a Squish for Windows package, the WPF addressbook example application and JavaScript as the scripting language to demonstrate this new feature.

We’ve created a short test script which performs an action for each row of data. In this case, we add a person to the addressbook with the given data from the .tsv file. Note: this could also be a .csv, .txt or .xls file. For more details, please take a look at our documentation on Behavior-Driven Testing.

The step implementation looks like this:

import * as names from 'names.js';

Given("AddressbookWPF is up and running", function(context) {

When("I create a new addressbook", function(context) {

Then("'|integer|' entries are present", function(context, rowNumber) {, 

When("I add persons from a file", function(context) {
    var table = context.table;
    for (var i = 1; i < table.length; ++i) {
        var forename = table[i][0];
        var surname = table[i][1];
        var email = table[i][2];
        var phone = table[i][3];

        type(waitForObject(names.addressBookAddForenameEdit), forename)
        type(waitForObject(names.addressBookAddSurnameEdit), surname)
        type(waitForObject(names.addressBookAddEmailEdit), email)
        type(waitForObject(names.addressBookAddPhoneEdit), phone)
        type(waitForObject(names.addressBookAddPhoneEdit), "<Return>");
        test.log("Added '" + forename + " " + surname + " " +  
            email + " " + phone + "' to the addressbook")

The sample data file is stored directly in the Test Data folder of the test suite:

Once the test is executed, the following output will be visible in the test results:

Data-driven BDD tests using external data tables is a useful method of GUI testing, especially in cases where input data consistently grows. Readability of your tests cases is also improved, an important factor when tests are shared amongst project stakeholders.

You can download the used test suite below:

1 Comment

it would be also helpful if you show different version of the above script using Python

Leave a Reply

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

Copy link
Powered by Social Snap