Search code examples
javaseleniumselenium-webdrivertestngassertion

How to use Assert method and Selenium with TestNg framework to compare two integers


I am practicing Selenium using the TestNG framework and assertion and there are 3 things that I can't solve. note: there is no page for XPath.. integers are static.

  1. selenium script to Compare 3 and 5.

  2. selenium script to get boolean result of 3>5.

  3. Selenium script for a string to check palindrom.


Solution

  • https://www.javadoc.io/doc/org.testng/testng/latest/org/testng/Assert.html

    see the full list of support assertion , so there is no specific method for checking greater than, use equals and true.

    import org.testng.Assert;
    
    Assert.assertEquals(2, 2);
    Assert.assertFalse( 2 > 30 , "comparing 2 greater than 30");
    Assert.assertEquals("teet", new StringBuilder("teet").reverse().toString());
    
    Assert.assertTrue("teet".contentEquals(new StringBuilder("teet").reverse().toString())