【问题标题】:How to compare the data in two excel sheets using data provider in Selenium如何使用 Selenium 中的数据提供程序比较两个 Excel 工作表中的数据
【发布时间】:2019-01-09 13:20:30
【问题描述】:

我已经在 excel 表中有数据。运行 selenium 脚本时将下载新的 excel 表。我需要比较这两个 excel 表。

【问题讨论】:

    标签: selenium testng-dataprovider


    【解决方案1】:

    有多种方法可以比较 selenium 中的 excel 文件:

    • 使用 hashmaps :为此,您需要在 Excel 文件中以表单或键值对的形式保存数据。比较 hashmap 中的数据会更加简单方便。

    这里是从 excel 文件中提取数据到你的 hashmap 的代码 sn-p(如果你使用 Java):

        HashMap<String, String> map = new HashMap<>();
        JSONObject jsonObject = new JSONObject(excelDataString);
        if(null != jsonObject){
            Set<String> keys = jsonObject.keySet();
            for(String key : keys){
                try{
                    map.put(key, jsonObject.getString(key));
                } catch(Exception e){
                    map.put(key, jsonObject.getString(key).toString());
                }
            }
        }
    
    • 使用 Apache POI、Fillo 或任何其他库从两个 excel 文件中读取数据,并根据其中的数据结构进行比较。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 2013-08-22
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多