javaseleniumverification

where I could find documentation on verification methods?


I use Assert class to check if some text is on the page, this command stop test executing if text is not present. I want use verification. Could someone tell where I could find documentation on such methods?

I mean WebDriver, junit. For example such code

String text=("Terms");
 List<WebElement> list = driver.findElements(By.xpath("//*[contains(text(),'" + text + "')]"));
 Assert.assertEquals("Text not found!", "Terms", list);

If there isn't text "Term" on page junit test will interrupt test, but I need just take error message and continue test.


Solution

  • If you want to continue execution of your test cases even if some some result you are expecting fails and get to see the results at the end of complete execution.

    You can do something like this -

    Declare a variable to store all the test case results which fail during execution and then in the tearDown method you can call Assert.fail(String message)

     StringBuffer errors = new StringBuffer();
    
     @Test
     public void testSomething(){
        if(!"data".equals(text)){
          addErrors(text +"not equal to data");
        }
    
        // add any number of if statements to check anything else 
     }
    
     @After()
     public void tearDown(){
       if(errors.length()!=0){         
         Assert.fail(errors.toString());
       } 
     }
    
     public String addErrors(String message){
       errors = errors.append(message+"\n");
     }
    

    Now in the testSomething() method you can check or test any number of WebElements on the webpage and all you have to do is have a simple if statement to check if some thing is correct and if not then call the addErrors() method. Hope this helps you.