当实际消息中的行更改时,如何将实际消息与预期消息进行比较

时间:2019-08-22 11:34:39

标签: java selenium selenium-webdriver string-comparison

我正在尝试通过java-selenium比较以下消息,但是在执行过程中实际消息中的行正在更改,请让我知道如何处理它。

例如:

String expMsg="Line1.\n"
+ "Line2\n" 
+ "Line3\n" 
+ "Line4\n" 
+ Line5\n" + "\n"
+ "Line6."


String actMsg="Line1.\n"
+ "Line3\n" 
+ "Line2\n" 
+ "Line5\n" 
+ Line4\n" + "\n"
+ "Line6."

我尝试了以下操作,但失败了:

if(actMsg.contains(expMsg){
System.out.println("both the messages are same")
}

请让我知道如何解决此问题。

3 个答案:

答案 0 :(得分:2)

将您的structure (CustomDateTimeExpression) { role-of (viv.time.DateTimeExpression) description (wrapper for DateTimeExpression) features { transient } } 转换为String s

Stream

然后是compare streams

答案 1 :(得分:0)

据我了解,actualMessage的顺序无关紧要,您只需要检查ActualMessage中是否存在所有ExpectedMessage?在这种情况下,将每一行保存在单独的变量/数组中,然后验证实际使用contains时是否存在每个ExpectedMessage。  `

for(i=1, i<6, i++) {
     if(actMsg.contains(expMsg+i){
     System.out.println("both the messages are same")
     }else 
     System.out.println("both the messages are not same")
 }

`

让我知道这是否可行

答案 2 :(得分:0)

这是我解决您的示例的方法:

<TEI xmlns="http://www.tei-c.org/ns/1.0">
   <surname> Amblard </surname>
      <bibl>
          <author>
         <surname bilbo="True"> Amblard </surname>
         <forename bilbo="True"> F. </forename>
      </author>
          <c bilbo="True"> , </c>
          <author>
         <forename bilbo="True"> P. </forename>
      </author><title>titre</title>
          <author>
     <surname bilbo="True"> Amblard </surname>
  </author>
  </bibl>
</TEI>

List<String> expMsg = Arrays.asList("Line1", "Line2", "Line3", "Line4", "Line5", "Line6"); String actMsg = "Line1.\n" + "Line3\n" + "Line2\n" + "Line5\n" + "Line4\n" + "\n" + "Line6."; boolean containsAll = expMsg.stream() //select only elements which are in actMsg .filter(actMsg::contains) //e -> actMsg.contains(e) //all strings from expMsg should be present .count() == expMsg.size(); System.out.println(containsAll); 拆分所有行,并检查是否所有行都在expMsg中。