If I'm trying to see if a field on a web page is displaying some text, and I have the following function to dynamically do this:
public boolean isInformationFound(String info){
By infoText= By.xpath("//h5[text()='The info is:']/following::td[text()[contains(.,'"+info+"')]]");
return findElementBy(infoText).isDisplayed();
}
and in my test case:
Assert.assertEquals(foo.isInformationFound("hello"), true)
alternatively, what I could do is:
public String getInfo(){
By infoText= By.xpath("//h5[text()='The info is:']/following::td");
return findElementBy(infoText).getText();
}
and then in my test case function, I would do something like:
String expected info = "hello"
Assert.assertEquals(info, foo.getInfo())
Which method is better practice?