How Parametermizing tests can be done in TestNG using Data Provider?

0 votes
How Parametermizing tests can be done in TestNG using Data Provider?
Jul 8 in Selenium by Devashish
34 views

1 answer to this question.

0 votes

Hi Devashish, you can parameterize tests with the help of DataProvider. DataProvider annotation passes test data to test script, which can be helpful with the scenario where you want to test login functionality with multiple credentials, let say 100 or so and you have to login one by one to make sure login is happening with all of these credentials. Below is the code sample showing usage of DataProvider:

public class DataProviderSample {

    // getdata passes the test data to test script

    @Test(dataProvider = "getData")
    public void loginTest(String username, String password) {

        System.out.println("UserName : " + username);
        System.out.println("Password : " + password);

        //Test Automation code

    }

    @DataProvider
    public Object[][] getData() {

        Object[][] data = new Object[4][2];

        // 1st row
        data[0][0] = "testuser1";
        data[0][1] = "pass";

        // 2nd row
        data[1][0] = "testuser2";
        data[1][1] = "pass2121";

        // 3rd row
        data[2][0] = "testuser3";
        data[2][1] = "wswkdsj";

        // 4th row
        data[3][0] = "testuser4";
        data[3][1] = "skaalk";

        return data;
    }
}
answered Jul 8 by Abha
• 23,030 points

Related Questions In Selenium

0 votes
1 answer

How exception handling can be done in Selenium?

@Suresh, Selenium exceptions can be handled in ...READ MORE

answered May 22 in Selenium by Suman
20 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How reports can be produced in different ways for TestNG results?

Hey Suraj, TestNG offers two ways to produce ...READ MORE

answered Jun 19 in Selenium by anonymous
• 12,860 points
31 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
596 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
902 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
585 views
0 votes
2 answers
0 votes
1 answer

How @Listener annotation can be used in TestNG?

Hey Barkha, TestNG @listeners are used to configure reports ...READ MORE

answered Jun 10 in Selenium by Abha
• 23,030 points
27 views