为了测试应用程序我目前使用的Codeception 2.2。我到目前为止的步骤如下:
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('perform actions and see result');
$I->amOnPage('/index.php');
$I->fillField('username', 'admin');
$I->fillField('password', 'password');
$I->click('Sign in');
$I->amOnPage('/index.php?module=CustomReports&view=Edit');
$I->fillField('relatedclient', '******');
$I->fillField('policynumber', '****');
$I->click('Save');
$I->see('You are being redirected to the clients isa report.');
$I->click('OK'); // This is where it fails
$I->see('Client ISA Statement');
?>
目前我使用PHP与在线JS这是在错误发生。我想知道我怎么能接受window.alert以进入下一个页面。我曾尝试$I->click('OK')
但似乎并没有工作。
谢谢
这是codeception一个非常令人困惑的事情。你可以试试
$I->acceptPopup()
不幸的是,可能是因为它不工作。这是由selenium2驱动程序引起的。有时,当浏览器都扔提醒他们不能得到钩。我看到有关这些警报真的很令人困惑的东西。
试试这个方法:
$I = $this->tester;
$I->amGoingTo("check whether any JS alert appears and accept it");
$I->executeInSelenium(function (\Facebook\WebDriver\WebDriver $webdriver) {
try {
$webdriver->wait(1.5, 200)->until(
WebDriverExpectedCondition::alertIsPresent()
);
$webdriver->switchTo()->alert()->accept();
} catch (Exception $e) {
echo("###ERROR: oops, didnt manage to find the alert. Exception: '" . $e->getTraceAsString() . "'
Please contact test developers for investgation");
}
});
if (strlen($this->errorMessage) > 0) {
$I->comment($this->errorMessage);
}
希望这可以帮助你。问候,
可能工作的另一件事是使用一个更具体的选择为“确定”按钮。
这里有一个为我工作:
$I->click("//button[contains(@class, 'x-btn-text') and text() = 'OK']");
在这种情况下的“按钮”是HTML标签我要点击“X-BTN-文本”是类的按钮和“OK”时,在标签内的文本。
如果按钮有一个唯一的ID(或者你可以添加一个),这是更简单:
<button id="button_id" type="button">OK</button>
$I->click('#button_id');
需要注意的是,除非你使用的webdriver可以为您验收测试,这可能无法正常工作。
尝试了这一点
try {
$I->click('i.e. CLOSE BUTTON OF YOUR POPUP ELEMENT');
} catch (\PHPUnit_Framework_Exception $e) {
// failed assertion handled
}
这是最后的工作:
$I->waitForElementVisible("//button[contains(@class, 'x-btn-text') and text() = 'Yes']");
$I->click("//button[contains(@class, 'x-btn-text') and text() = 'Yes']");