2015-04-24 73 views
0

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

这是怎么发生的?

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

回答

0

我假设你使用的是默认的PHP浏览器,因为你没有提到其他的东西。这个浏览器无法处理JavaScript,所以AJAX /事件没有发生。您需要使用Selenium或其他可以处理JS的浏览器。

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

常见PhpBrowser缺点:

  • ,你只能在具有有效的URL链接点击或表单提交按钮
  • 可以不填不属于形式
  • 内场
  • 您无法使用JavaScript交互:模式窗口,日期选择器等。