Webtest fixes
authorColeman Watts <coleman@civicrm.org>
Thu, 18 Sep 2014 14:11:43 +0000 (10:11 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 18 Sep 2014 14:11:43 +0000 (10:11 -0400)
tests/phpunit/CiviTest/CiviSeleniumTestCase.php
tests/phpunit/WebTest/Contact/AdvancedSearchTest.php
tests/phpunit/WebTest/Event/AddEventTest.php

index 16934bd915841c0462d4166a3150c8399bac124d..1c2037434099301fbd3aae57f9bcdb1f85449117 100644 (file)
@@ -237,17 +237,16 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Click a popup link and wait for the ajax content to load
+   * Click a link or button and wait for the ajax content to load
    * @param string $element
    * @param string $waitFor
    */
-  function clickPopupLink($element, $waitFor) {
+  function clickAjaxLink($element, $waitFor = 'css=.ui-dialog') {
     $this->click($element);
-    $this->waitForElementPresent('css=.ui-dialog');
-    $this->waitForAjaxContent();
     if ($waitFor) {
       $this->waitForElementPresent($waitFor);
     }
+    $this->waitForAjaxContent();
   }
 
   /**
@@ -269,6 +268,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    */
   function waitForAjaxContent() {
     // Add sleep to prevent condition where we click an ajax button and call this function before the content has even started loading
+    // TODO: When test suite is more stable, try removing sleep() and see if it breaks anything
     sleep(1);
     $this->waitForElementNotPresent('css=.blockOverlay');
   }
@@ -718,7 +718,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    *
    * @param string $financialAccount
    * @throws PHPUnit_Framework_AssertionFailedError
-   * @return void
+   * @return int
    */
 
   function webtestAddPaymentProcessor($processorName, $processorType = 'Dummy', $processorSettings = NULL, $financialAccount = 'Deposit Bank Account') {
@@ -766,8 +766,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     if (empty($pid)) {
       $this->fail("$processorType processortype not found.");
     }
-    $this->open($this->sboxPath . 'civicrm/admin/paymentProcessor?action=add&reset=1&pp=' . $pid);
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->openCiviPage('admin/paymentProcessor', 'action=add&reset=1&pp=' . $pid, 'name');
     $this->type('name', $processorName);
     $this->select('financial_account_id', "label={$financialAccount}");
 
@@ -775,14 +774,14 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
       $this->type($f, $v);
     }
 
-    // Is new processor created?
-    $this->click('_qf_PaymentProcessor_next-bottom');
+    // Save
+    $this->clickLink('_qf_PaymentProcessor_next-bottom');
+
     $this->waitForTextPresent($processorName);
-    $this->assertTrue($this->isTextPresent($processorName), 'Processor name not found in selector after adding payment processor (webTestAddPaymentProcessor).');
 
-    $paymentProcessorId = explode('&id=', $this->getAttribute("xpath=//table[@class='selector row-highlight']//tbody//tr/td[text()='{$processorName}']/../td[7]/span/a[1]@href"));
-    $paymentProcessorId = explode('&', $paymentProcessorId[1]);
-    return $paymentProcessorId[0];
+    // Get payment processor id
+    $paymentProcessorLink = $this->getAttribute("xpath=//table[@class='selector row-highlight']//tbody//tr/td[text()='{$processorName}']/../td[7]/span/a[1]@href");
+    return $this->urlArg('id', $paymentProcessorLink);
   }
  
   function webtestAddCreditCardDetails() {
@@ -2085,6 +2084,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @return array
    */
   function addCustomGroupField($customSets) {
+    $return = array();
     foreach ($customSets as $customSet) {
       $this->openCiviPage("admin/custom/group", "action=add&reset=1");
 
@@ -2120,6 +2120,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
       $return[] = array(
         "{$customSet['entity']}_{$customSet['subEntity']}" => array('cgtitle' => $customGroupTitle, 'gid' => $gid, 'triggerElement' => $customSet['triggerElement']));
     }
+    // Avoid weird qf_key bug when going straight from here to the next form
+    $this->openCiviPage('');
     return $return;
   }
 
@@ -2127,6 +2129,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * function to type and select first occurance of autocomplete
    */
   function select2($fieldName,$label, $multiple = FALSE, $xpath=FALSE) {
+    // In the case of chainSelect, wait for options to load
+    $this->waitForElementNotPresent('css=select.loading');
     if ($multiple) {
       $this->clickAt("//*[@id='$fieldName']/../div/ul/li");
       $this->keyDown("//*[@id='$fieldName']/../div/ul/li//input", " ");
index 7685a3b64c194c21bafecac3c49ad27033a0b938..b8493d34723665328daf17e0c508e85cdbb01718 100644 (file)
@@ -56,74 +56,60 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     $this->createDetailContact($firstName);
 
     // go to group tab and add to new group
-    $this->click("css=li#tab_group a");
-    $this->waitForElementPresent("_qf_GroupContact_next");
+    $this->clickAjaxLink("css=li#tab_group a", "_qf_GroupContact_next");
     $this->select("group_id", "$groupName");
-    $this->click("_qf_GroupContact_next");
+    $this->clickAjaxLink("_qf_GroupContact_next", NULL);
+    $this->waitForText('crm-notification-container', "Contact has been added to '$groupName'");
 
     // go to tag tab and add to new tag
-    $this->click("css=li#tab_tag a");
-    $this->waitForElementPresent("css=div#tagtree");
+    $this->clickAjaxLink("css=li#tab_tag a", "css=div#tagtree");
     $this->click("xpath=//ul/li/span/label[text()=\"$tagName\"]");
     $this->waitForStatusMsg();
 
-    // go to event tab and register for event ( auto add activity and contribution )
-    $this->click("css=li#tab_participant a");
-    $this->waitForElementPresent("link=Add Event Registration");
-    $this->click("link=Add Event Registration");
+    // register for event ( auto add activity and contribution )
+    $this->clickAjaxLink("link=Register for Event");
     $this->waitForText('s2id_event_id', "- select event -");
-    // fall fundraiser dinner event label is variable
     $this->select2("event_id", "Fall Fundraiser Dinner");
     $this->waitForElementPresent("receipt_text");
     $this->multiselect2("role_id", array('Volunteer'));
-    $this->click("CIVICRM_QFID_17_4");
+    // Select $100 fee
+    $this->click("css=input[data-amount=100]");
     $this->check("record_contribution");
     $this->waitForElementPresent("contribution_status_id");
     $this->select("payment_instrument_id", "Check");
     $this->type("check_number", "chqNo$firstName");
     $this->type("trxn_id", "trid$firstName");
-    $this->click("_qf_Participant_upload-bottom");
-    $this->waitForElementPresent("link=Add Event Registration");
+    $this->clickAjaxLink("_qf_Participant_upload-bottom", "link=Add Event Registration");
     $this->waitForText('crm-notification-container', "Event registration for $firstName adv$firstName has been added");
 
-    // go to pledge tab and add pledge
-    $this->click("css=li#tab_pledge a");
-    $this->waitForElementPresent("link=Add Pledge");
-    $this->click("link=Add Pledge");
+    // Add pledge
+    $this->clickAjaxLink("link=Add Pledge");
     $this->waitForElementPresent("contribution_page_id");
     $this->type("amount", "200");
     $this->type("installments", "5");
     $this->type("frequency_interval", "1");
     $this->select("frequency_unit", "month(s)");
-    $this->click("_qf_Pledge_upload-bottom");
-    $this->waitForElementPresent("link=Add Pledge");
-
+    $this->clickAjaxLink("_qf_Pledge_upload-bottom", "link=Add Pledge");
     $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created.");
 
-    // go to Membership tab and add membership
-    $this->click("css=li#tab_member a");
-    $this->waitForElementPresent("link=Add Membership");
-    $this->clickLink("link=Add Membership", "_qf_Membership_cancel-bottom", FALSE);
+    // Add membership
+    $this->clickAjaxLink("link=Add Membership", "_qf_Membership_cancel-bottom");
     //let the organisation be default (Default Organization)
     $this->select("membership_type_id[0]", "value=1");
     $this->click("membership_type_id[1]");
     $this->select("membership_type_id[1]", "Student");
     $this->type("source", "membership source$firstName");
-    $this->clickLink("_qf_Membership_upload-bottom", "link=Add Membership", FALSE);
-
+    $this->clickAjaxLink("_qf_Membership_upload-bottom");
     $this->waitForText('crm-notification-container', "Student membership for $firstName adv$firstName has been added");
 
-    // go to relationship tab and add relationship
-    $this->click("css=li#tab_rel a");
-    $this->waitForElementPresent("link=Add Relationship");
-    $this->click("link=Add Relationship");
-    $this->waitForElementPresent("_qf_Relationship_cancel");
+    // Add relationship
+    $this->clickAjaxLink("link=Add Relationship", "_qf_Relationship_cancel");
     $this->select2("relationship_type_id", "Employee of");
     $this->waitForElementPresent("xpath=//input[@id='related_contact_id'][@placeholder='- select organization -']");
     $this->select2("related_contact_id", "Default", TRUE);
     $this->webtestFillDate("start_date", "-1 day");
     $this->webtestFillDate("end_date", "+1 day");
-    $this->click('_qf_Relationship_upload-bottom');
+    $this->clickAjaxLink('_qf_Relationship_upload-bottom', NULL);
     $this->waitForText('crm-notification-container', "Relationship created.");
 
     //-------------- advance search --------------
@@ -187,11 +173,9 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
   function testActivitySearchByTypeTest() {
     $this->webtestLogin();
     $this->openCiviPage('contact/search/advanced', 'reset=1');
-    $this->click("activity");
-    $this->waitForElementPresent('activity_subject');
+    $this->clickAjaxLink("activity", 'activity_subject');
     $this->check("xpath=//div[@id='Activity']//div/label[text()='Tell a Friend']/../input");
-    $this->click("_qf_Advanced_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Advanced_refresh");
     $count = explode(" ", trim($this->getText("xpath=//div[@id='search-status']/table/tbody/tr/td")));
     $count = $count[0];
     $this->assertTrue(is_numeric($count), "The total count of search results not found");
@@ -240,42 +224,23 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     $this->click("xpath=//form[@id='Advanced']//div[2]/div/div[1]");
   }
 
-  // function to fill auto complete
-  /**
-   * @param $text
-   * @param $elementId
-   */
-  function fillAutoComplete($text, $elementId) {
-    $this->click("$elementId");
-    $this->type("$elementId", "$text");
-    $this->typeKeys("$elementId", "$text");
-    $this->waitForElementPresent("css=div.ac_results li");
-    $this->click("css=div.ac_results li");
-    $this->assertContains($text, $this->getValue("$elementId"),
-      "autocomplete expected $text but didn’t find it in " . $this->getValue("$elementId")
-    );
-  }
-
   /*
    * Check for CRM-14952
    */
   function testStateSorting() {
     $this->webtestLogin();
-    $this->openCiviPage('contact/search/advanced', 'reset=1');
-    $this->waitForElementPresent('group');
+    $this->openCiviPage('contact/search/advanced', 'reset=1', 'group');
     $this->select2("group", "Newsletter", TRUE);
     $this->select2("group", "Advisory", TRUE);
-    $this->click("location");
-    $this->waitForElementPresent('country');
+    $this->clickAjaxLink("location", 'country');
     $this->select2("country", "United States", False);
-    $this->click("_qf_Advanced_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Advanced_refresh");
+
     $stateBeforeSort = $this->getText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
     $this->click("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
     $this->waitForElementPresent("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
     $this->assertElementNotContainsText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]", $stateBeforeSort);
-    $this->click("xpath=//form[@id='Advanced']//div//div[contains(text(),'Edit Search Criteria')]/../div");
-    $this->waitForElementPresent('group');
+    $this->clickAjaxLink("xpath=//form[@id='Advanced']//div//div[contains(text(),'Edit Search Criteria')]/../div", 'group');
     $this->select2("group", "Summer", TRUE);
     $this->waitForElementPresent('state_province');
     $this->select2("state_province", "Ohio", TRUE);
@@ -286,8 +251,8 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     $this->select2("state_province", "Georgia", TRUE);
     $this->select2("state_province", "New Jersey", TRUE);
     $this->select2("state_province", "Texas", TRUE);
-    $this->click("_qf_Advanced_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Advanced_refresh");
+
     $stateBeforeSort = $this->getText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
     $this->click("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
     $this->waitForElementPresent("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
@@ -339,7 +304,7 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     $this->select("country", "United States");
     // select state-province
     $this->waitForElementPresent('state_province');
-    $this->select("state_province", "Alaska");
+    $this->select2("state_province", "Alaska", TRUE);
   }
 
   // function to fill activity search block in advance search
@@ -545,8 +510,7 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     $this->webtestFillDate("deceased_date", "now");
 
     // save contact
-    $this->click("_qf_Contact_upload_view");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Contact_upload_view", 'css=.crm-summary-display_name');
     $this->assertElementContainsText('css=.crm-summary-display_name', "$firstName adv$firstName");
   }
 }
index b5c93cd7f595bafa97337815f565988ce5df75f9..d2a09355ec17a9136642b145aea47c3a8b5282fa 100644 (file)
@@ -776,7 +776,7 @@ class WebTest_Event_AddEventTest extends CiviSeleniumTestCase {
 
     //CRM-12618 check edit screen of additional participant and ensuring record_contribution not present
     foreach ($addtlPart as $value) {
-      $this->clickPopupLink("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
+      $this->clickAjaxLink("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
        '{$value['last_name']}, {$value['first_name']}')]/../../td[11]/span/a[2][contains(text(), 'Edit')]",
         '_qf_Participant_upload-bottom');
       $this->assertTrue(