【问题标题】:Getting list of objects from excel to Dataprovider using Poiji使用 Poiji 将对象列表从 excel 获取到 Dataprovider
【发布时间】:2019-04-25 10:22:13
【问题描述】:

我在将对象传递给 Testng 数据提供者时遇到了问题。

主要问题: 我正在使用https://github.com/ozlerhakan/poiji 从 Excel 文件中读取测试数据(1 行是 Person 类的 1 个新对象)。

它返回一个 Person 对象列表,但对于数据提供者,它应该是 Object[][]。如何转换?

Xlsx 文件:

firstName | secondName
-----------------------
John      | Deer
Eric      | Boots

人物类:

public class Person{

    @ExcelCellName("firstName")
    private String firstName;

    @ExcelCellName("secondName")
    private String secondName;

数据提供者:

  @DataProvider
    public Object[][] readExcel() throws Exception {
        List<PersonalApplicant> res = Poiji.fromExcel(new File(("persons.xlsx")), Person.class);
        return res;

    }

错误:

Incompatible types.
Required:
java.lang.Object[][]

Found:
java.util.List
<com.example.package.Person>

【问题讨论】:

标签: java selenium testng


【解决方案1】:

第一个问题是你声明你的函数返回 Object[][] 并且你返回一个列表。 声明函数只返回Object[],返回时使用.toArray()。

    @DataProvider
    public Object[] readExcel() throws Exception {
        List<PersonalApplicant> res = Poiji.fromExcel(new File(("persons.xlsx")), Person.class);
        return res.toArray();

    }

【讨论】:

  • 出现错误——“数据提供者必须返回 Object[][] 或 Iterator”
猜你喜欢
  • 2011-04-30
  • 2019-02-23
  • 2016-08-28
  • 1970-01-01
  • 2011-07-31
  • 2017-05-13
  • 2018-12-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多