Skip to main content

How to use GitHub as a Data Source in Tests

You can use CSV, JSON, or XML files that are stored in a GitHub repository as a data source in your tests. Follow this guide to learn how to use this bypopulation.csv file as a data source.

What You'll Need

Step 1: Setting Up GitHub

  1. Create a new access token associated to your GitHub profile by accessing https://github.com/settings/tokens. GitHub will show you the token only once, so make sure you’re copying and pasting it somewhere safe and accessible.

    GitHub token settings
    note

    When creating the token, make sure to select the public_repo subcategory or the repo category based on which type of repository hosts your input data.

    Type of repository
  2. Create a repository to host your input data if one doesn't exist already.

  3. Commit and push a data source file. It can be a CSV, JSON or XML file.

Step 2: Creating a Basic Test

  1. Go to Sauce Labs API Testing and create a new test.

  2. Add the GitHub component and configure it as follow:

    • Account is your GitHub username.
    • Repository is the name of the repository that your data file is pushed to.
    • Branch is the repository branch that the desired version of the data file is in.
    • Token is the access token you created in Step 1.
    • Path is the name of the file in the repository.
    • Variable is the variable to store the payload in.
    • Mode is the filetype of the file in the repository.
    GitHub component

The system uses these component settings to retrieve the bypopulation.csv file, parse it as a CSV file, and assign it to the inputData variable.

  1. (Optional) Verify the set up by adding a Comment component for printing the parsed data as shown:
comment
  1. (Optional) Run the test.
test report
  1. Next, iterate over a subset of this input set by adding an Each component.
each component

This iterates over a subset of five randomly selected items.

Suggestion

To help you identify an item for debugging purposes, you can add a comment that prints out the current item in each iteration. (like ID: ${_1[0]})

  1. Use the data to perform your request. For example, in a POST Body:

    {
    "id":${_1[0]},
    "city":"${_1[1]}",
    "state":"${_1[2]}",
    "population":"${_1[3]}"
    }
  2. Add the assertions required for testing purposes.

  3. Run the test.