CiviCRM presents status messages in a slick overlay, which looks neat for human users but has been hard for me to test for in Selenium. It appears the messages first appear within the main page content, but are then moved into the overlay div, where they appear on-screen only for several seconds before fading.

I'm guessing CiviCRM's own Selenium tests have standardized a variation on assertText() that works with this overlay, but I've not dug around enough to find it.

How would one detect the presence of a given status message, in Selenium IDE and in phpunit?

  • SeleniumTestCase, or Selenium2TestCase? Apr 26 '17 at 23:36
  • @jackrabbithanna I'm thinking it probably doesn't matter. I'm using (and civicrm uses) SeleniumTestCase, but if there's a way in Selenium2TestCase that would be a good start.
    – TwoMice
    May 3 '17 at 14:52

So one possibility is to use Selenium2TestCase as your base class for you test...

I've been using Selenium Standalone Server 3.3 (looks like 3.4 just released) http://www.seleniumhq.org/download/

So its a little different that SeleniumTestCase, because Selenium 2 uses the WebDriver, and support for firefox may require you install the third party gecko drivers, there's a chrome driver there too that works really well.

So I have a test class that extends Selenium2TestCase , and added this helper function:

   * Utility function to wait for an element to be displayed
   * @param $elementCssPath
   * @param $timeout
   * @return \PHPUnit_Extensions_Selenium2TestCase_Element
   * @throws Exception
  public function findElementWaitUntilDisplay($elementCssPath, $timeout){
    $this->waitUntil(function() use($elementCssPath){
      if ($element = $this->byCssSelector($elementCssPath)) {
        if($element->displayed()) {
          return true;
        else {
          return null;
      return null;
    }, $timeout);
      $element = $this->byCssSelector($elementCssPath);
      return $element;
    catch(Exception $e){
      throw $e;

So then you may have a test use it like so:

testStatusMessageDisplayed() {
  $status_message_element = $this->findElementWaitUntilDisplay('whatever-your-css-selector-is', 5000); //wait 5s for status message to appear
  $this->assertEquals('expected text', $status_message_element->text());

This helper function has been coming in handy, whether I am waiting for a page to load, or an ajax request, or some javascript rewrite the dom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.