During test I need to do following:
My Code:
$this->byId('reg_email')->value('[email protected]');
$this->byId('reg_password')->value('seecret');
// No form here, so i can't just call submit()
// This click invokes ajax request
$this->byId('reg_submit')->click();
// Check page content (this page should appear after redirect)
$msg = $this->byCssSelector('h1')->text();
$this->assertEquals('Welcome!', $msg);
Problem
Solution, I do not like:
sleep(3);
before content check.I do not like it because:
I wonder, is there any way to track ajax request+refresh and check for content just in time?
My setup:
Ok, there is a kind of solution, I do not really like it, but it is something instead of nothing.
The idea is to use more smart "sleep", there is a method waitUntil()
which takes an anonymous function
and timeout
in milliseconds. What is does - runs this passed function in loop until timeout hits or your function return True
. So you can run something and wait until context is changed:
$this->waitUntil(function () {
if ($this->byCssSelector('h1')) {
return true;
}
return null;
}, 5000);
I still will be glad if somebody give better solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With