Testing: Selenium: ZimbraSelenium SampleTestCase: Difference between revisions
(Created page with '==General Information== Below is a sample test case with descriptions. ==Harness Overview== See Zimbra Selenium Overview ==Samp…') |
(→Code) |
||
Line 27: | Line 27: | ||
import com.zimbra.qa.selenium.projects.ajax.core.AjaxCommonTest; | import com.zimbra.qa.selenium.projects.ajax.core.AjaxCommonTest; | ||
import com.zimbra.qa.selenium.projects.ajax.ui.mail.FormMailNew; | import com.zimbra.qa.selenium.projects.ajax.ui.mail.FormMailNew; | ||
import com.zimbra.qa.selenium.projects.ajax.ui.mail.FormMailNew.Field; | |||
// Test case classes extend from a basic AjaxCommonTest class, which | |||
// includes functionality that is common to all test cases | |||
// | |||
public class CreateMailText extends AjaxCommonTest { | public class CreateMailText extends AjaxCommonTest { | ||
public CreateMailText() { | public CreateMailText() { | ||
// The AjaxCommonTest class defines a log4j Logger object | |||
// named "logger". This "logger" can be used to output | |||
// INFO level logging to the test results output folder | |||
// | |||
logger.info("New "+ CreateMailText.class.getCanonicalName()); | logger.info("New "+ CreateMailText.class.getCanonicalName()); | ||
// | // Define a starting page, which will be active before | ||
// each test method. For example, calendar test cases | |||
// will start in the calendar app automatically | |||
// | |||
super.startingPage = app.zPageMail; | super.startingPage = app.zPageMail; | ||
// The harness authenticates to the app automatically, using | |||
// the account defined by ZimbraAccount.AccountZWC (for ajax), | |||
// ZimbraAccount.AccountZMC (for mobile), ZimbraAccount.AccountZHC | |||
// (for HTML-lite), etc. | |||
// | |||
// Define any user preferences required for the test methods in | |||
// this class. The test account will have these preferences | |||
// set automatically. | |||
// | |||
// | |||
super.startingAccountPreferences = new HashMap<String , String>() {{ | super.startingAccountPreferences = new HashMap<String , String>() {{ | ||
put("zimbraPrefComposeFormat", "text"); | put("zimbraPrefComposeFormat", "text"); | ||
Line 43: | Line 65: | ||
} | } | ||
@Test( description = "Send a mail using Text editor", | // TestNG methods must be decorated with the @Test attribute to be | ||
groups = { "sanity" }) | // included in test execution | ||
@Test( | |||
// Use the description to specify the test case objective | |||
description = "Send a mail using Text editor", | |||
// Zimbra uses sanity, smoke, functional groups. See | |||
// the wiki for more information, definitions | |||
groups = { "sanity" } | |||
) | |||
public void CreateMailText_01() throws HarnessException { | public void CreateMailText_01() throws HarnessException { | ||
// Create | // Create a unique string to be used for the subject, | ||
// which minimizes the search results later in the test | |||
// | |||
String subject = "subject" + ZimbraSeleniumProperties.getUniqueString(); | |||
String body = "text" + ZimbraSeleniumProperties.getUniqueString(); | |||
// | // Use the ajax "app" object, which is defined in the base AjaxCommonTest object | ||
// | |||
// The "app" object contains a "zPageMail" object, which interfaces with | |||
// the "mail" tab. | |||
// | |||
// The zPageMail object has methods that can be used to click on the "NEW" button | |||
// | |||
// Certain button actions return other objects. In this case, a 'new mail compose' | |||
// screen opens, which is a "FormMailNew" object in the harness. | |||
// | |||
FormMailNew mailform = (FormMailNew) app.zPageMail.zToolbarPressButton(Button.B_NEW); | FormMailNew mailform = (FormMailNew) app.zPageMail.zToolbarPressButton(Button.B_NEW); | ||
// The ZAssert class extends the base java Assert class. Basically, | |||
// the ZAssert class has additional custom logging and result counters. | |||
// | |||
ZAssert.assertNotNull(mailform, "Verify the new form opened"); | ZAssert.assertNotNull(mailform, "Verify the new form opened"); | ||
// | // Use the FormMailNew object to fill out the fields | ||
mailform. | // | ||
// For convenience, the ZimbraAccount class has two static accounts, AccountA | |||
// and AccountB, that can be used for sender or recipients of sample emails | |||
// from the test account. | |||
// | |||
mailform.zFillField(Field.To, ZimbraAccount.AccountA().EmailAddress); | |||
mailform.zFillField(Field.Subject, subject); | |||
mailform.zFillField(Field.Body, body); | |||
// Send the message | // Send the message | ||
Line 66: | Line 117: | ||
MailItem received = MailItem.importFromSOAP(ZimbraAccount.AccountA(), "subject:("+ | // The framework.items.* classes have helper methods to import data | ||
// using SOAP into plain old java objects. For instance, the | |||
// MailItem.importFromSOAP() will use Zimbra's SOAP API requests SearchRequest | |||
// followed by GetMsgRequest to import the message into the "received" object | |||
// | |||
MailItem received = MailItem.importFromSOAP(ZimbraAccount.AccountA(), "subject:("+ subject +")"); | |||
// | // Verify the receipient message contains the correct data | ||
// | |||
ZAssert.assertEquals(received.dFromRecipient.dEmailAddress, app.zGetActiveAccount().EmailAddress, "Verify the from field is correct"); | ZAssert.assertEquals(received.dFromRecipient.dEmailAddress, app.zGetActiveAccount().EmailAddress, "Verify the from field is correct"); | ||
ZAssert.assertEquals(received.dToRecipients.get(0).dEmailAddress, ZimbraAccount.AccountA().EmailAddress, "Verify the to field is correct"); | ZAssert.assertEquals(received.dToRecipients.get(0).dEmailAddress, ZimbraAccount.AccountA().EmailAddress, "Verify the to field is correct"); | ||
ZAssert.assertEquals(received.dSubject, subject, "Verify the subject field is correct"); | |||
ZAssert.assertStringContains(received.dBodyText, | ZAssert.assertStringContains(received.dBodyText, body, "Verify the body field is correct"); | ||
} | } | ||
} | } | ||
===Walk Through=== | ===Walk Through=== |
Revision as of 20:18, 24 January 2011
General Information
Below is a sample test case with descriptions.
Harness Overview
Sample Test Case
Objective
The sample test case has the objective: "Send a mail using text editor"
Code
package com.zimbra.qa.selenium.projects.ajax.tests.mail.compose; import java.util.HashMap; import org.testng.annotations.Test; import com.zimbra.qa.selenium.framework.items.*; import com.zimbra.qa.selenium.framework.ui.*; import com.zimbra.qa.selenium.framework.util.*; import com.zimbra.qa.selenium.projects.ajax.core.AjaxCommonTest; import com.zimbra.qa.selenium.projects.ajax.ui.mail.FormMailNew; import com.zimbra.qa.selenium.projects.ajax.ui.mail.FormMailNew.Field; // Test case classes extend from a basic AjaxCommonTest class, which // includes functionality that is common to all test cases // public class CreateMailText extends AjaxCommonTest { public CreateMailText() { // The AjaxCommonTest class defines a log4j Logger object // named "logger". This "logger" can be used to output // INFO level logging to the test results output folder // logger.info("New "+ CreateMailText.class.getCanonicalName()); // Define a starting page, which will be active before // each test method. For example, calendar test cases // will start in the calendar app automatically // super.startingPage = app.zPageMail; // The harness authenticates to the app automatically, using // the account defined by ZimbraAccount.AccountZWC (for ajax), // ZimbraAccount.AccountZMC (for mobile), ZimbraAccount.AccountZHC // (for HTML-lite), etc. // // Define any user preferences required for the test methods in // this class. The test account will have these preferences // set automatically. // // super.startingAccountPreferences = new HashMap<String , String>() Template:Put("zimbraPrefComposeFormat", "text");; } // TestNG methods must be decorated with the @Test attribute to be // included in test execution @Test( // Use the description to specify the test case objective description = "Send a mail using Text editor", // Zimbra uses sanity, smoke, functional groups. See // the wiki for more information, definitions groups = { "sanity" } ) public void CreateMailText_01() throws HarnessException { // Create a unique string to be used for the subject, // which minimizes the search results later in the test // String subject = "subject" + ZimbraSeleniumProperties.getUniqueString(); String body = "text" + ZimbraSeleniumProperties.getUniqueString(); // Use the ajax "app" object, which is defined in the base AjaxCommonTest object // // The "app" object contains a "zPageMail" object, which interfaces with // the "mail" tab. // // The zPageMail object has methods that can be used to click on the "NEW" button // // Certain button actions return other objects. In this case, a 'new mail compose' // screen opens, which is a "FormMailNew" object in the harness. // FormMailNew mailform = (FormMailNew) app.zPageMail.zToolbarPressButton(Button.B_NEW); // The ZAssert class extends the base java Assert class. Basically, // the ZAssert class has additional custom logging and result counters. // ZAssert.assertNotNull(mailform, "Verify the new form opened"); // Use the FormMailNew object to fill out the fields // // For convenience, the ZimbraAccount class has two static accounts, AccountA // and AccountB, that can be used for sender or recipients of sample emails // from the test account. // mailform.zFillField(Field.To, ZimbraAccount.AccountA().EmailAddress); mailform.zFillField(Field.Subject, subject); mailform.zFillField(Field.Body, body); // Send the message mailform.zSubmit(); // The framework.items.* classes have helper methods to import data // using SOAP into plain old java objects. For instance, the // MailItem.importFromSOAP() will use Zimbra's SOAP API requests SearchRequest // followed by GetMsgRequest to import the message into the "received" object // MailItem received = MailItem.importFromSOAP(ZimbraAccount.AccountA(), "subject:("+ subject +")"); // Verify the receipient message contains the correct data // ZAssert.assertEquals(received.dFromRecipient.dEmailAddress, app.zGetActiveAccount().EmailAddress, "Verify the from field is correct"); ZAssert.assertEquals(received.dToRecipients.get(0).dEmailAddress, ZimbraAccount.AccountA().EmailAddress, "Verify the to field is correct"); ZAssert.assertEquals(received.dSubject, subject, "Verify the subject field is correct"); ZAssert.assertStringContains(received.dBodyText, body, "Verify the body field is correct"); } }
Walk Through