带有hashmap的Assert-使用testng和java验证selenium webdriver中的实际数据和预期数据

a2mppw5e  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(242)

我已经将存储的字符串值与提供的hashmap中的ExpectedValue进行了比较。
但我完全停留在以下几点上:
我能够验证这些项目,但是如果这个特定的字符串(假设100)出现在详细页面的任何地方,那么它就是传递的,这是一种不正确的Assert方式。
如果我把

//  Assert.assertEquals(allEle, entry.getValue());

它不能正常工作。
如果我使用2列表来比较预期值和实际值,那么如何在结果中显示日期失败或名称失败/通过。
我的实际数据存储在一个变量中的字符串值,就像我存储所有文本值的Allegment arraylist一样 gettext() ,这是我的详细视图网页。
并且期望的数据已经存储在hashmap键值对中
请参阅以下代码以获取参考

Map<String,String> expectedDataMap=new HashMap<String,String>();            
  expectedDataMap.put("Date", SalesInvoiceDate);
  expectedDataMap.put("Bank Voucher Number", DeliveryDocumentNumber);
  expectedDataMap.put("Total Amount", totalBaseAmountBV);
  expectedDataMap.put("Total Balance Amount", totalBalanceAmountBV);
  expectedDataMap.put("Total Paid Amount", totalPaidAmountBV);
  expectedDataMap.put("Bank Name", "Axis Bank-10100001");
  expectedDataMap.put("Vendor Name", "-50000017");

    List<WebElement> allOptions=driver.findElements(By.xpath(prop.getProperty(objectname)));

    List<String> allEle=new ArrayList<>();

    for(WebElement ele:allOptions)
    {
       allEle.add(ele.getText());

    } 
            //String actual=ele.getText();
     for(Map.Entry<String, String> entry:expectedDataMap.entrySet())
     {
         if(allEle.contains(entry.getValue()))
            {
               //  Assert.assertEquals(allEle, entry.getValue());

                System.out.println(entry.getKey()+ " is Passed:- "+entry.getValue());

         System.out.println("-----------------------------------------------------");
            }
            else
            {
                System.out.println(entry.getKey()+ "is Failed:- "+entry.getValue());

                 System.out.println("-----------------------------------------------------");
            }
         }

如何始终以不同的形式重用此函数以Assert值并使用期望的密钥对打印它?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题