请考虑以下代码:
$this->visit('/');
$text = $this->byCssSelector('.some-element')->text();
$this->byCssSelector('.some-link')->click();
# how do I wait for a new page to be loaded here?
$this->assertEquals($text, $this->byCssSelector('.some-element')->text());
答案 0 :(得分:0)
您可以设置(通过js调用)window.is_old_page = true
,然后检查这将是undefined
答案 1 :(得分:0)
从我在网上看到的内容,如果可能的话,应该避免执行javascript,所以我提出了非JavaScript解决方案:
$this->visit('/');
$text = $this->byCssSelector('.some-element')->text();
$this->waitForPageReload(function () {
$this->byCssSelector('.some-link')->click();
}, 5000);
$this->assertEquals($text, $this->byCssSelector('.some-element')->text());
function waitForPageReload($navigate_f, $timeout) {
$id = $this->byCssSelector('html')->getId();
call_user_func($navigate_f);
$this->waitUntil(function () use ($id) {
$html = $this->byCssSelector('html');
if ($html->getId() != $id)
return TRUE;
}, $timeout);
}
受此great article的启发。
答案 2 :(得分:0)
在某些情况下,您可以使用睡眠功能:
sleep($seconds);