From e739afc31bb5fae16860fea7ad2a4f6af85ec16d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 19 Sep 2014 16:09:09 -0400 Subject: [PATCH] Race-condition fixes for webtests --- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 22 ++++-- .../WebTest/Event/ParticipantSearchTest.php | 4 +- .../Generic/GeneralClickAroundTest.php | 68 ++++++++----------- 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index ff5bcd174e..65dd1b8f2d 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -251,6 +251,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { /** * Force a link to open full-page, even if it would normally open in a popup + * @note: works with links only, not buttons * @param string $element * @param string $waitFor */ @@ -264,13 +265,16 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } /** - * Wait for ajax snippets to finish loading + * Wait for all 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 - // TODO: When test suite is more stable, try removing sleep() and see if it breaks anything - sleep(1); $this->waitForElementNotPresent('css=.blockOverlay'); + // Some ajax calls happen in pairs (e.g. submit a popup form then refresh the underlying content) + // So we'll wait a sec and recheck to see if any more stuff is loading + sleep(1); + if ($this->isElementPresent('css=.blockOverlay')) { + $this->waitForAjaxContent(); + } } /** @@ -2015,8 +2019,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->select('protocol', "IMAP"); $this->type('server', 'localhost'); $this->type('domain', 'example.com'); - $this->click('_qf_MailSettings_next-top'); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink('_qf_MailSettings_next-top'); } } @@ -2134,6 +2137,9 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $customGroupTitle = preg_replace('/\s/', '_', trim($customGroupTitle)); $return[] = array( "{$customSet['entity']}_{$customSet['subEntity']}" => array('cgtitle' => $customGroupTitle, 'gid' => $gid, 'triggerElement' => $customSet['triggerElement'])); + + // Go home for a sec to give time for caches to clear + $this->openCiviPage(''); } return $return; } @@ -2166,6 +2172,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->waitForElementPresent("//*[@class='select2-result-label']"); $this->clickAt("//*[contains(@class,'select2-result-selectable')]/div[contains(@class, 'select2-result-label')]"); } + // Wait a sec for select2 to update the original element + sleep(1); } /** @@ -2180,6 +2188,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->clickAt("xpath=//ul[@class='select2-results']//li/div[text()='$value']"); $this->assertElementContainsText("xpath=//*[@id='$fieldid']/preceding-sibling::div[1]/", $value); } + // Wait a sec for select2 to update the original element + sleep(1); } /** diff --git a/tests/phpunit/WebTest/Event/ParticipantSearchTest.php b/tests/phpunit/WebTest/Event/ParticipantSearchTest.php index 6ad68116ec..3b5d1312dc 100644 --- a/tests/phpunit/WebTest/Event/ParticipantSearchTest.php +++ b/tests/phpunit/WebTest/Event/ParticipantSearchTest.php @@ -178,7 +178,7 @@ class WebTest_Event_ParticipantSearchTest extends CiviSeleniumTestCase { // visit event search page $this->openCiviPage("event/search", "reset=1"); - $this->select("xpath=//div[@id='Food_Preference']/div[2]/table/tbody/tr/td[2]//select", 'Chicken Combo'); + $this->select("css=select[data-crm-custom='Food_Preference:Soup_Selection']", 'Chicken Combo'); $this->clickLink("_qf_Search_refresh"); @@ -189,7 +189,7 @@ class WebTest_Event_ParticipantSearchTest extends CiviSeleniumTestCase { $this->_checkStrings($stringsToCheck); - $this->select("xpath=//div[@id='Food_Preference']/div[2]/table/tbody/tr/td[2]//select", 'Salmon Stew'); + $this->select("css=select[data-crm-custom='Food_Preference:Soup_Selection']", 'Salmon Stew'); $this->clickLink("_qf_Search_refresh"); $stringsToCheck = array("Soup Selection = Salmon Stew"); diff --git a/tests/phpunit/WebTest/Generic/GeneralClickAroundTest.php b/tests/phpunit/WebTest/Generic/GeneralClickAroundTest.php index 5f8c38181e..df7dfd20ea 100644 --- a/tests/phpunit/WebTest/Generic/GeneralClickAroundTest.php +++ b/tests/phpunit/WebTest/Generic/GeneralClickAroundTest.php @@ -37,8 +37,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { function login() { $this->webtestLogin(); - $this->open($this->sboxPath . "civicrm"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->openCiviPage(''); } function testSearchMenu() { @@ -93,8 +92,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Contacts → Manage Groups $this->click("//ul[@id='civicrm-menu']/li[4]"); - $this->click("xpath=//div[@id='root-menu-div']//div/ul//li/div/a[text()='Manage Groups']"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("xpath=//div[@id='root-menu-div']//div/ul//li/div/a[text()='Manage Groups']"); $this->assertTextPresent("Find Groups"); $this->assertElementPresent("title"); @@ -105,13 +103,14 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { } function testContributionDashboard() { - $this->login(); + $this->webtestLogin(); // Enable CiviContribute module if necessary $this->enableComponents("CiviContribute"); // Contributions → Dashboard $this->click("css=ul#civicrm-menu li.crm-Contributions"); - $this->click("css=ul#civicrm-menu li.crm-Contributions li.crm-Dashboard a"); + $this->clickLink("css=ul#civicrm-menu li.crm-Contributions li.crm-Dashboard a"); + $this->waitForElementPresent("xpath=//*[@id='chart_view']/a"); $this->waitForElementPresent("xpath=//*[@id='ContributionCharts']/div[4]/div[3]"); $this->assertTextPresent("Contribution Summary"); @@ -119,15 +118,14 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { } function testEventDashboard() { - $this->login(); + $this->webtestLogin(); // Enable CiviEvent module if necessary $this->enableComponents("CiviEvent"); // Events → Dashboard $this->click("css=ul#civicrm-menu li.crm-Events"); - $this->click("css=ul#civicrm-menu li.crm-Events li.crm-Dashboard a"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("css=ul#civicrm-menu li.crm-Events li.crm-Dashboard a"); $this->assertTextPresent("Event Summary"); $this->assertTextPresent("Counted:"); @@ -144,7 +142,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { } function testMembershipsDashboard() { - $this->login(); + $this->webtestLogin(); // Enable CiviMember module if necessary $this->enableComponents("CiviMember"); @@ -161,7 +159,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { } function testFindContributions() { - $this->login(); + $this->webtestLogin(); // Enable CiviContribute module if necessary $this->enableComponents("CiviContribute"); @@ -169,8 +167,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Search → Find Contributions // Use class names for menu items since li array can change based on which components are enabled $this->click("css=ul#civicrm-menu li.crm-Search"); - $this->click("css=ul#civicrm-menu li.crm-Find_Contributions a"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("css=ul#civicrm-menu li.crm-Find_Contributions a"); $this->assertTextPresent("Edit Search Criteria"); $this->assertElementPresent("sort_name"); @@ -187,7 +184,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { } function testNewMailing() { - $this->login(); + $this->webtestLogin(); // Enable CiviMail module if necessary $this->enableComponents("CiviMail"); @@ -198,8 +195,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // New Mailing Form // Use class names for menu items since li array can change based on which components are enabled $this->click("css=ul#civicrm-menu li.crm-Mailings"); - $this->click("css=ul#civicrm-menu li.crm-New_Mailing a"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("css=ul#civicrm-menu li.crm-New_Mailing a"); $this->assertTextPresent("New Mailing"); $this->assertElementPresent("name"); @@ -212,16 +208,15 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Constituent Report Summary $this->click("css=ul#civicrm-menu li.crm-Reports"); - $this->click("css=ul#civicrm-menu li.crm-Contact_Reports a"); - $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->click("xpath=//div[@id='Contact']/table/tbody/tr/td/a"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("css=ul#civicrm-menu li.crm-Contact_Reports a"); + + $this->clickLink("xpath=//div[@id='Contact']/table/tbody/tr/td/a"); $this->assertTextPresent("Constituent Summary"); - $this->click("//form[@id='Summary']/div[2]/div/div/div/div"); - $this->assertTextPresent("Display Columns"); + $this->click("//div[contains(text(), 'Report Criteria')]"); + $this->waitForVisible("//h3[contains(text(), 'Display Columns')]"); $this->click("//form[@id='Summary']/div[2]//div[@id='id_default']/div/div/div"); - $this->assertTextPresent("Most Important Issue"); + $this->waitForVisible("//label[contains(text(), 'Most Important Issue')]"); $this->assertTextPresent("Set Filters"); $this->assertTextPresent("Contact Name"); $this->assertTextPresent("Contact Source"); @@ -229,8 +224,8 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { $this->assertTextPresent("State/Province"); $this->assertTextPresent("Group"); $this->assertTextPresent("Tag"); - $this->click("_qf_Summary_submit"); - $this->waitForElementPresent("_qf_Summary_submit_print"); + $this->clickLink("_qf_Summary_submit"); + $this->assertTextPresent("Row(s) Listed"); $this->assertTextPresent("Total Row(s)"); } @@ -240,8 +235,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Use class names for menu items since li array can change based on which components are enabled $this->click("css=ul#civicrm-menu li.crm-Administer"); - $this->click("xpath=//div[@id='root-menu-div']//a[text()='Custom Fields']"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("xpath=//div[@id='root-menu-div']//a[text()='Custom Fields']"); $this->assertTextPresent("Custom Data"); $this->assertTextPresent("Constituent Information"); @@ -249,8 +243,8 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { $this->assertTextPresent("Food Preference"); // Verify create form - $this->click("//span[contains(text(), 'Add Set of Custom Fields')]"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("//span[contains(text(), 'Add Set of Custom Fields')]"); + $this->assertElementPresent("title"); $this->assertElementPresent("extends[0]"); $this->assertElementPresent("weight"); @@ -264,9 +258,8 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Use class names for menu items since li array can change based on which components are enabled $this->click("css=ul#civicrm-menu li.crm-Administer"); $this->click("css=ul#civicrm-menu li.crm-Customize_Data_and_Screens"); - $this->click("xpath=//div[@id='root-menu-div']//a[text()='Profiles']"); + $this->clickLink("xpath=//div[@id='root-menu-div']//a[text()='Profiles']"); - $this->waitForPageToLoad($this->getTimeoutMsec()); $this->assertTextPresent("CiviCRM Profile"); // Verify Reserved Profiles @@ -307,9 +300,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Use class names for menu items since li array can change based on which components are enabled $this->click("css=ul#civicrm-menu li.crm-Administer"); $this->click("css=ul#civicrm-menu li.crm-Customize_Data_and_Screens"); - $this->click("xpath=//div[@id='root-menu-div']//a[text()='Tags (Categories)']"); - - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("xpath=//div[@id='root-menu-div']//a[text()='Tags (Categories)']"); // Verify tags $this->assertTextPresent("Non-profit"); @@ -325,9 +316,8 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Use class names for menu items since li array can change based on which components are enabled $this->click("css=ul#civicrm-menu li.crm-Administer"); $this->click("css=ul#civicrm-menu li.crm-Customize_Data_and_Screens"); - $this->click("xpath=//div[@id='root-menu-div']//a[text()='Activity Types']"); + $this->clickLink("xpath=//div[@id='root-menu-div']//a[text()='Activity Types']"); - $this->waitForPageToLoad($this->getTimeoutMsec()); // Verify activity types $this->assertTextPresent("Meeting"); @@ -343,9 +333,8 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Use class names for menu items since li array can change based on which components are enabled $this->click("css=ul#civicrm-menu li.crm-Administer"); $this->click("css=ul#civicrm-menu li.crm-Customize_Data_and_Screens"); - $this->click("xpath=//div[@id='root-menu-div']//a[text()='Relationship Types']"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("xpath=//div[@id='root-menu-div']//a[text()='Relationship Types']"); // Verify relationship types $this->assertTextPresent("Child of"); @@ -362,8 +351,7 @@ class WebTest_Generic_GeneralClickAroundTest extends CiviSeleniumTestCase { // Use class names for menu items since li array can change based on which components are enabled $this->click("css=ul#civicrm-menu li.crm-Administer"); $this->click("css=ul#civicrm-menu li.crm-Communications"); - $this->click("xpath=//div[@id='root-menu-div']//a[text()='Message Templates']"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink("xpath=//div[@id='root-menu-div']//a[text()='Message Templates']"); // Verify message templates $this->click("//a[contains(text(),'System Workflow Messages')]"); -- 2.25.1