From beea38fcfc0a0863967116dd473a0acb1b284912 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 22 Sep 2014 22:17:33 -0400 Subject: [PATCH] Webtest cleanup and fixes --- tests/phpunit/WebTest/Contact/SearchTest.php | 3 +- .../Contact/TaskActionAddToGroupTest.php | 3 +- tests/phpunit/WebTest/Event/PCPAddTest.php | 3 +- tests/phpunit/WebTest/Export/ContactTest.php | 64 ++++--------------- .../Export/ExportCiviSeleniumTestCase.php | 20 +++--- tests/phpunit/WebTest/Import/GroupTest.php | 6 +- .../Import/ImportCiviSeleniumTestCase.php | 35 +++------- 7 files changed, 38 insertions(+), 96 deletions(-) diff --git a/tests/phpunit/WebTest/Contact/SearchTest.php b/tests/phpunit/WebTest/Contact/SearchTest.php index 1f10ce2524..23009ca26a 100644 --- a/tests/phpunit/WebTest/Contact/SearchTest.php +++ b/tests/phpunit/WebTest/Contact/SearchTest.php @@ -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); diff --git a/tests/phpunit/WebTest/Contact/TaskActionAddToGroupTest.php b/tests/phpunit/WebTest/Contact/TaskActionAddToGroupTest.php index 337937759d..91de5c92e2 100644 --- a/tests/phpunit/WebTest/Contact/TaskActionAddToGroupTest.php +++ b/tests/phpunit/WebTest/Contact/TaskActionAddToGroupTest.php @@ -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"); diff --git a/tests/phpunit/WebTest/Event/PCPAddTest.php b/tests/phpunit/WebTest/Event/PCPAddTest.php index 061017417a..768ee32737 100644 --- a/tests/phpunit/WebTest/Event/PCPAddTest.php +++ b/tests/phpunit/WebTest/Event/PCPAddTest.php @@ -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()); diff --git a/tests/phpunit/WebTest/Export/ContactTest.php b/tests/phpunit/WebTest/Export/ContactTest.php index b741ca7c9e..a385ee5cc8 100644 --- a/tests/phpunit/WebTest/Export/ContactTest.php +++ b/tests/phpunit/WebTest/Export/ContactTest.php @@ -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 diff --git a/tests/phpunit/WebTest/Export/ExportCiviSeleniumTestCase.php b/tests/phpunit/WebTest/Export/ExportCiviSeleniumTestCase.php index e596c60eca..45519dc919 100644 --- a/tests/phpunit/WebTest/Export/ExportCiviSeleniumTestCase.php +++ b/tests/phpunit/WebTest/Export/ExportCiviSeleniumTestCase.php @@ -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."); } /** diff --git a/tests/phpunit/WebTest/Import/GroupTest.php b/tests/phpunit/WebTest/Import/GroupTest.php index e9ce368e29..65e27e8f43 100644 --- a/tests/phpunit/WebTest/Import/GroupTest.php +++ b/tests/phpunit/WebTest/Import/GroupTest.php @@ -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"); diff --git a/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php b/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php index de90475c7a..7fb9f49ea7 100644 --- a/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php +++ b/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php @@ -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]; -- 2.25.1