I am trying to perform data driven testing in TestNG But I am getting error

+1 vote

I am trying to perform data driven testing in TestNG. 

But I am getting error: 

FAILED: loginWay2sms 

org.testng.internal.reflect.MethodMatcherException: Data provider mismatch. 

What's wrong in my script.

package testNG;

import java.io.File;

import java.io.IOException;


import org.apache.commons.io.FileUtils;

import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebDriverException;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Assert;

import org.testng.ITestResult;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;


import jxl.Cell;

import jxl.Sheet;

import jxl.Workbook;

import jxl.read.biff.BiffException;


public class Datadriven_testing_in_testNG

{

public WebDriver driver;

@DataProvider(name="testData")

public Object[][] readExcel() throws BiffException, IOException{

//File location

File f=new File("C:\\Users\\Dell\\Desktop\\SELENIUM\\New folder\\akshay\\src\\akshay\\src\\testNG\\Waytosms testdata.xls");

//reading workbook

Workbook w=Workbook.getWorkbook(f);

//reading sheet

Sheet s=w.getSheet(0);

//Storing no.of rows and columns

int noofRows=s.getRows();

int noofCols=s.getColumns();

     //for getting the input data from excel

String inputData[][]=new String[noofRows-1][noofCols];

int count=0;

for(int i=1;i<noofRows;i++){

for(int j=0;j<noofCols;j++){

Cell c=s.getCell(j,i);

inputData[count][j]=c.getContents();

}

count++;

}

return inputData;


}

@Test(dataProvider="testData")

public void loginways2sms(String uname,String pwd) throws InterruptedException

{//open browser

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Dell\\Desktop\\SELENIUM\\chromedriver.exe");

driver=new ChromeDriver();

//navigate to url

driver.get("https://www.edureka.co/");

Thread.sleep(4000);

//for username

driver.findElement(By.id("mobileNo")).sendKeys(uname);

//for password

driver.findElement(By.id("password")).sendKeys(pwd);

//for clicking on login

driver.findElement(By.xpath("(//button[contains(text(),'Login')])[1]")).click();

//verification point

String eurl="https://www.edureka.co/blog/pmp-certification/";

Assert.assertEquals(driver.getCurrentUrl(), eurl);

}

@AfterMethod

public void getTestResult(ITestResult testResult){

System.out.println("Test case name: "+testResult.getName());

System.out.println("Test case Result: "+testResult.getStatus());

//if status=1-->pass, status=2--->fail

int status=testResult.getStatus();

if(status==1){

driver.close();

}

else
{
try {

//take screenshot

File outfile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(outfile, new File("C:\\Users\\Dell\\Desktop\\SELENIUM\\New folder\\akshay\\src\\akshay\\src\\testNG"+testResult.getParameters()[0]+"Defect.jpg"));

} catch (WebDriverException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} 

}

driver.close();
}
Sep 6, 2020 in Selenium by akshay
• 130 points
1,313 views
Hey @Akshay, could you please post the complete error stack trace you are getting?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

i am not able to perform this method in selenium driver.get("google")

Hi Sachin, are you getting any errors ...READ MORE

answered May 15, 2019 in Selenium by Abha
• 28,140 points
1,807 views
0 votes
2 answers

I am trying to run the below code but java.lang.Illegalstate Exception is coming

You are facing this error because while ...READ MORE

answered Jun 21, 2019 in Selenium by Abha
• 28,140 points
1,044 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,673 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,142 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,221 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,874 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