logo logo

How to Use Data Driven with Selenium Test Suite

This tutorial is the final step in Creating a Test Automation framework with C#, Selenium Webdriver 3 and Nunit. After Creating a functional testing flow with multiple test cases in the previous tutorial, we’ll now learn how to use data driven with Selenium test suite to add data driven support to the framework.


Tutorial Overview:

Class 1 – Creating an Automated Test Using Selenium WebDriver 3 and C#

Class 2 – How to Create a Test Automation Framework Architecture with Selenium WebDriver 3

Class 3 – Utilizing Test Automation Framework with Advanced Capabilities


Let’s implement data driven with Selenium for the automated tests execution: Create a CSV file and enter the following lines of data:

test1;[email protected];Test 123;Hello from Csv File

test2;[email protected];Test 123;Hello from Csv File

Each line is the information the website’s form will receive (in our example: Contact Us), meaning our test will fill in the form twice, each time clicking on the Submit button and right away filling in the the next line.

We’ll be opening the Contact Us class, created here and paste the following function:

public void filldatafromCsv()
{
    string filePath = @"C:\Users\TestProject\Desktop\runFile.csv";
    List<string> data = new List<string>();
    data = Servers.general.loadCsvFile(filePath);

    for (int i = 0; i < data.Count ; i++)
    {
        var values = data[i].Split(';');
        SendYourName(values[0]);
        SendYourEmail(values[1]);
        SendYourSubject(values[2]);
        SendYourMessage(values[3]);
        clickSubmit();
        ValidateMessage();
    }
}

This function’s purpose is to:

  1. Loading the file and its data.
  2. Fill out the form fields
  3. Click on Submit
  4. Verify the message has been sent successfully

The function will run once for every line of data in the CSV file.


Congratulations! In case you have been following all the tutorials for Creating a Test Automation framework , now you’ve created a test automation framework with C#, multiple browser support, Selenium WebDriver 3, Page Object Pattern and added support for data driven with Selenium.

Please leave a comment and let us know if you have any recommendations or questions!


 

Asya Galinsky

About the author

Asya Galinsky

Comments

11 2 comments

Leave a Reply

FacebookLinkedInTwitterEmail