From 3fb9aed93e885108447f4193efaf8f39cf8f3a0c Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Thu, 7 Mar 2013 20:36:44 +0530 Subject: [PATCH] webtest improvements for mailing tests --- .../Mailing/AddMessageTemplateTest.php | 24 +++++----- .../Mailing/AddNewMailingComponentTest.php | 47 ++++--------------- 2 files changed, 23 insertions(+), 48 deletions(-) diff --git a/tests/phpunit/WebTest/Mailing/AddMessageTemplateTest.php b/tests/phpunit/WebTest/Mailing/AddMessageTemplateTest.php index d3756199b8..5a2d5d07c4 100644 --- a/tests/phpunit/WebTest/Mailing/AddMessageTemplateTest.php +++ b/tests/phpunit/WebTest/Mailing/AddMessageTemplateTest.php @@ -85,12 +85,14 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); // Is status message correct - $this->assertTrue($this->isTextPresent("The Message Template '$msgTitle' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "The Message Template '$msgTitle' has been saved."); // Verify text. - $this->assertTrue($this->isTextPresent($msgTitle)); + $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"), + 'Message Template Title not found!'); if (!$useTokens) { - $this->assertTrue($this->isTextPresent($msgSubject)); + $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"), + 'Message Subject not found!'); } } @@ -137,7 +139,7 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase { $this->assertChecked("open_tracking"); // do check count for Recipient - $this->assertTrue($this->isTextPresent("Total Recipients: 1")); + $this->assertElementContainsText('css=.messages', "Total Recipients: 1"); $this->click("_qf_Settings_next"); $this->waitForElementPresent("_qf_Upload_cancel"); @@ -152,13 +154,13 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase { $this->select('footer_id', "label=Mailing Footer"); // do check count for Recipient - $this->assertTrue($this->isTextPresent("Total Recipients: 1")); + $this->assertElementContainsText('css=.messages', "Total Recipients: 1"); // click next with nominal content $this->click("_qf_Upload_upload"); $this->waitForElementPresent("_qf_Test_cancel"); - $this->assertTrue($this->isTextPresent("Total Recipients: 1")); + $this->assertElementContainsText('css=.messages', "Total Recipients: 1"); // click next $this->click("_qf_Test_next"); @@ -167,15 +169,15 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase { $this->assertChecked("now"); // do check count for Recipient - $this->assertTrue($this->isTextPresent("Total Recipients: 1")); + $this->assertElementContainsText('css=.messages', "Total Recipients: 1"); // finally schedule the mail by clicking submit $this->click("_qf_Schedule_next"); $this->waitForPageToLoad($this->getTimeoutMsec()); //check redirected page to Scheduled and Sent Mailings and verify for mailing name - $this->assertTrue($this->isTextPresent("Scheduled and Sent Mailings")); - $this->assertTrue($this->isTextPresent("Mailing $mailingName Webtest")); + $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings"); + $this->assertElementContainsText("xpath=//table[@class='selector']/tbody//tr//td", "Mailing $mailingName Webtest"); $this->openCiviPage('mailing/queue', 'reset=1'); // verify status @@ -190,6 +192,6 @@ class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase { $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']"); $this->waitForElementPresent("_qf_ActivityView_next"); - $this->assertTrue($this->isTextPresent("Bulk Email Sent."), "Status message didn't show up after saving!"); + $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!"); } -} +} \ No newline at end of file diff --git a/tests/phpunit/WebTest/Mailing/AddNewMailingComponentTest.php b/tests/phpunit/WebTest/Mailing/AddNewMailingComponentTest.php index 7fa96dd9bf..ebf4e6ee36 100644 --- a/tests/phpunit/WebTest/Mailing/AddNewMailingComponentTest.php +++ b/tests/phpunit/WebTest/Mailing/AddNewMailingComponentTest.php @@ -46,8 +46,7 @@ class WebTest_Mailing_AddNewMailingComponentTest extends CiviSeleniumTestCase { $this->webtestLogin(); // Go directly to the URL of the screen that you will be testing (Add New Mailing Component). - $this->open($this->sboxPath . "civicrm/admin/component?action=add&reset=1"); - + $this->openCiviPage("admin/component", "action=add&reset=1"); // fill component name. $componentName = 'ComponentName_' . substr(sha1(rand()), 0, 7); @@ -75,14 +74,10 @@ class WebTest_Mailing_AddNewMailingComponentTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); // Is status message correct. - $this->assertTrue($this->isTextPresent("The mailing component '$componentName' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "The mailing component '$componentName' has been saved."); // Verify text. - $this->assertTrue($this->isTextPresent($componentName)); - $this->assertTrue($this->isTextPresent("Header")); - $this->assertTrue($this->isTextPresent($subject)); - $this->assertTrue($this->isTextPresent($txtMsg)); - $this->assertTrue($this->isTextPresent($htmlMsg)); + $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[text()='{$componentName}']/../td[2][text()='Header']/../td[3][text()='{$subject}']/../td[4][text()='{$txtMsg}']/../td[5][text()='{$htmlMsg}']"), "The row doesn't consists of proper component details"); } function testFooterAdd() { @@ -91,16 +86,10 @@ class WebTest_Mailing_AddNewMailingComponentTest extends CiviSeleniumTestCase { // class attributes. $this->open($this->sboxPath); - // Logging in. Remember to wait for page to load. In most cases, - // you can rely on 30000 as the value that allows your test to pass, however, - // sometimes your test might fail because of this. In such cases, it's better to pick one element - // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole - // page contents loaded and you can continue your test execution. $this->webtestLogin(); // Go directly to the URL of the screen that you will be testing (Add New Mailing Component). - $this->open($this->sboxPath . "civicrm/admin/component?action=add&reset=1"); - + $this->openCiviPage("admin/component", "action=add&reset=1"); // fill component name. $componentName = 'ComponentName_' . substr(sha1(rand()), 0, 7); @@ -128,14 +117,10 @@ class WebTest_Mailing_AddNewMailingComponentTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); // Is status message correct. - $this->assertTrue($this->isTextPresent("The mailing component '$componentName' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "The mailing component '$componentName' has been saved."); // Verify text. - $this->assertTrue($this->isTextPresent($componentName)); - $this->assertTrue($this->isTextPresent("Footer")); - $this->assertTrue($this->isTextPresent($subject)); - $this->assertTrue($this->isTextPresent($txtMsg)); - $this->assertTrue($this->isTextPresent($htmlMsg)); + $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[text()='{$componentName}']/../td[2][text()='Footer']/../td[3][text()='{$subject}']/../td[4][text()='{$txtMsg}']/../td[5][text()='{$htmlMsg}']"), "The row doesn't consists of proper component details"); } function testAutomatedAdd() { @@ -144,16 +129,10 @@ class WebTest_Mailing_AddNewMailingComponentTest extends CiviSeleniumTestCase { // class attributes. $this->open($this->sboxPath); - // Logging in. Remember to wait for page to load. In most cases, - // you can rely on 30000 as the value that allows your test to pass, however, - // sometimes your test might fail because of this. In such cases, it's better to pick one element - // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole - // page contents loaded and you can continue your test execution. $this->webtestLogin(); // Go directly to the URL of the screen that you will be testing (Add New Mailing Component). - $this->open($this->sboxPath . "civicrm/admin/component?action=add&reset=1"); - + $this->openCiviPage("admin/component", "action=add&reset=1"); // fill component name. $componentName = 'ComponentName_' . substr(sha1(rand()), 0, 7); @@ -181,15 +160,9 @@ class WebTest_Mailing_AddNewMailingComponentTest extends CiviSeleniumTestCase { $this->waitForPageToLoad($this->getTimeoutMsec()); // Is status message correct. - $this->assertTrue($this->isTextPresent("The mailing component '$componentName' has been saved.")); + $this->assertElementContainsText('crm-notification-container', "The mailing component '$componentName' has been saved."); // Verify text - $this->assertTrue($this->isTextPresent($componentName)); - $this->assertTrue($this->isTextPresent("Reply")); - $this->assertTrue($this->isTextPresent($subject)); - $this->assertTrue($this->isTextPresent($txtMsg)); - $this->assertTrue($this->isTextPresent($htmlMsg)); + $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[text()='{$componentName}']/../td[2][text()='Reply']/../td[3][text()='{$subject}']/../td[4][text()='{$txtMsg}']/../td[5][text()='{$htmlMsg}']"), "The row doesn't consists of proper component details"); } -} - - +} \ No newline at end of file -- 2.25.1