Tuesday, 3 July 2018

TestNG Data Provider

When you need to pass complex parameters for example created from Java (complex objects, objects read from a property file or a database, etc…), in such cases parameters can be passed using Dataproviders. A Data Provider is a method annotated with @DataProvider. A Data Provider returns an array of objects.

Let us check out the same Search examples using Dataproviders.

Video Tutorial -

How to do it ?

1)  Define the method searchValue() which is defined as a Dataprovider using the annotation. This method returns array of object array.

2) Add a method test() to your DataProviderTest class. This method takes two strings as input parameters.

3) Add the annotation @Test(dataProvider = “search”) to this method. The attribute dataProvider is mapped to “search”.

4) Run the below code as testNG test case then the test will execute two times as we are passing two Data Values.

package test;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestNGDataProvider {
 private static WebDriver driver;
  @DataProvider(name = "search")
  public static Object[][] searchValue() {
        return new Object[][] { { "appium" }, { "selenium" }};
  // Here we are calling the Data Provider object with its Name
  @Test(dataProvider = "search")
  public void test(String searchtext) throws Exception {
   System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\chromedriver_win32\\chromedriver.exe");
   driver=new ChromeDriver();


  1. Replies
    1. Great Article Cloud Computing Projects

      Networking Projects

      Final Year Projects for CSE

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. Your site has a lot of useful information for myself. I visit regularly. Hope to have more quality items.
    ludo king

  3. Nice Sharing..! I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.


    software quality assurance companies

  4. Awesome blog. Thanks for sharing such a valuable information.Keep giving like this.
    Best Selenium Training Institute In Hyderabad | Online Selenium Training

  5. AWS Training in Bangalore - Live Online & Classroom
    myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.

    IOT Training in Bangalore - Live Online & Classroom
    IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Reading data through the sensors and processing it with applications sitting in the cloud and thereafter passing the processed data to generate different kind of output is the motive of the complete curricula. Students are made to understand the type of input devices and communications among the devices in a wireless media.

  6. Hello,
    I just come through your blog while searching more about the software testing. Read your blog and love the way you have implemented the unique content about software testing and other testing related information. Thanks for sharing this and I will wait for your next updates. Keep it up!


    software development company

  7. Wonderful blog!!! Thanks for your information… Waiting for your upcoming data.

    Article submission sites
    Guest posting sites

  8. Nice blog..! I really loved reading through this article. Thanks for sharing such an amazing post with us and keep blogging...Well written article Thank You for Sharing with Us pmp training institute in chennai | pmp training class in chennai | pmp training near me | pmp training courses online | pmp training fee |

  9. Good Post and thanks for sharing this things with us. Get the Best Selenium Training Institute in Bangalore

  10. This is very great thinks. It was very comprehensive post and powerful concept. Thanks for your sharing with as. Keep it up...
    Software Testing Training in Chennai | Software Testing Training Institute in Chennai


  11. Thanks for sharing this information!
    I totally agree with you. Your information is very interesting and important. I really like this information.
    Our easy web plans company is famous in Advanced AWS Online Training Institutes in Hyderabad.
    If you want to see our training venue then click on links:
    Call Now: 9581111796
    Drop Mail: online@futureqtech.com

  12. Thank you for excellent article.You made an article that is interesting.
    Best AWS certification training courses. Build your AWS cloud skills with expert instructor- led classes. Live projects, Hands-on training,24/7 support.

  13. Thanks for sharing,you have done a very good job.Keep it up.The content is very interesting and impressive.If you are looking for any online training visit our site.
    Best Big Data Hadoop Online Training