From 5c88df60449bb1eb7dfdaa4eff6aa12f07c03487 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 19 Sep 2014 17:10:08 -0400 Subject: [PATCH] Webtest cleanup --- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 50 +++++++++---------- .../WebTest/Contact/AdvancedSearchTest.php | 2 +- .../WebTest/Contact/ContactTagTest.php | 2 +- tests/phpunit/WebTest/Contact/SearchTest.php | 2 +- .../Contribute/UpdateContributionTest.php | 2 +- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 65dd1b8f2d..1b4d1bfdbf 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -407,12 +407,11 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { * @return mixed either a string with the (either generated or provided) email or null (if no email) */ function webtestAddContact($fname = 'Anthony', $lname = 'Anderson', $email = NULL, $contactSubtype = NULL) { - $url = $this->sboxPath . 'civicrm/contact/add?reset=1&ct=Individual'; + $args = 'reset=1&ct=Individual'; if ($contactSubtype) { - $url = $url . "&cst={$contactSubtype}"; + $args .= "&cst={$contactSubtype}"; } - $this->open($url); - $this->waitForElementPresent('_qf_Contact_upload_view-bottom'); + $this->openCiviPage('contact/add', $args, '_qf_Contact_upload_view-bottom'); $this->type('first_name', $fname); $this->type('last_name', $lname); if ($email === TRUE) { @@ -421,9 +420,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { if ($email) { $this->type('email_1_email', $email); } - $this->waitForElementPresent('_qf_Contact_upload_view-bottom'); - $this->click('_qf_Contact_upload_view-bottom'); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink('_qf_Contact_upload_view-bottom'); return $email; } @@ -434,7 +431,6 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { * @return null|string */ function webtestAddHousehold($householdName = "Smith's Home", $email = NULL) { - $this->openCiviPage("contact/add", "reset=1&ct=Household"); $this->click('household_name'); $this->type('household_name', $householdName); @@ -446,8 +442,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->type('email_1_email', $email); } - $this->click('_qf_Contact_upload_view'); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink('_qf_Contact_upload_view'); return $email; } @@ -459,12 +454,11 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { * @return null|string */ function webtestAddOrganization($organizationName = "Organization XYZ", $email = NULL, $contactSubtype = NULL) { - - $url = $this->sboxPath . 'civicrm/contact/add?reset=1&ct=Organization'; + $args = 'reset=1&ct=Organization'; if ($contactSubtype) { - $url = $url . "&cst={$contactSubtype}"; + $args .= "&cst={$contactSubtype}"; } - $this->open($url); + $this->openCiviPage('contact/add', $args, '_qf_Contact_upload_view-bottom'); $this->click('organization_name'); $this->type('organization_name', $organizationName); @@ -474,8 +468,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { if ($email) { $this->type('email_1_email', $email); } - $this->click('_qf_Contact_upload_view'); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink('_qf_Contact_upload_view'); return $email; } @@ -798,7 +791,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $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() { $this->waitForElementPresent('credit_card_type'); $this->select('credit_card_type', 'label=Visa'); @@ -1926,7 +1919,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { else { $text = "The financial type \"{$financialType['name']}\" has been updated."; } - $this->assertSuccessMsg($text); + $this->checkCRMAlert($text); } /** @@ -2193,20 +2186,23 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } /** - * Wait for unobtrusive status message as set by CRM.status + * Check for unobtrusive status message as set by CRM.status */ - function waitForStatusMsg() { + function checkCRMStatus($text=NULL) { $this->waitForElementPresent("css=.crm-status-box-outer.status-success"); + if ($text) { + $this->assertElementContainsText("css=.crm-status-box-outer.status-success", $text); + } } - + /** - * Wait for unobtrusive status message as set by CRM.status + * Check for obtrusive status message as set by CRM.alert */ - function assertSuccessMsg($text) { - $this->waitForElementPresent("css=div.success"); - $this->assertElementContainsText("css=div.success", $text); + function checkCRMAlert($text, $type='success') { + $this->waitForElementPresent("css=div.ui-notify-message.$type"); + $this->waitForText("css=div.ui-notify-message.$type", $text); } - + /** * function to enable or disable Pop-ups via Display Preferences */ @@ -2217,7 +2213,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->click('ajaxPopupsEnabled'); } if ($enabled) { - $this->assertChecked('ajaxPopupsEnabled'); + $this->assertChecked('ajaxPopupsEnabled'); } else { $this->assertNotChecked('ajaxPopupsEnabled'); diff --git a/tests/phpunit/WebTest/Contact/AdvancedSearchTest.php b/tests/phpunit/WebTest/Contact/AdvancedSearchTest.php index b8493d3472..eaa7ed4463 100644 --- a/tests/phpunit/WebTest/Contact/AdvancedSearchTest.php +++ b/tests/phpunit/WebTest/Contact/AdvancedSearchTest.php @@ -64,7 +64,7 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase { // go to tag tab and add to new tag $this->clickAjaxLink("css=li#tab_tag a", "css=div#tagtree"); $this->click("xpath=//ul/li/span/label[text()=\"$tagName\"]"); - $this->waitForStatusMsg(); + $this->checkCRMStatus(); // register for event ( auto add activity and contribution ) $this->clickAjaxLink("link=Register for Event"); diff --git a/tests/phpunit/WebTest/Contact/ContactTagTest.php b/tests/phpunit/WebTest/Contact/ContactTagTest.php index 41ee7ad46c..5c2d623f8c 100644 --- a/tests/phpunit/WebTest/Contact/ContactTagTest.php +++ b/tests/phpunit/WebTest/Contact/ContactTagTest.php @@ -73,7 +73,7 @@ class WebTest_Contact_ContactTagTest extends CiviSeleniumTestCase { // check tag we have created $this->click("xpath=//ul/li/span/label[text()=\"$tagName\"]"); - $this->waitForStatusMsg(); + $this->checkCRMStatus(); } function testTagSetContact() { diff --git a/tests/phpunit/WebTest/Contact/SearchTest.php b/tests/phpunit/WebTest/Contact/SearchTest.php index 4972237332..1f10ce2524 100644 --- a/tests/phpunit/WebTest/Contact/SearchTest.php +++ b/tests/phpunit/WebTest/Contact/SearchTest.php @@ -126,7 +126,7 @@ class WebTest_Contact_SearchTest extends CiviSeleniumTestCase { // select tag $this->click("xpath=//ul/li/span/label[text()=\"$tagName\"]"); - $this->waitForStatusMsg(); + $this->checkCRMStatus(); // visit contact search page $this->openCiviPage("contact/search", "reset=1"); diff --git a/tests/phpunit/WebTest/Contribute/UpdateContributionTest.php b/tests/phpunit/WebTest/Contribute/UpdateContributionTest.php index fabf2eb9be..2b659d0e63 100755 --- a/tests/phpunit/WebTest/Contribute/UpdateContributionTest.php +++ b/tests/phpunit/WebTest/Contribute/UpdateContributionTest.php @@ -184,7 +184,7 @@ class WebTest_Contribute_UpdateContributionTest extends CiviSeleniumTestCase { $this->select('product_name_0', "label=$premiumName2 ( $sku2 )"); // Clicking save. $this->clickLink("_qf_Contribution_upload", "xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[7][text()='$premiumName2']", FALSE); - $this->assertSuccessMsg("The contribution record has been saved."); + $this->checkCRMAlert("The contribution record has been saved."); //Assertions $actualAmount = $this->_getPremiumActualCost($contId, $to, $from, $cost2, "'civicrm_contribution'"); -- 2.25.1