Webtest cleanup and fixes
authorColeman Watts <coleman@civicrm.org>
Tue, 23 Sep 2014 02:17:33 +0000 (22:17 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 23 Sep 2014 02:17:33 +0000 (22:17 -0400)
tests/phpunit/WebTest/Contact/SearchTest.php
tests/phpunit/WebTest/Contact/TaskActionAddToGroupTest.php
tests/phpunit/WebTest/Event/PCPAddTest.php
tests/phpunit/WebTest/Export/ContactTest.php
tests/phpunit/WebTest/Export/ExportCiviSeleniumTestCase.php
tests/phpunit/WebTest/Import/GroupTest.php
tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php

index 1f10ce2524c3ac019afef04ea211cb3fc022dd78..23009ca26a3f846976a319a0bd0f0208f19dfc47 100644 (file)
@@ -236,8 +236,7 @@ class WebTest_Contact_SearchTest extends CiviSeleniumTestCase {
     $this->select("group", "label=$parentGroupName");
 
     // click to search
-    $this->click("_qf_Basic_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Basic_refresh");
 
     // Is contact present in search result?
     $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
index 337937759d315eeb217ad2466f2744ede36fdc33..91de5c92e20ce227f829b17e1224164b87197053 100644 (file)
@@ -110,8 +110,7 @@ class WebTest_Contact_TaskActionAddToGroupTest extends CiviSeleniumTestCase {
     $this->WebtestAddGroup($newGroupName);
 
     $this->openCiviPage('contact/search', 'reset=1');
-    $this->click("_qf_Basic_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Basic_refresh");
 
     $this->type("xpath=//*[@id='CRM_Contact_Form_Search_Basic-rows-per-page-select']", '25');
     $this->waitForElementPresent("toggleSelect");
index 061017417ac1bcd35c1fecde997928a69f252a89..768ee327378ac07dac1bc73ecad87c821354602f 100644 (file)
@@ -525,8 +525,7 @@ class WebTest_Event_PCPAddTest extends CiviSeleniumTestCase {
     $this->type("css=.crm-basic-criteria-form-block input#sort_name", $pcpCreatorFirstName);
 
     // click to search
-    $this->click("_qf_Basic_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Basic_refresh");
 
     $this->click("xpath=//div[@class='crm-search-results']//table/tbody//tr/td[3]/a[text()='{$sortName}']");
     $this->waitForPageToLoad($this->getTimeoutMsec());
index b741ca7c9e34b48c538d882b3b9f7599e3f02949..a385ee5cc80fd918977966352dccc37766b2aa0f 100644 (file)
@@ -40,7 +40,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
 
     // Create new  group
     $parentGroupName = 'TestSuffixPrefixGender_' . substr(sha1(rand()), 0, 7);
-    $this->addContactGroup($parentGroupName);
+    $this->WebtestAddGroup($parentGroupName);
 
     // Adding Parent group contact
     // We're using Quick Add block on the main page for this.
@@ -59,7 +59,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$parentGroupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForElementPresent("//*[@id='GroupContact']");
+    $this->waitForAjaxContent();
 
     $secondContactName = 'TestExport2' . substr(sha1(rand()), 0, 7);
     list($emailContactSecond,$prefixLabelContactScnd,$suffixLabelContactScnd,$genderLabelContactScnd) = WebTest_Export_ContactTest::webtestAddContactWithGenderPrefixSuffix($secondContactName, "John", "$secondContactName.john@example.org", Null);
@@ -75,7 +75,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$parentGroupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForElementPresent("//*[@id='GroupContact']");
+    $this->waitForAjaxContent();
 
     $this->openCiviPage("contact/search", "reset=1");
 
@@ -86,8 +86,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     $this->select("group", "label=$parentGroupName");
 
     // Click to search.
-    $this->click("_qf_Basic_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Basic_refresh");
 
     // Is contact present in search result?
     $this->assertElementContainsText('css=div.crm-search-results', $sortFirstName, "Contact did not found in search result!");
@@ -154,11 +153,11 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
 
     // Create new  group
     $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
-    $this->addContactGroup($parentGroupName);
+    $this->WebtestAddGroup($parentGroupName);
 
     // Create new group and select the previously selected group as parent group for this new group.
     $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
-    $this->addContactGroup($childGroupName, $parentGroupName);
+    $this->WebtestAddGroup($childGroupName, $parentGroupName);
 
     // Adding Parent group contact
     // We're using Quick Add block on the main page for this.
@@ -176,7 +175,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$parentGroupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForElementPresent("//*[@id='GroupContact']");
+    $this->waitForAjaxContent();
 
     // Adding child group contact
     // We're using Quick Add block on the main page for this.
@@ -194,7 +193,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to child group.
     $this->select("group_id", "label=regexp:$childGroupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForElementPresent("//*[@id='GroupContact']");
+    $this->waitForAjaxContent();
 
     // Visit contact search page.
     $this->openCiviPage("contact/search", "reset=1");
@@ -206,8 +205,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     $this->select("group", "label=$parentGroupName");
 
     // Click to search.
-    $this->click("_qf_Basic_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Basic_refresh");
 
     // Is contact present in search result?
     $this->assertElementContainsText('css=div.crm-search-results', $sortName, "Contact did not found in search result!");
@@ -265,7 +263,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
 
     // Create new  group
     $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7);
-    $this->addContactGroup($groupName);
+    $this->WebtestAddGroup($groupName);
 
     // Adding Parent group contact
     // We're using Quick Add block on the main page for this.
@@ -298,7 +296,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$groupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForElementPresent("//*[@id='GroupContact']");
+    $this->waitForAjaxContent();
 
     $firstName1 = 'aa' . substr(sha1(rand()), 0, 5);
     $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org");
@@ -314,7 +312,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$groupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForElementPresent("//*[@id='GroupContact']");
+    $this->waitForAjaxContent();
 
     $firstName2 = 'bb' . substr(sha1(rand()), 0, 5);
 
@@ -348,7 +346,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$groupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForElementPresent("//*[@id='GroupContact']");
+    $this->waitForAjaxContent();
 
     $this->openCiviPage("contact/search", "reset=1", NULL);
 
@@ -356,8 +354,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     $this->select("group", "label=$groupName");
 
     // Click to search.
-    $this->click("_qf_Basic_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Basic_refresh");
 
     // Is contact present in search result?
     $this->assertElementContainsText('css=div.crm-search-results', $sortName1, "Contact did not found in search result!");
@@ -412,39 +409,6 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
   }
 
-  /**
-   * @param string $groupName
-   * @param string $parentGroupName
-   */
-  function addContactGroup($groupName = 'New Group', $parentGroupName = "- select group -") {
-    $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
-
-    // Fill group name.
-    $this->type("title", $groupName);
-
-    // Fill description.
-    $this->type("description", "Adding new group.");
-
-    // Check Access Control.
-    $this->click("group_type[1]");
-
-    // Check Mailing List.
-    $this->click("group_type[2]");
-
-    // Select Visibility as Public Pages.
-    $this->select("visibility", "value=Public Pages");
-
-    // Select parent group.
-    $this->select("parents", "label=$parentGroupName");
-
-    // Clicking save.
-    $this->click("_qf_Edit_upload");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-
-    // Is status message correct?
-    $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
-  }
-
   /**
    * @param string $fname
    * @param string $lname
index e596c60ecaf506639fbd3faaba3f01cec0f3e0ca..45519dc91912879b7d1a5ce33343a621f3b92d25 100644 (file)
@@ -53,19 +53,17 @@ class ExportCiviSeleniumTestCase extends CiviSeleniumTestCase {
       @unlink($file);
     }
 
-    // Download file.
-    // File will automatically download without confirmation.
     $this->click($selector);
-    // Because it tends to cause problems, all uses of sleep() must be justified in comments
-    // Sleep should never be used for wait for anything to load from the server
-    // FIXME: consider doing the following assertion in a while loop
-    // with a more reasonable sleep time of 2 seconds per loop iteration
-    sleep(20);
 
-    // File was downloaded?
-    $this->assertTrue(file_exists($file), "CSV {$file} was not downloaded.");
-
-    return $file;
+    // Wait for file to be downloaded
+    for ($i=1; $i<15; ++$i) {
+      sleep(2);
+      if (file_exists($file)) {
+        return $file;
+      }
+    }
+    // Timeout
+    $this->fail("CSV {$file} was not downloaded.");
   }
 
   /**
index e9ce368e29a1e310e2f80a492b2f1848db0d6d09..65e27e8f43f5de36019c4313c8080669fa57af69 100644 (file)
@@ -64,8 +64,7 @@ class WebTest_Import_GroupTest extends ImportCiviSeleniumTestCase {
     // Select GroupName
     $this->select("group", "label={$groupName}");
 
-    $this->click("_qf_Basic_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Basic_refresh");
 
     // To Check Number Of Imported Contacts
     $this->assertTrue($this->isTextPresent("{$count} Contacts"), "Contacts Not Found");
@@ -86,8 +85,7 @@ class WebTest_Import_GroupTest extends ImportCiviSeleniumTestCase {
     // Select GroupName
     $this->select("group", "label={$groupName}");
 
-    $this->click("_qf_Basic_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Basic_refresh");
 
     // To Check Imported Contacts
     $this->assertTrue($this->isTextPresent("{$count} Contacts"), "Contacts Not Found");
index de90475c7a0cc35fdacb3406c18163a985600f69..7fb9f49ea7283460b529485b8e49cf2596491104 100644 (file)
@@ -69,12 +69,7 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
   ) {
 
     // Go to contact import page.
-    $this->open($this->sboxPath . $this->_getImportComponentUrl($component));
-
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-
-    // check for upload field.
-    $this->waitForElementPresent("uploadFile");
+    $this->openCiviPage($this->_getImportComponentUrl($component), 'reset=1', "uploadFile");
 
     // Create csv file of sample data.
     $csvFile = $this->webtestCreateCSV($headers, $rows);
@@ -209,8 +204,7 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
    * @param array $other
    * @param string $type
    */
-  function importContacts($headers, $rows, $contactType = 'Individual', $mode = 'Skip', $fieldMapper = array(
-    ), $other = array(), $type = 'csv') {
+  function importContacts($headers, $rows, $contactType = 'Individual', $mode = 'Skip', $fieldMapper = array(), $other = array(), $type = 'csv') {
 
     // Go to contact import page.
     $this->openCiviPage("import/contact", "reset=1", "uploadFile");
@@ -251,15 +245,8 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
 
     // Select contact subtype
     if (isset($other['contactSubtype'])) {
-      if ($contactType != 'Individual') {
-        // Because it tends to cause problems, all uses of sleep() must be justified in comments
-        // Sleep should never be used for wait for anything to load from the server
-        // FIXME: this is bad, using sleep to wait for AJAX
-        // Need to use a better way to wait for contact subtypes to repopulate
-        sleep(5);
-      }
-      $this->waitForElementPresent("subType");
-      $this->select('subType', 'label=' . $other['contactSubtype']);
+      $this->waitForElementPresent("css=#subType option[value={$other['contactSubtype']}]");
+      $this->select('subType', $other['contactSubtype']);
     }
 
     if (isset($other['dedupe'])) {
@@ -289,8 +276,7 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
     }
 
     // Submit form.
-    $this->click('_qf_DataSource_upload');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink('_qf_DataSource_upload');
 
     if (isset($other['checkMapperHeaders'])) {
       $checkMapperHeaders = $other['checkMapperHeaders'];
@@ -461,13 +447,12 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
    *
    * @return mixed
    */
-  function _getImportComponentUrl($component) {
-
+  private function _getImportComponentUrl($component) {
     $importComponentUrl = array(
-      'Event' => 'civicrm/event/import?reset=1',
-      'Contribution' => 'civicrm/contribute/import?reset=1',
-      'Membership' => 'civicrm/member/import?reset=1',
-      'Activity' => 'civicrm/import/activity?reset=1',
+      'Event' => 'event/import',
+      'Contribution' => 'contribute/import',
+      'Membership' => 'member/import',
+      'Activity' => 'import/activity',
     );
 
     return $importComponentUrl[$component];