[英]Codeception remains at the same page after clicking submit button
I'm testing a form in Yii2 with Codeception and when I click on submit button and expect to be redirected to another url (by javascript) after recieving a ok via Ajax. 我正在使用Codeception在Yii2中测试一个表单,当我单击“提交”按钮,并希望在通过Ajax收到确定后,希望重定向到另一个URL(通过javascript)。 I use
wait(3)
method to give it some time to do the redirect, but when I check the url with dontSeeInCurrentUrl()
method I'm always at the same page. 我使用
wait(3)
方法给它一些时间来进行重定向,但是当我使用dontSeeInCurrentUrl()
方法检查url时,我总是在同一页面上。
Why is this happening? 为什么会这样呢?
<?php
$newFamily = [
'name' => 'testFamily'
];
$I->amOnPage('/backend/web/index.php/foobar/create');
$I->seeInCurrentUrl('create');
$I->amGoingTo('try to submit without having enter a name');
$I->click('#submitBtn');
$I->expect('not to have changed of location');
$I->seeInCurrentUrl('create');
$I->amGoingTo('check that parent family select is unchecked');
$I->dontSeeCheckboxIsChecked('#isSuperior');
$I->fillField('#familynutriment-name', $newFamily['name']);
$I->click('#submitBtn');
$I->expectTo('be in another location');
$I->wait(3);
$I->dontSeeInCurrentUrl('create');
$I->seeInDatabase('family_nutriment', $newFamily);
I'm assuming you're using the default PHP Browser, since you didn't mention anything else. 我假设您使用的是默认的PHP浏览器,因为您没有提及其他任何内容。 This browser cannot handle JavaScript, so the AJAX/event isn't happening.
该浏览器无法处理JavaScript,因此不会发生AJAX /事件。 You will need to use Selenium, or some other browser that can handle the JS.
您将需要使用Selenium或其他可以处理JS的浏览器。
http://codeception.com/docs/03-AcceptanceTests#PHP-Browser http://codeception.com/docs/03-AcceptanceTests#PHP-Browser
Common PhpBrowser drawbacks:
PhpBrowser的常见缺点:
- you can click only on links with valid urls or form submit buttons
您只能单击具有有效网址或表单提交按钮的链接
- you can't fill fields that are not inside a form
您不能填写不在表单内的字段
- you can't work with JavaScript interactions: modal windows, datepickers, etc.
您不能使用JavaScript交互:模式窗口,日期选择器等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.