Selify与TestNG和Java中的数据提供程序不匹配 [英] Data Provider Mismatch in Selenium with TestNG and Java

查看:0
本文介绍了Selify与TestNG和Java中的数据提供程序不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里遇到了一些问题,您能告诉我如何解决吗?

下面是我读取Excel的代码

import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadExcel {
    public String unicode;
    public String[][] readExcel() throws IOException {
        XSSFWorkbook excelObject = new XSSFWorkbook("./data/unicode1.xlsx");
        XSSFSheet excelSheet = excelObject.getSheet("Sheet1");
        
        int rows = excelSheet.getLastRowNum();
        int columns = excelSheet.getRow(0).getLastCellNum();
        
        String[][] data = new String [rows][columns];

        for (int i = 1; i <= rows; i++) {
            XSSFRow row = excelSheet.getRow(i);
            for (int j = 0; j < columns; j++) {
                XSSFCell cell = row.getCell(j);
                String cellValue = cell.getStringCellValue();
                data[i-1][j] = cellValue;
            }
        }
    return data;
    }
}

我的测试用例代码

import java.io.IOException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.github.javafaker.Faker;
import commonFeatures.CommonThings;
import commonFeatures.ReadExcel;

public class SignUpWithUnicode extends CommonThings{
    
    Faker faker = new Faker();

    @Test(dataProvider = "fetchData")
    public void signUpWithUnicode(String unicode) throws InterruptedException {
        invokeBrowser("chrome", "https://master.signup");
        type(locateEle("xpath","//input[@id='first_name-id']"),faker.name().firstName());
        type(locateEle("xpath","//input[@id='last_name-id']"),faker.name().lastName());
        type(locateEle("xpath","//input[@id='last_name-id']"),faker.name().lastName());
        type(locateEle("xpath","//input[@id='client_user_email-id']"),faker.internet().emailAddress());
        type(locateEle("xpath", "//input[@id='password-id']"), "12345");
        type(locateEle("xpath", "//input[@id='degree-id']"), unicode);
        click(locateEle("xpath", "//span[contains(text(),'SUBMIT')]"));
        closeBrowser();
    }
        
    @DataProvider (name = "fetchData")
    public String[][] getData() throws IOException {
        ReadExcel excel = new ReadExcel();
        return excel.readExcel();   
    }
}

下面是错误

[RemoteTestNG] detected TestNG version 7.0.0
FAILED: signUpWithUnicode
org.testng.internal.reflect.MethodMatcherException: 
[public void testCases.SignUpWithUnicode.signUpWithUnicode(java.lang.String) throws java.lang.InterruptedException] has no parameters defined but was found to be using a data provider (either explicitly specified or inherited from class level annotation).
Data provider mismatch

我在Excel工作表中使用的是Unicode字符,因此我尝试使用Object而不是String,但仍然出现此错误。然后,我尝试使用Excel中的字符串来查找错误,但仍未成功。

推荐答案

错误为Data provider mismatch

您在ReadExcel类中以Multi dimensional array的形式返回数据,但在测试signUpWithUnicode中以String的形式传递数据,因此请更改参数类型。

@Test(dataProvider = "fetchData")
    public void signUpWithUnicode(String[][] unicode) throws InterruptedException {
   //code
  }

这篇关于Selify与TestNG和Java中的数据提供程序不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆