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. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.

    ccna training in chennai

    ccna training in bangalore

    ccna training in pune

  7. I feel that this blog article contains very nice information. Thanks for sharing this kind of nice artices.Happy to read this blog. Kindly Vist us @ Ramanathapuram Hospital List Hospitals in Ramanathapuram

  8. myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance

  9. 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

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

    Article submission sites
    Guest posting sites

  11. 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 |

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

  13. 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


  14. 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

  15. 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.

  16. 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

  17. Thanks for sharing,this blog makes me to learn new thinks.
    interesting to read and understand.keep updating it.
    call girls in dehradun
    escort service in dehradun

  18. Thanks for sharing,this blog makes me to learn new thinks.
    interesting to read and understand.keep updating it.
    call girls in mussoorie
    escort service in mussoorie

  19. Thanks for sharing,this blog makes me to learn new thinks.
    interesting to read and understand.keep updating it.
    call girls in lucknow
    escort service in lucknow


  20. Thanks for sharing,this blog makes me to learn new thinks.
    interesting to read and understand.keep updating it.
    call girls in ghaziabad
    escort service in ghaziabad

  21. Thanks for sharing,this blog makes me to learn new thinks.
    interesting to read and understand.keep updating it.
    call girls in gurgaon
    escort service in gurgaon

  22. Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Website. Please feel free to visit our site. Thank you for sharing.
    Be Your Own Boss! If you're looking for a change in your work prospects, then let's prepare for your career from here!!!
    Self Employment | Women Development | Information Technology | Engineering Courses