From 38bf8139f68aae9941174ff6fbffd6d20ba5f68d Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Wed, 6 Mar 2013 20:47:35 +0530 Subject: [PATCH] webtest cleanup and code improvement --- .../WebTest/Profile/BatchUpdateTest.php | 41 +++++++++---------- tests/phpunit/WebTest/Profile/DedupeTest.php | 12 ++---- .../Profile/MultiRecordProfileAddTest.php | 33 +++++++-------- .../WebTest/Profile/ProfileAddTest.php | 14 +++---- 4 files changed, 44 insertions(+), 56 deletions(-) diff --git a/tests/phpunit/WebTest/Profile/BatchUpdateTest.php b/tests/phpunit/WebTest/Profile/BatchUpdateTest.php index 396617e921..71b5505dfb 100644 --- a/tests/phpunit/WebTest/Profile/BatchUpdateTest.php +++ b/tests/phpunit/WebTest/Profile/BatchUpdateTest.php @@ -67,11 +67,13 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); $profileTitle = 'Batch Profile test_' . substr(sha1(rand()), 0, 7); - $profileFields = array (array ( - 'type' => 'Individual', - 'name' => 'Last Name', - 'label' => 'Last Name' - )); + $profileFields = array( + array( + 'type' => 'Individual', + 'name' => 'Last Name', + 'label' => 'Last Name' + ) + ); $this->addProfile($profileTitle, $profileFields); $this->openCiviPage('contact/search', 'reset=1', '_qf_Basic_refresh'); $this->type('sort_name', "Smiths_x"); @@ -382,8 +384,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Reserve and interview responsedents - $this->open($this->sboxPath . "civicrm/campaign?reset=1&subPage=survey"); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->openCiviPage('campaign', 'reset=1&subPage=survey'); $this->waitForElementPresent("xpath=//table[@id='surveys']/tbody//tr/td[2]/a[text()='{$surveyTitle}']/../following-sibling::td[@class='crm-campaign-voterLinks']/span/ul/li/a"); $this->click("xpath=//table[@id='surveys']/tbody//tr/td[2]/a[text()='{$surveyTitle}']/../following-sibling::td[@class='crm-campaign-voterLinks']/span/ul/li/a"); $this->waitForPageToLoad($this->getTimeoutMsec()); @@ -523,8 +524,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->assertTrue($assertCheck, 'copy rows for field two failed for inteview (campaign)[radio button]'); //change the editor back to ckeditor - $this->open($this->sboxPath . "civicrm/admin/setting/preferences/display?reset=1"); - $this->waitForElementPresent('_qf_Display_next-bottom'); + $this->openCiviPage('admin/setting/preferences/display', 'reset=1', '_qf_Display_next-bottom'); $this->select('editor_id', 'CKEditor'); $this->click('_qf_Display_next-bottom'); $this->waitForPageToLoad($this->getTimeoutMsec()); @@ -532,9 +532,8 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { function _addProfile($profileTitle, $customDataArr, $profileFor) { // Go directly to the URL of the screen that you will be testing (New Profile). - $this->open($this->sboxPath . "civicrm/admin/uf/group?reset=1"); + $this->openCiviPage('admin/uf/group', 'reset=1'); - $this->waitForPageToLoad($this->getTimeoutMsec()); $this->click('link=Add Profile'); // Add membership custom data field to profile @@ -543,7 +542,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->click('_qf_Group_next-bottom'); $this->waitForElementPresent('_qf_Field_cancel-bottom'); - $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.")); + $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); foreach ($customDataArr as $key => $customDataParams) { $this->select('field_name[0]', "label={$profileFor}"); @@ -554,7 +553,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { // Clicking save and new $this->click('_qf_Field_next_new-bottom'); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '{$customDataParams[1]}' has been saved to '{$profileTitle}'.")); + $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile Field '{$customDataParams[1]}' has been saved to '{$profileTitle}'."); } } @@ -562,7 +561,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $returnArray = array(); $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 4); // Go directly to the URL of the screen that you will be testing (New Custom Group). - $this->open($this->sboxPath . "civicrm/admin/custom/group?reset=1"); + $this->openCiviPage('admin/custom/group', 'reset=1'); //add new custom data $this->click("//a[@id='newCustomDataGroup']/span"); @@ -583,7 +582,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForElementPresent('_qf_Field_cancel-bottom'); //Is custom group created? - $this->assertTrue($this->isTextPresent("Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.")); + $this->assertElementContainsText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); //for checkbox 1 $checkLabel1 = 'Custom Check One Text_' . substr(sha1(rand()), 0, 4); @@ -612,7 +611,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Is custom field created - $this->assertTrue($this->isTextPresent("Your custom field '$checkLabel1' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "Your custom field '$checkLabel1' has been saved."); $returnArray[1] = array($customGroupTitle, $checkLabel1); // create another custom field - Integer Radio @@ -643,7 +642,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Is custom field created - $this->assertTrue($this->isTextPresent("Your custom field '$checkLabel2' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "Your custom field '$checkLabel2' has been saved."); $returnArray[2] = array($customGroupTitle, $checkLabel2); // create another custom field - Integer Radio @@ -672,7 +671,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Is custom field created - $this->assertTrue($this->isTextPresent("Your custom field '$dateFieldLabel' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "Your custom field '$dateFieldLabel' has been saved."); $returnArray[3] = array($customGroupTitle, $dateFieldLabel); // create another custom field - Integer Radio @@ -691,7 +690,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Is custom field created - $this->assertTrue($this->isTextPresent("Your custom field '$richTextField' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "Your custom field '$richTextField' has been saved."); $returnArray[4] = array($customGroupTitle, $richTextField); // create another custom field - Integer Radio @@ -723,7 +722,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Is custom field created - $this->assertTrue($this->isTextPresent("Your custom field '$radioLabel1' has been saved.")); + $this->assertElementContainsText('crm-container', "Your custom field '$radioLabel1' has been saved."); $returnArray[5] = array($customGroupTitle, $radioLabel1); // create another custom field - Integer Radio @@ -754,7 +753,7 @@ class WebTest_Profile_BatchUpdateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Is custom field created - $this->assertTrue($this->isTextPresent("Your custom field '$radioLabel2' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "Your custom field '$radioLabel2' has been saved."); $returnArray[6] = array($customGroupTitle, $radioLabel2); return $returnArray; diff --git a/tests/phpunit/WebTest/Profile/DedupeTest.php b/tests/phpunit/WebTest/Profile/DedupeTest.php index 22dd109361..f7356a16d2 100644 --- a/tests/phpunit/WebTest/Profile/DedupeTest.php +++ b/tests/phpunit/WebTest/Profile/DedupeTest.php @@ -43,7 +43,7 @@ class WebTest_Profile_DedupeTest extends CiviSeleniumTestCase { $this->changePermissions($permission); // Go directly to the URL of the screen that you will beadding New Individual. - $this->open($this->sboxPath . "civicrm/contact/add?reset=1&ct=Individual"); + $this->openCiviPage('contact/add', 'reset=1&ct=Individual'); $firstName = "John" . substr(sha1(rand()), 0, 7); $lastName = "Smith" . substr(sha1(rand()), 0, 7); @@ -61,12 +61,10 @@ class WebTest_Profile_DedupeTest extends CiviSeleniumTestCase { $this->click("_qf_Contact_upload_view"); $this->waitForPageToLoad($this->getTimeoutMsec()); $individualName = $this->getText("xpath=//div[@class='crm-summary-display_name']"); - $this->assertTrue($this->isTextPresent("$individualName has been created.")); + $this->assertElementContainsText('crm-notification-container', "$individualName has been created."); // submit dupe using profile/create as anonymous - $this->open($this->sboxPath . "civicrm/profile/create?gid=4&reset=1"); - $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->waitForElementPresent("_qf_Edit_next"); + $this->openCiviPage('profile/create', 'gid=4&reset=1', '_qf_Edit_next'); $firstName = "John" . substr(sha1(rand()), 0, 7); $lastName = "Smith" . substr(sha1(rand()), 0, 7); @@ -84,6 +82,4 @@ class WebTest_Profile_DedupeTest extends CiviSeleniumTestCase { $this->click("_qf_Edit_next"); $this->waitForTextPresent("A record already exists with the same information."); } -} - - +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php b/tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php index 70cc419f30..2be907f2fa 100644 --- a/tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php +++ b/tests/phpunit/WebTest/Profile/MultiRecordProfileAddTest.php @@ -95,8 +95,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $params = $this->_testCustomAdd($checkSearchable); // Go directly to the URL of the screen that you will be // testing (Add new profile ). - $this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1'); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->openCiviPage('admin/uf/group', 'reset=1'); $this->click('newCiviCRMProfile-top'); $this->waitForElementPresent('_qf_Group_next-bottom'); @@ -140,7 +139,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //check for profile create - $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$profileTitle' has been added. You can add fields to this profile now")); + $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); //Add field to profile $this->waitForElementPresent('field_name[0]'); @@ -221,6 +220,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $recordNew = $this->_addRecords('Create'); $this->waitForPageToLoad($this->getTimeoutMsec()); $elements = $this->parseURL( ); + $gid = $elements['queryString']['gid']; $id = $elements['queryString']['id']; @@ -242,9 +242,9 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $this->click('edit-submit'); $this->waitForPageToLoad($this->getTimeoutMsec()); } - $this->open($this->sboxPath . 'civicrm/profile/edit?reset=1&id='.$id.'&gid='.$gid); + $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid"); if (!$checkMultiRecord) { - $this->assertTrue($this->isTextPresent('No multi-record entries found')); + $this->assertElementContainsText('crm-container', 'No multi-record entries found'); return; } $this->waitForElementPresent("//div[@id='crm-profile-block']/a"); @@ -253,8 +253,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel'])); $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[2]/td[1]", preg_quote($record1['text'])); - $this->open($this->sboxPath . 'civicrm/profile/edit?reset=1&id='.$id.'&gid='.$gid); - $this->waitForElementPresent("//div[@id='crm-profile-block']/a"); + $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", "//div[@id='crm-profile-block']/a"); $this->click("//div[@id='crm-profile-block']/a"); $record2 = $this->_addRecords(); $this->waitForPageToLoad($this->getTimeoutMsec()); @@ -277,15 +276,15 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Delete']"); $this->waitForElementPresent("//html/body/div[5]"); sleep(3); - $this->assertTrue($this->isTextPresent('Are you sure you want to delete this record?')); + $this->assertElementContainsText('profile-dialog', 'Are you sure you want to delete this record?'); $this->click('_qf_Edit_upload_delete'); // Check the view functionality sleep(3); $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='View']"); $this->waitForElementPresent("//html/body/div[5]"); - $this->assertTrue($this->isTextPresent('View '.$params['customGroupTitle'])); - $this->assertTrue($this->isTextPresent($params['textFieldLabel'])); + $this->assertElementContainsText('ui-id-1', 'View '.$params['customGroupTitle']); + $this->assertElementContainsText('crm-container', $params['textFieldLabel']); if ($checkSearchable) { $this->verifyElementNotPresent("//div[@id='profile-dialog']/div/div/div/div[1]/div[2]/a"); return; @@ -296,8 +295,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $this->click("//div[@id='profile-dialog']/div/div/div/div/div[2]/a"); $this->waitForElementPresent("//form[@id='Search']"); $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr[2]/td[2]", preg_quote($recordNew['firstname'])); - $this->open($this->sboxPath . 'civicrm/profile/view?reset=1&id='.$id.'&gid='.$gid); - $this->waitForElementPresent("//div[@id='row-first_name']/div[2]/a"); + $this->openCiviPage('profile/view', "reset=1&id=$id&gid=$gid", "//div[@id='row-first_name']/div[2]/a"); $this->click("//div[@id='row-first_name']/div[2]/a"); $this->waitForElementPresent("//form[@id='Search']"); // Check that Email column is not present in selector results @@ -310,10 +308,9 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { function _testCustomAdd($checkSearchable) { // Go directly to the URL of the screen that you will be testing (Custom data for contacts). - $this->open($this->sboxPath . "civicrm/admin/custom/group?action=add&reset=1"); + $this->openCiviPage('admin/custom/group', 'action=add&reset=1'); // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit // button at the end of this page to show up, to make sure it's fully loaded. - $this->waitForPageToLoad($this->getTimeoutMsec()); //fill custom group title $params['customGroupTitle'] = 'custom_group' . substr(sha1(rand()), 0, 3); @@ -331,7 +328,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Is custom group created? - $this->assertTrue($this->isTextPresent($params['customGroupTitle'])); + $this->assertElementContainsText('crm-container', $params['customGroupTitle']); //add custom field - alphanumeric text $params['textFieldLabel'] = 'test_text_field' . substr(sha1(rand()), 0, 3); $this->click("header"); @@ -373,7 +370,7 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //Is custom field created? - $this->assertTrue($this->isTextPresent($params['selectFieldLabel'])); + $this->assertElementContainsText('crm-container', $params['selectFieldLabel']); return $params; } @@ -389,8 +386,8 @@ class WebTest_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase { $params['email'] = $params['firstname'].$params['lastname'].'@exa.com'; $this->type('email-Primary', $params['email']); } - $this->waitForElementPresent("//div[@id='crm-profile-block']/div/div[3]/div[2]/select"); - $this->select("//div[@id='crm-profile-block']/div/div[3]/div[2]/select",'value=1'); + $this->waitForElementPresent("//div[@id='crm-profile-block']/div//div/div[2]/select"); + $this->select("//div[@id='crm-profile-block']/div//div/div[2]/select",'value=1'); $this->click('_qf_Edit_next'); return $params; } diff --git a/tests/phpunit/WebTest/Profile/ProfileAddTest.php b/tests/phpunit/WebTest/Profile/ProfileAddTest.php index dd539ea8a2..fb770bfd10 100644 --- a/tests/phpunit/WebTest/Profile/ProfileAddTest.php +++ b/tests/phpunit/WebTest/Profile/ProfileAddTest.php @@ -47,9 +47,7 @@ class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase { // Go directly to the URL of the screen that you will be // testing (Add new profile ). - $this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1'); - - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->openCiviPage('admin/uf/group', 'reset=1'); $this->click('newCiviCRMProfile-top'); @@ -113,7 +111,7 @@ class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); //check for profile create - $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$profileTitle' has been added. You can add fields to this profile now")); + $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); //Add field to profile $this->click('field_name[0]'); @@ -127,7 +125,7 @@ class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); // delete the profile - $this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1'); + $this->openCiviPage('admin/uf/group', 'reset=1'); $this->_testdeleteProfile($profileTitle); } @@ -139,8 +137,6 @@ class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase { $this->waitForElementPresent('_qf_Group_next-bottom'); $this->click('_qf_Group_next-bottom'); $this->waitForElementPresent('newCiviCRMProfile-bottom'); - $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$profileTitle' has been deleted.")); + $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted."); } -} - - +} \ No newline at end of file -- 2.25.1