简体   繁体   English

单击提交按钮后,Codeception保留在同一页面上

[英]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.

相关问题 单击提交按钮后停留在同一页面上 - Staying on same page after clicking submit button 单击“提交”按钮后无法重新加载同一页面 - Unable to reload the same page after clicking submit button 单击提交按钮后页面被重新加载 - Page gets reloaded after clicking the submit button 使用onclick功能单击“提交”按钮后,HTML页面正在刷新 - HTML page is refreshing after clicking on submit button with onclick function 单击提交按钮后重定向到另一个页面并传递变量 - Redirecting to another page and passing variables after clicking a submit button 单击子页面时,该页面的URL为什么总是保持不变? - How come the URL of this page always remains the same when clicking on subpages? 在 IE11 Windows 8.1 上,单击后按钮保持突出显示 - On IE11 Windows 8.1, button remains highlighted after clicking 单击提交按钮后禁用选择按钮 - Disable a select button after clicking on submit button 如果用户中断重定向到新页面,则禁用提交按钮将保持禁用状态 - Disabled submit button remains Disabled if a user interrupts redirecting to a new page 即使依赖数组 object 保持不变,在单击按钮时重新渲染页面仍保留在 Reactjs 中 - Re-render page on clicking button even though dependency array object remains unchanged remains in Reactjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM