Use CodeCeption assertion in conditional (if) statement

Borjovsky picture Borjovsky · Oct 3, 2014 · Viewed 9.8k times · Source

I'm totally new with CodeCeption.

I want to do an action/assertion depending on another assertion result, like this:

if ($I->see('message')){

    $I->click('button_close');

}

Is something like that possible? I tried, but doesn't work. Probably the assertion result doesn't apply to IF, but is there any alternative?

Thanks in advance!

IMPORTANT UPDATE:

Finally Codeception now has the function performOn!! http://codeception.com/docs/modules/WebDriver#performOn

Answer

DAB picture DAB · Dec 18, 2015

I had this same issue. Although it's not ideal, you can do this:

try {
    $I->see('message');
    // Continue to do this if it's present
    // ...
} catch (Exception $e) {
    // Do this if it's not present.
    // ...
}