Elsid
Elsid

Reputation: 243

assertTrue multiple values in webdriver java

I want to assert.true 2 different value, one or the other.

I am getting the value of the background color, which is being changed, so it can have two different colors as the option.

This is what I have:

Assert.assertTrue(Assert_BG1.contains("0, 255, 1, 1"));

But I want it to assertTrue that value and if that value is not present, assert the next value. I know you cannot write if and statements with assertTrue.

What would be the easiest way to achieve this in Java?

Thanks

Upvotes: 1

Views: 2185

Answers (1)

aholt
aholt

Reputation: 2971

Assert.assertTrue(Assert_BG1.contains("0, 255, 1, 1") ? true : <enter other check here>);

This is basically an inline if statement (not exactly, but it functions similarly, and a lot of if statements can be replaced by it)

Syntax

<boolean expression> ? <if boolean expression true, execute this> : <if boolean expression false, execute this>;

Other Examples

Object foobar = null;
String foobarString = foobar != null ? foobar.toString() : "";

The above would check to see if the "foobar" Object is null before calling "toString()" on it, preventing a possible NullPointerException.

Upvotes: 1

Related Questions