Just started using SauceOnDemand and was working on adding some new functionality that they offered. One of them is the spinAssert, which is the equivalent of pausing or issuing a waitFor* before asserting something. That’s bad practice because it slows down tests, so spinAssert keeps trying the assertion a set number of times until it fails. This should get rid of our intermittently failing tests!
So I had
1 |
$this->assertTextPresent('Some text on a page.', 'Did not find "Some text on a page."') |
But there isn’t really an assertTextPresent in the driver. So here’s the spinAssert alternative:
1 2 3 4 5 6 7 8 |
$driver = $this; $search = 'Some text.'; $spin_test = function() use ($search, $driver) { $text = $driver->getBodyText(); return (strpos($text, $search) !== FALSE); }; $this->spinAssert('Did not find text "' . $target, $spin_test); |
Ta da!