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

时间:2015-04-24 10:13:48

标签: javascript ajax yii2 codeception

我正在使用Codeception在Yii2中测试一个表单,当我点击提交按钮并希望在通过Ajax收到ok后重定向到另一个url(通过javascript)。 我使用wait(3)方法给它一些时间来进行重定向,但是当我使用dontSeeInCurrentUrl()方法检查网址时,我总是在同一页面上。

为什么会这样?

<?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);

1 个答案:

答案 0 :(得分:0)

我假设您使用的是默认的PHP浏览器,因为您没有提及任何其他内容。此浏览器无法处理JavaScript,因此AJAX /事件不会发生。您将需要使用Selenium或其他可以处理JS的浏览器。

http://codeception.com/docs/03-AcceptanceTests#PHP-Browser

  

常见的PhpBrowser缺点:

     
      
  • 您只能点击包含有效网址或表单提交按钮的链接
  •   
  • 您无法填写不在表单中的字段
  •   
  • 您无法使用JavaScript互动:模态窗口,日期选择器等
  •