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, 2019 in Selenium by Devashish
659 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, 2019 by Abha
• 27,930 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, 2019 in Selenium by Suman
77 views
0 votes
1 answer

How can we create data driven framework using TestNG?

Hey Yuvraj, we can create a Data ...READ MORE

answered Jun 12, 2019 in Selenium by Anvi
• 14,090 points
511 views
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, 2019 in Selenium by anonymous
• 14,090 points
183 views
0 votes
2 answers

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,510 points
3,487 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,493 views
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,890 points
2,574 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,812 views
0 votes
2 answers

How can we take screenshots of tests in Selenium 2 using C#

Hey, try using following code command to ...READ MORE

answered Aug 22, 2019 in Selenium by Abha
• 27,930 points
318 views
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, 2019 in Selenium by Abha
• 27,930 points
291 views