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.way2sms.com/");

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.way2sms.com/send-sms";

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 5, 2020 in Selenium by akshay
• 130 points
168 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,000 points
377 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,000 points
317 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,520 points
4,656 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,010 points
5,491 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,890 points
3,320 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 2, 2020 in Selenium by Sri
• 3,010 points
3,931 views