2015-04-24 68 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交互:模式窗口,日期選擇器等。