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
2,550 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
• 28,140 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 23, 2019 in Selenium by Suman
701 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,150 points
2,439 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,150 points
1,813 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,500 points
13,649 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,131 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,910 points
7,209 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 3, 2020 in Selenium by Sri
• 3,190 points
7,865 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 23, 2019 in Selenium by Abha
• 28,140 points
1,421 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
• 28,140 points
1,613 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP