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

我对CodeCeption完全陌生。

我想根据另一个断言结果执行操作/断言,如下所示:

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

    $I->click('button_close');

}

这样的事情可能吗?我试过了,但不起作用。断言结果可能不适用于IF,但是有没有其他选择?

提前致谢!

重要更新:

终于 Codeception 现在有了 performOn 的功能!!http://codeception.com/docs/modules/WebDriver#performOn


答案 1

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

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

答案 2

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

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

然后在验收测试中使用:

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

推荐