Using a Data Provider

We previously learned how a data set list can be passed to a parameterised test step to run a single step once per set of data.

We defined the data list set within our test. Doing so can get cumbersome over time. An overly-large collection of data can make the test hard to follow. We run the risk of too-closely coupling that which is being tested with the data with which it is being tested.

A data provider imported into a test addresses these matters.

Creating a Data Provider

We create a data_providers section within our imports section, choose an import a name and give the path to our data provider.

Now just pass the import name we chose as the data property of the test.

# examples/data-provider/google-search-query.yml
  search_term: "foo"
  expected_title: "foo - Google Search"

  search_term: "bar"
  expected_title: "bar - Google Search"
# examples/test/google-search-parameterised-with-data-provider.yml
  browser: chrome
  url: google_com.url

    assert_opened_page_step: "../step/assert-page-open-parameterised.yml"
    query_step: "../step/google-search-query-parameterised.yml"
    imported_query_data: "../data-provider/google-search-query.yml"

"verify Google is open":
  use: assert_opened_page_step
      expected_url: $config.url
      expected_title: "Google"

  use: query_step
  data: imported_query_data