公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

本文介绍了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中的数据提供程序不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,

分享到:
标签:Java Selify TestNG 不匹配 提供 数据 程序
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定