From 50d95825245e941c9786471421c1116e0cc3083f Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 18 Sep 2014 00:02:26 -0400 Subject: [PATCH] CRM-15197 - Webtest fixes --- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 31 +++++++++++++++++-- tests/phpunit/WebTest/Event/AddEventTest.php | 22 ++++++------- .../phpunit/WebTest/Event/AddPricesetTest.php | 7 ++--- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 870608c1a9..16934bd915 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -237,8 +237,22 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } /** - * Click on a link and have it open full-page - * @param $element + * Click a popup link and wait for the ajax content to load + * @param string $element + * @param string $waitFor + */ + function clickPopupLink($element, $waitFor) { + $this->click($element); + $this->waitForElementPresent('css=.ui-dialog'); + $this->waitForAjaxContent(); + if ($waitFor) { + $this->waitForElementPresent($waitFor); + } + } + + /** + * Force a link to open full-page, even if it would normally open in a popup + * @param string $element * @param string $waitFor */ function clickLinkSuppressPopup($element, $waitFor = 'civicrm-footer') { @@ -250,6 +264,15 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } } + /** + * Wait for ajax snippets to finish loading + */ + function waitForAjaxContent() { + // Add sleep to prevent condition where we click an ajax button and call this function before the content has even started loading + sleep(1); + $this->waitForElementNotPresent('css=.blockOverlay'); + } + /** * Call the API on the local server * (kind of defeats the point of a webtest - see CRM-11889) @@ -2091,7 +2114,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $fieldLabel = "custom_field_for_{$customSet['entity']}_{$customSet['subEntity']}" . substr(sha1(rand()), 0, 4); $this->type('label', $fieldLabel); - $this->click('_qf_Field_next_new-bottom'); + $this->click('_qf_Field_done-bottom'); $customGroupTitle = preg_replace('/\s/', '_', trim($customGroupTitle)); $return[] = array( @@ -2132,6 +2155,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { * function to select multiple options */ function multiselect2($fieldid, $params) { + // In the case of chainSelect, wait for options to load + $this->waitForElementNotPresent('css=select.loading'); foreach($params as $value) { $this->clickAt("xpath=//*[@id='$fieldid']/../div/ul//li/input"); $this->waitForElementPresent("xpath=//ul[@class='select2-results']"); diff --git a/tests/phpunit/WebTest/Event/AddEventTest.php b/tests/phpunit/WebTest/Event/AddEventTest.php index 5f5ce829f4..b5c93cd7f5 100644 --- a/tests/phpunit/WebTest/Event/AddEventTest.php +++ b/tests/phpunit/WebTest/Event/AddEventTest.php @@ -310,7 +310,9 @@ class WebTest_Event_AddEventTest extends CiviSeleniumTestCase { $this->assertChecked('is_pay_later'); $this->click("CIVICRM_QFID_0_is_monetary"); - $this->clickLink("_qf_Fee_upload-bottom", "_qf_Fee_upload-bottom"); + $this->click("_qf_Fee_upload-bottom"); + $this->waitForText('crm-notification-container', "'Fees' information has been saved."); + $this->waitForAjaxContent(); //check if pay later option is disabled $this->click('CIVICRM_QFID_1_is_monetary'); @@ -357,8 +359,7 @@ class WebTest_Event_AddEventTest extends CiviSeleniumTestCase { $this->type("max_participants", "50"); $this->click("is_map"); $this->click("is_public"); - $this->click("_qf_EventInfo_upload-bottom"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("_qf_EventInfo_upload-bottom"); } /** @@ -373,8 +374,8 @@ class WebTest_Event_AddEventTest extends CiviSeleniumTestCase { // Select event template. Use option value, not label - since labels can be translated and test would fail $this->select("template_id", "value={$templateID}"); - // Wait for event type to be filled in (since page reloads) - $this->waitForElementPresent("event_type_id"); + // Wait for event type to be filled in (since page refreshes) + $this->waitForAjaxContent(); $this->verifySelectedValue("event_type_id", $eventTypeID); // Attendee role s/b selected now. @@ -395,8 +396,7 @@ class WebTest_Event_AddEventTest extends CiviSeleniumTestCase { $this->type("max_participants", "50"); $this->click("is_map"); - $this->click("_qf_EventInfo_upload-bottom"); - + $this->clickLink("_qf_EventInfo_upload-bottom"); } /** @@ -404,7 +404,7 @@ class WebTest_Event_AddEventTest extends CiviSeleniumTestCase { */ function _testAddLocation($streetAddress) { // Wait for Location tab form to load - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->waitForAjaxContent(); $this->waitForElementPresent("_qf_Location_upload-bottom"); // Fill in address fields @@ -766,7 +766,7 @@ class WebTest_Event_AddEventTest extends CiviSeleniumTestCase { $this->_testOnlineRegistration($registerUrl, 2, $anonymous, FALSE, $participantEmails, "Test Processor"); $primaryDisplayName = "{$primaryParticipantInfo['first_name']} {$primaryParticipantInfo['last_name']}"; $this->webtestLogin(); - $this->openCiviPage("event/search?reset=1", "reset=1"); + $this->openCiviPage("event/search", "reset=1"); $this->select2("event_id", $eventTitle, FALSE); $this->clickLink('_qf_Search_refresh'); $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(), @@ -776,9 +776,9 @@ 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->clickLink("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(), + $this->clickPopupLink("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', FALSE); + '_qf_Participant_upload-bottom'); $this->assertTrue( $this->isElementPresent("xpath=//tr[@class='crm-participant-form-block-registered-by']/td[2]/a[contains(text(), '$primaryDisplayName')]"), 'Registered By info is wrong on additional participant edit form'); diff --git a/tests/phpunit/WebTest/Event/AddPricesetTest.php b/tests/phpunit/WebTest/Event/AddPricesetTest.php index 6f680e628e..8aecd6cfc4 100644 --- a/tests/phpunit/WebTest/Event/AddPricesetTest.php +++ b/tests/phpunit/WebTest/Event/AddPricesetTest.php @@ -50,7 +50,7 @@ class WebTest_Event_AddPricesetTest extends CiviSeleniumTestCase { $sid = $this->urlArg('sid'); $this->assertType('numeric', $sid); - $validStrings = array(); + $validateStrings = array(); $fields = array( 'Full Conference' => 'Text', @@ -59,7 +59,6 @@ class WebTest_Event_AddPricesetTest extends CiviSeleniumTestCase { 'Evening Sessions' => 'CheckBox', ); $this->_testAddPriceFields($fields, $validateStrings); - // var_dump($validateStrings); // load the Price Set Preview and check for expected values $this->_testVerifyPriceSet($validateStrings, $sid); @@ -97,7 +96,7 @@ class WebTest_Event_AddPricesetTest extends CiviSeleniumTestCase { * @param bool $dateSpecificFields */ function _testAddPriceFields(&$fields, &$validateStrings, $dateSpecificFields = FALSE) { - $this->waitForElementPresent('_qf_Field_cancel-bottom'); + $this->clickLinkSuppressPopup('newPriceField'); foreach ($fields as $label => $type) { $validateStrings[] = $label; @@ -176,7 +175,7 @@ class WebTest_Event_AddPricesetTest extends CiviSeleniumTestCase { default: break; } - $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE); + $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom'); $this->waitForText('crm-notification-container', "Price Field '".$label."' has been saved."); } } -- 2.25.1