首页 > 解决方案 > 如何在 selenium 中使用 Excel 和 junit 进行参数化(读取隐藏的 excel 数据)

问题描述

嗨,我正在尝试从外部文件中获取数据,并在运行时读取并加载到测试脚本(多个测试用例)中,而不是对其进行硬编码或使用 @parameter 注释,我不想提及我的参数或我的数据如下所示的脚本,

@RunWith(Parameterized.class)
public class Class_Test {

    @Parameter(0)
    public String name;
    @Parameter(1)
    public String type;
    @Parameter(2)
    public String username;
    @Parameter(3)
    public String password;
    @Parameter(4)
    public String email;

    @Parameters(name = "{1}")
    public static String[][] data() throws IOException {
        return Reader.readDataFromExcel("Core_Test");
    }
}

有什么办法可以隐藏我的变量而不是在测试脚本中公开它们

标签: javaseleniumjunitparameter-passing

解决方案


参数由带有@Parameters 注释的方法生成。您可以使用此方法从 Excel 电子表格中读取数据。

@Parameters
public static Object[][] data() {
  //read the date here from the Excel file.
}

推荐阅读