首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在条件(if)语句中使用CodeCeption断言

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

Stack Overflow用户
提问于 2014-10-04 01:28:08
回答 8查看 10.9K关注 0票数 25

我对CodeCeption完全是新手。

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

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

    $I->click('button_close');

}

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

提前感谢!

重要更新:

最后,Codeception现在有了函数performOn!!http://codeception.com/docs/modules/WebDriver#performOn

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2015-12-18 10:55:35

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

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

Stack Overflow用户

发布于 2016-04-15 19:45:50

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");
}
票数 8
EN

Stack Overflow用户

发布于 2014-11-12 21:46:35

您可以使用类似这样的解决方法或类似的组合:

$tmp = $I->grabTextFrom('SELECTOR');
if ($tmp == 'your text') {

$I->click('button_close');

}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26183792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档