converting phpunit-selenium assertTextPresent to spinAssert

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

$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:

$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!