Answers.Body: <p>So one possibility is to use Selenium2TestCase as your base class for you test...</p>
  
  <p>I've been using Selenium Standalone Server 3.3 (looks like 3.4 just released)
  <a href="http://www.seleniumhq.org/download/" rel="nofollow noreferrer">http://www.seleniumhq.org/download/</a></p>
  
  <p>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.</p>
  
  <p>So I have a test class that extends Selenium2TestCase , and added this helper function:</p>
  
  <pre><code>/**
     * 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-&gt;waitUntil(function() use($elementCssPath){
        if ($element = $this-&gt;byCssSelector($elementCssPath)) {
          if($element-&gt;displayed()) {
            return true;
          }
          else {
            return null;
          }
        }
        return null;
      }, $timeout);
      try{
        $element = $this-&gt;byCssSelector($elementCssPath);
        return $element;
      }
      catch(Exception $e){
        throw $e;
      }
    }
  </code></pre>
  
  <p>So then you may have a test use it like so:</p>
  
  <pre><code>testStatusMessageDisplayed() {
    $status_message_element = $this-&gt;findElementWaitUntilDisplay('whatever-your-css-selector-is', 5000); //wait 5s for status message to appear
    $this-&gt;assertEquals('expected text', $status_message_element-&gt;text());
  }
  </code></pre>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-03T18:10:45.440Z
Answers.LastActivityDate: 2017-05-03T18:10:45.440Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>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.</p>
  
  <p>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.</p>
  
  <p>How would one detect the presence of a given status message, in Selenium IDE and in phpunit?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-26T23:36:57.473Z
Comments.Text: SeleniumTestCase, or Selenium2TestCase?
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-03T14:52:21.710Z
Comments.Text: @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.
Comments.UserDisplayName: TwoMice
Tags: <testing>
Title: How to test for CiviCRM status messages in selenium?
ThreadText: # How to test for CiviCRM status messages in selenium?
  
  (Asked by: username_0 on 2016-05-16)
  
  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?
  
  **Tags:** testing
  
  > **Comments:**
  > **username_1**: SeleniumTestCase, or Selenium2TestCase?  
  > **username_0**: @username_1 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-05-03. Score: 2
  
  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);
      try{
        $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.
  
  
  ---
  
  