'How to use verifyText for comparing two strings?

As we know, assert continues the execution but verify stops the execution the moment the script fails. e.g suppose two string abc, abd xyz

i want to verify the two strings. How to verify them without using Assert.assertEquals(expected, actual);

Can anyone please guide me for the same?



Solution 1:[1]

You can verify the 2 strings by creating a method and using if else to compare them. In your example instead of assert this can be done

 public void compareMethod()
 {
    string expected = "abc";
    string actual = "xyz";
    if(expected == actual) 
       {
         //do steps required
       } 
    else
       {
       }
 } 

Solution 2:[2]

If you have already stored strings and want to verifyText using Selenium WebDriver then the following code will surely help..

 if("expected String".equals("actual string"))
   {
      System.out.println("String matches ");
   }
 else
  {
      System.out.println("String does not match ");
  }

Try this

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jessica
Solution 2 Tanushree