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 foo: search_term: "foo" expected_title: "foo - Google Search" bar: search_term: "bar" expected_title: "bar - Google Search"
# examples/test/google-search-parameterised-with-data-provider.yml config: browsers: - chrome url: google_com.url imports: steps: assert_opened_page_step: "../step/assert-page-open-parameterised.yml" query_step: "../step/google-search-query-parameterised.yml" data_providers: imported_query_data: "../data-provider/google-search-query.yml" "verify Google is open": use: assert_opened_page_step data: 0: expected_url: $config.url expected_title: "Google" "query": use: query_step data: imported_query_data