【问题标题】:Error when trying to accept a native js popup with Codeception and Yii2尝试使用 Codeception 和 Yii2 接受本机 js 弹出窗口时出错
【发布时间】:2015-06-28 05:59:46
【问题描述】:

我正在尝试关闭 Yii2 生成的确认 js 弹出窗口,以确认删除记录,在本例中为用户,使用 Codeception 和他的。

以下是错误:

[WebDriverException] 远程响应的 JSON 解码失败。 错误代码:4 响应:'无效的命令方法 - 请求 => {"headers":{"Accept":"application/json","Content-Length":"0","Content-Type":"application/json;charset= UTF-8","Host":"127.0.0.1:4444"},"httpVersion":"1.1","method":"GET","url":"/alert_text","urlParsed":{"anchor ":"","query":"","file":"alert_text","directory":"/","path":"/alert_text","re​​lative":"/alert_text","port": "","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":" /alert_text","queryKey":{},"chunks":["alert_text"]},"urlOriginal":"/session/cac855f0-e7f8-11e4-ae75-8baa74cf41b1/alert_text"}'

下面是我的代码:

<?php 
$username = 'foobar';
$email = 'foo@bar.com';

$I = new AcceptanceTester($scenario);
$I->wantTo('Check that users can update their passwords');

$I->haveInDatabase('user', array('username' => $username, 'email' => $email));
$id = $I->grabFromDatabase('user', 'id', array('username' => $username, 'email' => $email));

$I->amOnPage("/backend/web/index.php/user/$id");
$I->see('Borrar');
$I->click('Borrar');

$I->wait(3);
## This line throws the error
$I->seeInPopup('eliminar este usuario');
## Trying to change to the popup. This doesn't throw any error
$I->executeInSelenium(function (Webdriver $webdriver) {
   $handles=$webdriver->getWindowHandles();
   $last_window = end($handles);
   $webdriver->switchTo()->window($last_window);
});
$I->pressKey('body', \WebDriverKeys::ENTER);
## This throwed the error before
$I->acceptPopup();
$I->wait(1);

$I->seeInCurrentUrl('user/list');
$I->dontSeeInDatabase('user', array('username' => $username, 'email' => $email));

【问题讨论】:

    标签: php testing yii2 codeception acceptance-testing


    【解决方案1】:

    据我所知,下面的代码告诉 Codeception 完全改变浏览器窗口。我实际上只是用这个确切的代码块编写了一个测试来更改浏览器窗口。也许尝试删除它或评论它并尝试再次运行测试?就我所见,弹出部分看起来还不错

    $I->executeInSelenium(function (Webdriver $webdriver) {
        $handles=$webdriver->getWindowHandles();
        $last_window = end($handles);
        $webdriver->switchTo()->window($last_window);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      相关资源
      最近更新 更多