codeception (5)Yii2下测试ajax

ajax属于验收测试返回
我测试的这个ajax必须要先登录

use tests\codeception\frontend\AcceptanceTester;

$I = new AcceptanceTester($scenario);
$I->wantTo('perform actions and see result');
$I->amOnPage('/');    //切换到配置站点 http://admin.handone.com
$I->see('登录');    //断言可以在这个页面里看到指定的文字

$I->amGoingTo('try to login with correct credentials');
$I->fillField('input[name="LoginForm[t_email]"]', '用户名');
$I->fillField('input[name="LoginForm[t_password]"]', '密码');
$I->click('登录');
$I->expectTo('see that user is logged');
$I->seeLink('退出');
$I->dontSeeLink('登录');

登录成功后跳转到目标页面

$I->wantTo('perform actions and see result');
$I->amOnPage('http://xxx.xxx.xx/sales/index');    
$I->see('添加客户');

填写参数的情况下

$param = [
    'Sales[t_clues_cat]'=> 9,
    'keys_str' => 10449,
];
$I->sendAjaxRequest('post', 'http://xxx.xxx.xx/sales/sales-free', $param);
$I->seeResponseCodeIs(200);
$I->see('1');//1代表成功

参数为空的情况

$param = [];
$I->sendAjaxRequest('post', 'http://xxx.xxx.xx/sales/sales-free', $param);
$I->seeResponseCodeIs(200);
$I->see('2');//2代表失败

运行《codeception (5)Yii2下测试ajax》

查看运行情况 打印的信息太多,就不上图了

codecept run acceptance SalesCept --debug

参考文章:

http://www.kkh86.com/it/codec…
https://www.cloudxns.net/Supp…

    原文作者:zebrayoung
    原文地址: https://segmentfault.com/a/1190000006264851
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞