Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
182 views
by The go-to Tester (158 points)
I have element,for example //div[@class='create-button'].
My test assert that for some users without admin rights this button not visible.

Assert.False(pageObject.IsElementDisplayed());

where:

public bool IsElementDisplayed() {

     try{

           element.Displayed;

           return true;

     }

     catch(NotFoundElementException){

           return false;

     }

}

Someone in my team change button class. Locator is broken. Now method IsElementDisplayed() always return false and my test always pass. This is a false positive result. How to avoid such results?

1 Answer

1 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer
I suggast you to throw NotFoundElementException instead of handling it. You should handle element not found exception saparatly. Instead of simply returning false, you should log exception and throw exception back to the method where it's called. So you can fail the test.
 
As per your requirement, you should identify if element is visible or not. But with your custom method you are explictly ignoring element presence. We already have a method called isDisplayed (), you should be using that.
 
Hope that helps!


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...