DataProvider不匹配异常

时间:2018-10-31 12:53:45

标签: java testng testng-dataprovider

获取DataProvider不匹配异常。下面的代码有人可以帮助我吗?我的Excel文件有6个值,我从Excel中传递了相同数量的值。

package newtoursProject;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Test_file2 {
    WebDriver driver;
    @BeforeTest
    @Parameters({"param1","param2","param3"})
    void environment(String sg1,String sg2,String sg3)
    {
        System.setProperty(sg1, sg2);
        driver=new ChromeDriver();
        driver.get(sg3);    


    }
    @Parameters({"param4","param5"})
    @Test(priority=1)
    void login(String sn,String sn2)
    {
        driver.findElement(By.name(ObjectRepository.s1)).sendKeys(sn);
        driver.findElement(By.name(ObjectRepository.s2)).sendKeys(sn2);
        driver.findElement(By.name(ObjectRepository.s3)).click();

    }
    @Test(dataProvider="fb")
    void flight(String s1,String s2,String s5,String s6,String s7,String s8)
    {   
        System.out.println("Hello");
    radio(s1,s2);
    System.out.println("Hello");
    //dropdown(s3,s4);
    dropdown(s5,s6);
    dropdown(s7,s8);
    }
    public void dropdown(String a,String b)
    {
        WebElement dropdown=driver.findElement(By.name(a)); 
        Select obj= new Select(dropdown);
        obj.selectByVisibleText(b);

    }
    public void radio(String a,String b)
    {
        System.out.println("Hello");
        List<WebElement> radio=driver.findElements(By.name(a)); 

        System.out.println(radio);
        for(WebElement temp:radio)
        {
            if(temp.getAttribute("value").contains(b))
            {
                //System.out.println("Hello");
                temp.click();
            }
        }
    }

    String[][] getDataExcel(String filename,String sheetname) throws IOException
    {
        FileInputStream fin=new FileInputStream(filename);

        HSSFWorkbook wbk=new HSSFWorkbook(fin);
        HSSFSheet sheet=wbk.getSheet(sheetname);
        int rowsize=sheet.getLastRowNum()+1;
        int colsize=sheet.getRow(0).getLastCellNum();
        System.out.println(rowsize);
        System.out.println(colsize);
        HSSFRow row;
        HSSFCell  cell;
        String ar[][]=new String[rowsize][colsize];
        for(int i=0;i<rowsize;i++)
        {
             row=sheet.getRow(i);
            for(int j=0;j<colsize;j++)
            {
                cell=row.getCell(j);
                ar[i][j]=cell.getStringCellValue();
                System.out.print(cell.getStringCellValue()+"\t");

            }
            System.out.println();

        }
        return ar;

    }
    @DataProvider(name="fb")
    Object[][] Registration() throws IOException
    {
        Object[][] str=getDataExcel("C:\\Users\\sailu\\Desktop\\NewTours_project.xls","Sheet1");
        return str;

    }

}

使用TestNG框架并使用dataprovider从Excel读取数据 并传递与测试中指定的值相同的值。 请帮助

例外: 我收到以下异常。

航班org.testng.internal.reflect.MethodMatcherException:数据提供者不匹配方法:flight([Parameter {index = 0,type = java.lang.String,clarifiedAnnotations = []},Parameter {index = 1,type = java.lang.String,clarifiedAnnotations = []},参数{index = 2,类型= java.lang.String,clarifiedAnnotations = []},参数{index = 3,type = java.lang.String,clarifiedAnnotations = [] },参数{index = 4,类型= java.lang.String,clarifiedAnnotations = []},参数{index = 5,类型= java.lang.String,clarifiedAnnotations = []}])参数:[(java.lang .String)tripType,(java.lang.String)oneway] ...删除了20个堆栈帧

0 个答案:

没有答案