【发布时间】:2015-03-16 16:52:52
【问题描述】:
我使用 Codeception 和 WebDriver 进行了一个非常简单的验收测试。它测试使用 Hybridauth 登录(“通过...登录”*一些社交网络)。
代码:
$I = $i = new AcceptanceTester($scenario);
$I->wantTo('Register using VK account (hybridauth) and check that friends list is loaded');
$I->amOnPage('/');
$I->see('VKontakte');
$I->click("VKontakte");
$__HANDLES= null;
$I->executeInSelenium(function (\WebDriver $webdriver) {
GLOBAL $__HANDLES;
$__HANDLES = $webdriver->getWindowHandles();
$webdriver->switchTo()->window(end($__HANDLES));
}); // VK's popup loaded
codecept_debug($I->grabTextFrom('#install_allow'));
$I->seeElement('.box_login');
$I->fillField('email', '******');
$I->fillField('pass', '******');
$I->click($I->grabTextFrom('#install_allow'));
$I->dontSeeElement('.oauth_error');
此测试中的每一行都成功执行,但最后Codeception抛出一个异常,抱怨“没有窗口”:
[NoSuchWindowException]
Window not found. The browser window may have been closed.
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: '***', ip: '***', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-4-amd64', java.version: '1.7.0_65'
Driver info: driver.version: unknown
问题是——如何管理这种情况以使测试顺利进行? $I->switchToWindow(); 没有帮助。
*** 更新:
解决。答案很简单:$I->dontSeeElement('.oauth_error'); 在窗口已经关闭时被触发。所以我们需要先切换窗口,然后才断言一些东西。
【问题讨论】:
标签: php selenium-webdriver webdriver codeception