Boolean Asserts = True


Hi all:
This is my first time posting and I am hoping someone can help.

I am opening a web app and ensuring that an element exists on the nav bar. So in my page object file, called, I have the following element
public class SEPNavBar {

// Additional data: {"img":"screenshots/bd432ba4-8bc2-361b-56d4-d76013ee4097.png"}
private By Actions = By.cssSelector("[href='\\/sep19\\/Actions\\/Index'] span");

Then below I have:

public Boolean actionsPresent() {
Boolean ActionsIsPresent = driver.findElements(this.Actions).size() > 0;

    return ActionsIsPresent;

Now in my text file, I call ActionsPresent();

And now I want to do an assert-- I want to see the return value of ActionIsPresent, which I would presume to be a true or false, but how to I get the assert to work?



Hi @micheleaz!
So you want to assert that your element is present, right?
There is a simple way of doing this using the Assert.assertTrue(boolean condition) method.

Basically, in your Test file use something like this:

// This is the element status boolean that you create by calling your function from your PageObject file
boolean elementStatus = SEPNavBar.actionsPresent();

// Use the Assert.assertTrue to confirm the true/false status

Furthermore, you could use the Assert.assertTrue(boolean condition, string Message) method and add some custom message if the assert is true, or using some if statements with the element status.boolean.
Hope this helps,


Thank you! That is exactly what I needed.

closed #4