我正在尝试关闭由Yii2生成的确认js弹出窗口,以使用Codeception及其他的用户来确认记录(在本例中为用户)的删除。
下面是错误:
下面是我的代码:
<?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));
最佳答案
据我所知,以下代码告诉Codeception完全更改浏览器窗口。我实际上只是使用此确切的代码块编写了一个测试,以更改浏览器窗口。也许尝试删除它或对其进行评论,然后尝试再次运行测试?据我所知,弹出部分看起来还不错
$I->executeInSelenium(function (Webdriver $webdriver) {
$handles=$webdriver->getWindowHandles();
$last_window = end($handles);
$webdriver->switchTo()->window($last_window);
});