简体   繁体   English

代码接收如何从yii2中的警报中获取文本?

[英]How can the codeception get the text from alert in yii2?

I've the problem. 我有问题。 I want to get some texts from alert that created by yii2 when the input text was blank. 当输入文本为空白时,我想从yii2创建的警报中获取一些文本。 So here is test case on codeception (functional): 所以这是关于代码接收(功能)的测试用例:

public function submitEmptyForm(\FunctionalTester $I)
    {
        $I->submitForm('#contact-form', []);
        $I->expectTo('see validations errors');
        $I->see('Contact', 'h1');
        $I->see('Name cannot be blank');
        $I->see('Email cannot be blank');
        $I->see('Subject cannot be blank');
        $I->see('Body cannot be blank');
        $I->see('The verification code is incorrect');
    }

And I ran that code, but I found the error in line: 我运行了该代码,但是发现以下错误:

$I->see('Name cannot be blank');

When I spec the code with inspect element, Here's the alert that I got: 当我使用inspect元素指定代码时,这是我收到的警报:

<p class="help-block help-block-error">Name cannot be blank.</p>

How can I get the alert text when the doesn't have name or id ? 没有名称或ID时如何获取警报文本? I read "How to call element in codeception" in codeception.com, you should be called by name or id. 我在codeception.com上阅读了“如何在Codeception中调用元素”,应按名称或ID进行调用。

使文本完全匹配,因此将句号添加到末尾并指定如下所示的类,它将找到它。

$I->see('Name cannot be blank.', '.help-block');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM