From 9d15e9875d09571e3d87a3e01390db4674ac13e0 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Mon, 4 Mar 2013 15:28:37 +0530 Subject: [PATCH] webtest code improvement(using helper functions of CiviSeleniumTestCase) and cleanup --- .../WebTest/Member/EditMembershipTest.php | 24 +++++--------- .../Member/InheritedMembershipTest.php | 33 ++++++++----------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/tests/phpunit/WebTest/Member/EditMembershipTest.php b/tests/phpunit/WebTest/Member/EditMembershipTest.php index 4416c313e4..16cef0586a 100644 --- a/tests/phpunit/WebTest/Member/EditMembershipTest.php +++ b/tests/phpunit/WebTest/Member/EditMembershipTest.php @@ -1,5 +1,5 @@ webtestAddMembershipType(); // now add membership - $this->open($this->sboxPath . "civicrm/member/add?reset=1&action=add&context=standalone"); - - $this->waitForElementPresent("_qf_Membership_upload"); + $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload"); // select contact $this->webtestFillAutocomplete($contactName); @@ -69,13 +66,11 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase { $this->click("xpath=//div[@id='memberships']//table/tbody/tr[1]/td[9]/span/a[text()='View']"); $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); $expected = array( - 2 => $membershipTypes['membership_type'], - 3 => 'New', - 4 => 'Membership StandaloneAddTest Webtest', + 'Membership Type' => $membershipTypes['membership_type'], + 'Status' => 'New', + 'Source' => 'Membership StandaloneAddTest Webtest', ); - foreach ($expected as $label => $value) { - $this->verifyText("xpath=id('MembershipView')/div[2]/div/table[1]/tbody/tr[$label]/td[2]", preg_quote($value)); - } + $this->webtestVerifyTabularData($expected); // now edit and update type and status $this->click("crm-membership-edit-button-top"); @@ -90,8 +85,8 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase { $this->waitForElementPresent("access"); // Use activity search to find the expected activities - $this->open($this->sboxPath . "civicrm/activity/search?reset=1"); - $this->waitForElementPresent("_qf_Search_refresh"); + $this->openCiviPage('activity/search', 'reset=1', "_qf_Search_refresh"); + $this->type("sort_name", $contactName); $this->click('activity_type_id[35]'); $this->click('activity_type_id[36]'); @@ -105,5 +100,4 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase { $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[3]/td[3][text()='Type changed from {$membershipTypes['membership_type']} to General']")); $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[3]/td[5]/a[text()='{$contactName}']")); } -} - +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Member/InheritedMembershipTest.php b/tests/phpunit/WebTest/Member/InheritedMembershipTest.php index 716574286f..e13cd36478 100644 --- a/tests/phpunit/WebTest/Member/InheritedMembershipTest.php +++ b/tests/phpunit/WebTest/Member/InheritedMembershipTest.php @@ -24,7 +24,6 @@ +--------------------------------------------------------------------+ */ - require_once 'CiviTest/CiviSeleniumTestCase.php'; class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase { protected function setUp() { @@ -40,19 +39,17 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase { // Log in using webtestLogin() method $this->webtestLogin(); - $this->open($this->sboxPath . 'civicrm/contact/add?reset=1&ct=Organization'); - $this->waitForElementPresent('_qf_Contact_cancel'); + $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel'); $title = substr(sha1(rand()), 0, 7); $this->type('organization_name', "Organization $title"); $this->type('email_1_email', "$title@org.com"); $this->click('_qf_Contact_upload_view'); $this->waitForPageToLoad($this->getTimeoutMsec()); - $this->assertTrue($this->isTextPresent("Organization $title has been created.")); + $this->assertElementContainsText('crm-notification-container', "Organization {$title} has been created."); // Go directly to the URL - $this->open($this->sboxPath . 'civicrm/admin/member/membershipType?reset=1&action=browse'); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse'); $this->click('link=Add Membership Type'); $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); @@ -78,10 +75,9 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase { $this->click('_qf_MembershipType_upload-bottom'); $this->waitForElementPresent('link=Add Membership Type'); - $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); - $this->open($this->sboxPath . 'civicrm/contact/add?reset=1&ct=Organization'); - $this->waitForElementPresent('_qf_Contact_cancel'); + $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel'); // creating another Orgnization $title1 = substr(sha1(rand()), 0, 7); @@ -114,9 +110,8 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase { $this->waitForTextPresent($sourceText); // Is status message correct? - $this->assertTrue($this->isTextPresent("Membership Type $title membership for Organization $title1 has been added."), - "Status message didn't show up after saving!" - ); + $this->assertElementContainsText('crm-notification-container', "Membership Type $title membership for Organization $title1 has been added.", + "Status message didn't show up after saving!"); // click through to the membership view screen $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); @@ -130,7 +125,7 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase { 'joinDate', 'startDate', 'endDate') as $date) { $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); } - + $this->webtestVerifyTabularData( array( 'Membership Type' => "Membership Type $title", @@ -211,21 +206,20 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase { $this->click('_qf_Relationship_upload'); $this->waitForElementPresent('inactive-relationships'); //check the status message - $this->assertTrue($this->isTextPresent('Relationship record has been updated.')); + $this->assertElementContainsText('crm-notification-container', 'Relationship record has been updated.'); // click through to the membership view screen $this->click('css=li#tab_member a'); //verify inherited membership has been removed - $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid=$id&selectedChild=member"); - $this->waitForElementPresent("xpath=//div[@class='crm-container-snippet']/div/div[3]"); + $this->openCiviPage("contact/view", "reset=1&cid=$id&selectedChild=member", "xpath=//div[@class='crm-container-snippet']/div/div[3]"); $this->assertTrue($this->isTextPresent('No memberships have been recorded for this contact.')); // visit relationship tab and re-enable the relationship $this->click('css=li#tab_rel a'); $this->waitForElementPresent('css=div.action-link'); $this->click("//li[@id='tab_rel']/a"); - + $this->waitForElementPresent("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span/a[text()='Edit']"); $this->click("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span/a[text()='Edit']"); $this->waitForElementPresent('is_active'); @@ -235,7 +229,7 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase { $this->click('_qf_Relationship_upload'); $this->waitForElementPresent('current-relationships'); //check the status message - $this->assertTrue($this->isTextPresent('Relationship record has been updated.')); + $this->assertElementContainsText('crm-notification-container', 'Relationship record has been updated.'); //check for memberships $this->click('css=li#tab_member a'); @@ -255,8 +249,7 @@ class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase { sleep(10); //verify inherited membership has been removed - $this->open($this->sboxPath . "civicrm/contact/view?reset=1&cid=$id&selectedChild=member"); - $this->waitForElementPresent("xpath=//div[@class='crm-container-snippet']/div/div[3]"); + $this->openCiviPage("contact/view", "reset=1&cid={$id}&selectedChild=member", "xpath=//div[@class='crm-container-snippet']/div/div[3]"); $this->assertTrue($this->isTextPresent('No memberships have been recorded for this contact.')); //enable relationship -- 2.25.1