Search code examples
phpif-statementconditional-statementsassertioncodeception

Use CodeCeption assertion in conditional (if) statement


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


Solution

  • 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.
        // ...
    }