本文介紹了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中的數據提供程序不匹配的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,