Dataprovider error:TestNG is unable in inject a suitable obj | Selenium Forum
M
Posted on 18/01/2016
i want to specify 4 parameters at public void f(String browser,String n, String s,String expectedResult) but its not being allowed,
i get error:The data provider is trying to pass 2 parameters but the method p1.LoginTest#doLogin takes 4 and TestNG is unable in inject a suitable object.

Sir,what code i put @DataProvider , to set this right??



Following is the code sir:
------------------------------------


import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.DataProvider;

public class Login_verifyy_gmail {
WebDriver w;
static String CaseAErr="The email or password you entered is incorrect. ?";
static String CaseBErr="Enter your email address.";
static String CaseCErr="Enter your password.";

@Test(dataProvider = "dp")



public void f(String browser,String n, String s,String expectedResult) {//here i want to specify 4 paramaertes..but am not allowed //to

w=new FirefoxDriver();
w.get("http://www.gmail.com/");
w.findElement(By.xpath("//input[@id='Email']")).sendKeys(n);
w.findElement(By.xpath("//*[@id='next']")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(s);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(Keys.ENTER);

System.out.println("n"+n+"s"+s);

}

@DataProvider
public Object[][] dp() {
/* return new Object[][] {
new Object[] { 1, "a" },
new Object[] { 2, "b" },*/


Object[][] x=new Object[3][2];
Xls_Reader xls=new Xls_Reader("C:\\Users\\chaitra\\Pictures\\shopping_cart.xlsx");
int rows = xls.getRowCount("Login");
int cols = xls.getColumnCount("Login");

Object data[][] = new Object[rows-1][cols];

for(int rNum=2;rNum<=rows;rNum++){
for(int cNum=0;cNum<cols;cNum++){
System.out.println(xls.getCellData("Login", cNum, rNum));
data[rNum-2][cNum] = xls.getCellData("Login", cNum, rNum);
}}
return data;



};
}

M
Replied on 19/01/2016

sir,
is the expectation like , browser & expected result be specified in xlsx..& i read it @ data provider & put it in array of x[] [].. & then supply it to f(parameter1,p2,p3,p4)?????????????????????????????


M
Replied on 22/01/2016

it is really hard to explain in the forum. please watch the datadriven framework.