2

I wrote a small code to search multiple keywords in google search. But it displays errors.

My coding is as follows:

public class GoogleSearchDataSet {

    WebDriver driver;

    @BeforeClass
    public void setup () {
        System.setProperty("webdriver.chrome.driver","E://chromedriver.exe");
        driver=new ChromeDriver();
        driver.get("http://www.google.com");    
    }

    @AfterClass
    public void quit(){
        driver.manage().deleteAllCookies();
        driver.quit();
    }

    @DataProvider(name="mykeywordset")  
    public Object[] data(){
        return new Object []{ "Cat", "Dog", "hat" };
    }

    @Test(dataProvider="mykeywordset")
    public void search(String Word){
        WebElement txtSearch= driver.findElement(By.className("gbqfif"));
        txtSearch.sendKeys(Word);
        WebElement btnSearch = driver.findElement(By.id("gbqfba"));
        btnSearch.submit();
    }
}

It displays the following error:

SKIPPED: search
org.testng.TestNGException
Data Provider public java.lang.Object[] googleSearch.GoogleSearchDataSet.data() must return either Object[][] or Iterator<Object>[], not class [Ljava.lang.Object]
Reporter
  • 3,897
  • 5
  • 33
  • 47
Saranga
  • 25
  • 6

1 Answers1

1

The problem is exactly what the error message says. You need to provide Object[][] or Iterator<Object []>.

First dimension is test case (or test run if you want). Second dimension is parameter index.

So your DataProvider should be:

@DataProvider(name="mykeywordset")  
public Object[][] data(){
   return new Object [][]{ 
     { "Cat" }, 
     { "Dog" }, 
     { "hat" }
   };
}
Falko
  • 17,076
  • 13
  • 60
  • 105
luboskrnac
  • 23,973
  • 10
  • 81
  • 92
  • Maybe I don't get what you are trying to do. Your test method with my corrected DataProvider is going to be called 3 times. Every time with different Word. This is how TestNg parametrized test support is designed. – luboskrnac Sep 24 '14 at 11:44
  • @Saranga, could you please paste code from comment into your question, so it will be indented and readable? – luboskrnac Sep 24 '14 at 11:47