在条件(if)语句中使用CodeCeption断言

Bor*_*sky 21 php conditional if-statement assertion codeception

我是CodeCeption的新手.

我想根据另一个断言结果做一个动作/断言,如下所示:

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

    $I->click('button_close');

}
Run Code Online (Sandbox Code Playgroud)

有可能吗?我试过了,但没办法.可能断言结果不适用于IF,但还有其他选择吗?

提前致谢!

重要更新:

最后Codeception现在有了这个功能performOn!! http://codeception.com/docs/modules/WebDriver#performOn

DAB*_*DAB 16

我有同样的问题.虽然它不理想,但你可以这样做:

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


Mat*_*ija 8

tests/_support/AcceptanceHelper.php添加其他方法

function seePageHasElement($element)
{
    try {
        $this->getModule('WebDriver')->_findElements($element);
    } catch (\PHPUnit_Framework_AssertionFailedError $f) {
        return false;
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

然后在验收测试中测试使用:

if ($I->seePageHasElement("input[name=address]")) {
    $I->fillField("input[name=address]", "IM");
}
Run Code Online (Sandbox Code Playgroud)