From: Coleman Watts Date: Wed, 6 Mar 2013 19:29:14 +0000 (-0800) Subject: Fix 3 webtests, and cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0bd37c069745f246ec299e7412b597722112fe40;p=civicrm-core.git Fix 3 webtests, and cleanup --- diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 533717f6b5..979f572da6 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -115,7 +115,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { * opening all civi pages, and using the $args param is also strongly encouraged * This will make it much easier to run webtests in other CMSs in the future */ - function openCiviPage($url, $args = NULL, $waitFor = NULL) { + function openCiviPage($url, $args = NULL, $waitFor = 'civicrm-footer') { // Construct full url with args // This could be extended in future to work with other CMS style urls if ($args) { @@ -223,6 +223,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $added = FALSE; foreach ((array) $components as $comp) { if (!in_array($comp, $enabledComponents)) { + $this->addSelection("enableComponents-f", "label=$comp"); $this->click("//option[@value='$comp']"); $this->click("add"); $added = TRUE; @@ -1645,7 +1646,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->webtestLogin(TRUE); $this->changeAdminLinks(); $this->waitForElementPresent('edit-submit'); - foreach ($permission as $key => $value) { + foreach ((array) $permission as $key => $value) { $this->check($value); } $this->click('edit-submit'); @@ -1654,7 +1655,6 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->open($this->sboxPath . "user/logout"); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->webtestLogin(); - $this->waitForPageToLoad($this->getTimeoutMsec()); } function addProfile($profileTitle, $profileFields) { diff --git a/tests/phpunit/WebTest/Campaign/SurveyUsageScenarioTest.php b/tests/phpunit/WebTest/Campaign/SurveyUsageScenarioTest.php index dbfc5fd4c7..d2b229a4bc 100644 --- a/tests/phpunit/WebTest/Campaign/SurveyUsageScenarioTest.php +++ b/tests/phpunit/WebTest/Campaign/SurveyUsageScenarioTest.php @@ -66,11 +66,11 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->click("_qf_GroupContact_next"); $this->waitForPageToLoad($this->getTimeoutMsec()); + // Enable CiviCampaign module if necessary $this->enableComponents(array('CiviCampaign')); // add the required Drupal permission - $permissions = array('edit-2-administer-civicampaign'); - $this->changePermissions($permissions); + $this->changePermissions(array('edit-2-administer-civicampaign')); // Go directly to the URL of the screen that you will be testing $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom"); @@ -99,7 +99,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->click("_qf_Campaign_upload-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); - //$this->assertElementContainsText("crm-notification-container", "$title"); + $this->assertElementContainsText("crm-notification-container", "$title"); // create a custom data set for activities -> survey $this->openCiviPage('admin/custom/group', "action=add&reset=1", "_qf_Group_next-bottom"); @@ -113,7 +113,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { // save the custom group $this->click("_qf_Group_next-bottom"); - $this->waitForPageToLoad(); + $this->waitForPageToLoad($this->getTimeoutMsec()); // add a custom field to the custom group $this->type("label", "Field $title"); @@ -180,7 +180,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->click("_qf_Main_upload-bottom"); $this->waitForElementPresent("_qf_Questions_upload_next-bottom"); - //Select the profile for the survey + // Select the profile for the survey $this->select("//form[@id='Questions']/div[2]/table/tbody/tr[1]/td[2]/div/div/span/select", "label=New Individual"); // select the question created for the survey @@ -272,7 +272,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->waitForElementPresent("_qf_Reserve_done_reserve-bottom"); $this->click("_qf_Reserve_done_reserve-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->assertElementContainsText("crm-notification-container", "3"); + $this->assertElementContainsText("crm-notification-container", "Contact(s) have been reserved"); // Release Respondents $this->openCiviPage("survey/search", "reset=1&op=release", "_qf_Search_refresh"); @@ -315,7 +315,6 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $groupName = $this->WebtestAddGroup(); // Adding contact - // We're using Quick Add block on the main page for this. $firstName1 = substr(sha1(rand()), 0, 7); $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org"); $url1 = explode('cid=', $this->getLocation()); @@ -357,7 +356,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->select('extends[0]', "value=Contact"); $this->click('_qf_Group_next-bottom'); $this->waitForElementPresent('_qf_Field_cancel-bottom'); - $this->assertTrue($this->isTextPresent("Your custom field set '$customGroup' has been added. You can add custom fields now.")); + $this->assertElementContainsText("crm-notification-container", $customGroup); // Add custom fields $field1 = "Checkbox $title"; @@ -385,7 +384,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->click('_qf_Field_next-bottom'); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->assertTrue($this->isTextPresent("Your custom field '$field1' has been saved.")); + $this->assertElementContainsText("crm-notification-container", $field1); // Create a profile for survey $this->openCiviPage("admin/uf/group", "reset=1"); @@ -397,7 +396,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->type('title', $surveyProfile); $this->click('_qf_Group_next-bottom'); $this->waitForElementPresent('_qf_Field_cancel-bottom'); - $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$surveyProfile' has been added. You can add fields to this profile now. ")); + $this->assertElementContainsText("crm-notification-container", $surveyProfile); // Add fields to the profile // Phone ( Primary ) @@ -422,18 +421,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); // Enable CiviCampaign module if necessary - $this->openCiviPage("admin/setting/component", "reset=1"); - - $this->waitForElementPresent('_qf_Component_next-bottom'); - $enabledComponents = $this->getSelectOptions('enableComponents-t'); - if (!in_array("CiviCampaign", $enabledComponents)) { - $this->addSelection('enableComponents-f', "label=CiviCampaign"); - $this->click("//option[@value='CiviCampaign']"); - $this->click('add'); - $this->click('_qf_Component_next-bottom'); - $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->assertTrue($this->isTextPresent('Changes Saved.')); - } + $this->enableComponents(array('CiviCampaign')); // add the required Drupal permission $permissions = array('edit-2-administer-civicampaign'); @@ -495,7 +483,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->select('campaign_survey_id', "label=$surveyTitle"); // need to wait for Groups field to reload dynamically - sleep(3); + $this->waitForElementPresent("//select[@class='campaignGroupsSelect']/option[text()='$groupName']"); // select group $this->click('campaignGroupsSelect1'); @@ -511,7 +499,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); // wait for Access Keys div to appear at bottom of page - since this page may take a while $this->waitForElementPresent('access'); - $this->assertTrue($this->isTextPresent("Reservation has been added for 2 Contact(s).")); + $this->assertElementContainsText("crm-notification-container", "2"); $this->openCiviPage("report/survey/detail", "reset=1", '_qf_SurveyDetails_submit'); @@ -542,7 +530,7 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->select('campaign_survey_id', "label=$surveyTitle"); // need to wait for Groups field to reload dynamically - sleep(3); + $this->waitForElementPresent("//select[@class='campaignGroupsSelect']/option[text()='$groupName']"); // select group $this->click('campaignGroupsSelect1'); @@ -557,8 +545,8 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { $this->waitForElementPresent('_qf_Interview_cancel_interview'); $this->type("field_{$id1}_phone-Primary-1", 9876543210); - $this->click("xpath=//table[@id='voterRecords']/tbody//tr[@id='row_{$id1}']/td[5]/input[2]/../label[text()='$label1']"); - $this->click("xpath=//table[@id='voterRecords']/tbody//tr[@id='row_{$id1}']/td[5]/input[6]/../label[text()='$label2']"); + $this->click("//table[@id='voterRecords']/tbody//tr[@id='row_{$id1}']/td[5]/input[2]/../label[text()='$label1']"); + $this->click("//table[@id='voterRecords']/tbody//tr[@id='row_{$id1}']/td[5]/input[6]/../label[text()='$label2']"); $this->select("field_{$id1}_result", $optionLabel1); $this->click("interview_voter_button_{$id1}"); sleep(3); @@ -591,14 +579,14 @@ class WebTest_Campaign_SurveyUsageScenarioTest extends CiviSeleniumTestCase { // select survey $this->select('campaign_survey_id', "label=$surveyTitle"); // need to wait for Groups field to reload dynamically - sleep(3); + $this->waitForElementPresent("//select[@class='campaignGroupsSelect']/option[text()='$groupName']"); // select group $this->click('campaignGroupsSelect1'); $this->select('campaignGroupsSelect1', "label=$groupName"); $this->waitForElementPresent("xpath=//ul[@id='crmasmList1']/li"); $this->click("xpath=//div[@id='search_form_gotv']/div[2]/table/tbody/tr[6]/td/a[text()='Search']"); - + $this->waitForElementPresent("xpath=//table[@id='gotvVoterRecords']/tbody/tr/td[7]"); $this->check("xpath=//table[@id='gotvVoterRecords']/tbody/tr/td[7]/input"); diff --git a/tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php b/tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php index a1f621bc74..6ab4aef049 100644 --- a/tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php +++ b/tests/phpunit/WebTest/Case/CaseCustomFieldsTest.php @@ -33,23 +33,11 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { } function testAddCase() { - $this->open($this->sboxPath); - - // Log in as admin first to verify permissions for CiviCase $this->webtestLogin(); // Enable CiviCase module if necessary - $this->open($this->sboxPath . "civicrm/admin/setting/component?reset=1"); - $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->waitForElementPresent("_qf_Component_next-bottom"); - $enabledComponents = $this->getSelectOptions("enableComponents-t"); - if (!in_array("CiviCase", $enabledComponents)) { - $this->addSelection("enableComponents-f", "label=CiviCase"); - $this->click("//option[@value='CiviCase']"); - $this->click("add"); - $this->click("_qf_Component_next-bottom"); - $this->waitForPageToLoad($this->getTimeoutMsec()); - } + $this->enableComponents("CiviCase"); + $customGrp1 = "CaseCustom_Data1_" . substr(sha1(rand()), 0, 7); // create custom group1 @@ -68,9 +56,9 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { $customGrpId1 = $elements['queryString']['gid']; $customId = $this->_testGetCustomFieldId($customGrpId1); - $cusId_1 = 'custom_' . $customId[0] . '_-1'; - $cusId_2 = 'custom_' . $customId[1] . '_-1'; - $cusId_3 = 'custom_' . $customId[2] . '_-1'; + $cusId_1 = 'custom_' . $customId[0] . '_-1'; + $cusId_2 = 'custom_' . $customId[1] . '_-1'; + $cusId_3 = 'custom_' . $customId[2] . '_-1'; // let's give full CiviCase permissions. $permission = array('edit-2-access-all-cases-and-activities', 'edit-2-access-my-cases-and-activities', 'edit-2-administer-civicase', 'edit-2-delete-in-civicase'); @@ -86,9 +74,6 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); $this->waitForElementPresent("profilewrap4"); - // Is status message correct? - $this->assertTextPresent("Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!"); - // Go directly to the URL of the screen that you will be testing (New Case-standalone). $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom'); @@ -96,7 +81,6 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { $this->click("_qf_Case_upload-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->waitForElementPresent("css=span.crm-error"); - $this->assertTextPresent("Please select a contact or create new contact", "Expected form rule error for submit without selecting contact did not show up after clicking Save."); // Adding contact with randomized first name (so we can then select that contact when creating case) // We're using pop-up New Contact dialog @@ -114,10 +98,10 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { $caseTypeLabel = "Adult Day Care Referral"; // activity types we expect for this case type - $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation"); - $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client"); + $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation"); + $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client"); $caseStatusLabel = "Ongoing"; - $subject = "Safe daytime setting - senior female"; + $subject = "Safe daytime setting - senior female"; $this->select("medium_id", "value=1"); $location = "Main offices"; $this->type("activity_location", $location); @@ -171,22 +155,19 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { // verify if custom data is present $this->openCiviPage('case', 'reset=1'); - $this->waitForPageToLoad($this->getTimeoutMsec()); $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']"); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->click("xpath=//div[@id='{$customGrp1}']/div[2]"); + $this->click("css=#{$customGrp1} .crm-accordion-header"); + $this->waitForElementPresent("css=#{$customGrp1} a.button"); + $cusId_1 = 'custom_' . $customId[0] . '_1'; + $cusId_2 = 'custom_' . $customId[1] . '_1'; + $cusId_3 = 'custom_' . $customId[2] . '_1'; + $this->click("css=#{$customGrp1} a.button"); sleep(2); - $this->waitForElementPresent("xpath=//div[@id='{$customGrp1}']/div[2]/div/a/span[text()='Edit']"); - $this->click("xpath=//div[@id='{$customGrp1}']/div[2]/div/a/span[text()='Edit']"); - sleep(3); + $this->waitForElementPresent("{$cusId_1}"); $custFname = "Miky" . substr(sha1(rand()), 0, 7); $custMname = "Davy" . substr(sha1(rand()), 0, 7); $custLname = "Kristy" . substr(sha1(rand()), 0, 7); - $cusId_1 = 'custom_' . $customId[0] . '_1'; - $cusId_2 = 'custom_' . $customId[1] . '_1'; - $cusId_3 = 'custom_' . $customId[2] . '_1'; - $this->click("xpath=//div[@id='{$customGrp1}']/div[2]"); - sleep(3); $this->type("{$cusId_1}", $custFname); $this->type("{$cusId_2}", $custMname); $this->type("{$cusId_3}", $custLname); @@ -225,13 +206,12 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { $customId = array(); // Create a custom data to add in profile - $field1 = "Fname" . substr(sha1(rand()), 0, 7); $field2 = "Mname" . substr(sha1(rand()), 0, 7); $field3 = "Lname" . substr(sha1(rand()), 0, 7); // add custom fields for group 1 - $this->openCiviPage('admin/custom/group/field/add', "reset=1&action=add&gid={$customGrpId1}"); + $this->openCiviPage('admin/custom/group/field/add', array('reset' => 1, 'action' => 'add', 'gid' => $customGrpId1)); $this->type("label", $field1); $this->check("is_searchable"); $this->click("_qf_Field_next_new-bottom"); @@ -248,7 +228,7 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); // get id of custom fields - $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGrpId1}"); + $this->openCiviPage("admin/custom/group/field", array('reset' => 1, 'action' => 'browse', 'gid' => $customGrpId1)); $custom1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[1]/td[8]/span/a[text()='Edit Field']/@href")); $custom1 = $custom1[1]; array_push($customId, $custom1); @@ -264,19 +244,19 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { function _testDeleteCustomData($customGrpId1, $customId) { // delete all custom data - $this->openCiviPage('admin/custom/group/field', "action=delete&reset=1&gid={$customGrpId1}&id={$customId[0]}"); + $this->openCiviPage("admin/custom/group/field", array('action' => 'delete', 'reset' => '1', 'gid' => $customGrpId1, 'id' => $customId[0])); $this->click("_qf_DeleteField_next-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->openCiviPage('admin/custom/group/field', "action=delete&reset=1&gid={$customGrpId1}&id={$customId[1]}"); + $this->openCiviPage("admin/custom/group/field", array('action' => 'delete', 'reset' => '1', 'gid' => $customGrpId1, 'id' => $customId[1])); $this->click("_qf_DeleteField_next-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->openCiviPage('admin/custom/group/field', "action=delete&reset=1&gid={$customGrpId1}&id={$customId[2]}"); + $this->openCiviPage("admin/custom/group/field", array('action' => 'delete', 'reset' => '1', 'gid' => $customGrpId1, 'id' => $customId[2])); $this->click("_qf_DeleteField_next-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->openCiviPage('admin/custom/group', "action=delete&reset=1&id={$customGrpId1}"); + $this->openCiviPage("admin/custom/group", "action=delete&reset=1&id=" . $customGrpId1); $this->click("_qf_DeleteGroup_next-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); } @@ -285,7 +265,7 @@ class WebTest_Case_CaseCustomFieldsTest extends CiviSeleniumTestCase { // search casecontact $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); $this->click("CiviCase"); - sleep(2); + $this->waitForElementPresent('case_from_relative'); $cusId_1 = 'custom_' . $customId[0]; $cusId_2 = 'custom_' . $customId[1]; $cusId_3 = 'custom_' . $customId[2]; diff --git a/tests/phpunit/WebTest/Contact/AddCmsUserTest.php b/tests/phpunit/WebTest/Contact/AddCmsUserTest.php index ad5c4f8a50..d396fd0584 100644 --- a/tests/phpunit/WebTest/Contact/AddCmsUserTest.php +++ b/tests/phpunit/WebTest/Contact/AddCmsUserTest.php @@ -69,11 +69,6 @@ class WebTest_Contact_AddCmsUserTest extends CiviSeleniumTestCase { } function testAnonymousAddUser() { - // This is the path where our testing install resides. - // The rest of URL is defined in CiviSeleniumTestCase base class, in - // class attributes. - $this->open($this->sboxPath); - // Make sure Drupal account settings allow visitors to register for account w/o admin approval // login as admin $this->webtestLogin(TRUE); @@ -85,8 +80,7 @@ class WebTest_Contact_AddCmsUserTest extends CiviSeleniumTestCase { $this->click('edit-submit'); $this->waitForPageToLoad($this->getTimeoutMsec()); // logout - $this->open($this->sboxPath . 'civicrm/logout?reset=1'); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->openCiviPage('logout', 'reset=1', NULL); // Go directly to the URL of the screen that will Create User Anonymously. $this->open($this->sboxPath . "user/register"); @@ -97,7 +91,6 @@ class WebTest_Contact_AddCmsUserTest extends CiviSeleniumTestCase { $emailId = substr(sha1(rand()), 0, 7) . '@web.com'; $this->type("edit-mail", $emailId); - //Add profile Details $firstName = 'Ma' . substr(sha1(rand()), 0, 4); $lastName = 'An' . substr(sha1(rand()), 0, 7); @@ -113,12 +106,13 @@ class WebTest_Contact_AddCmsUserTest extends CiviSeleniumTestCase { $this->click("edit-submit"); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->assertTrue($this->isTextPresent("A welcome message with further instructions has been sent to your e-mail address.")); + + // In case the site is set up to login immediately upon registration + $this->open($this->sboxPath . "user/logout"); $this->webtestLogin(); - $this->open($this->sboxPath . "civicrm/contact/search?reset=1"); - $this->waitForElementPresent("_qf_Basic_refresh"); + $this->openCiviPage("contact/search", "reset=1", "_qf_Basic_refresh"); $this->type("sort_name", $emailId); $this->click("_qf_Basic_refresh"); $this->waitForPageToLoad($this->getTimeoutMsec());