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…')
 
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 {
   
   
@SuppressWarnings("serial")
  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());
 
 
  // All tests start at the login page
  // 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 the message data to be sent
  // Create a unique string to be used for the subject,
  MailItem mail = new MailItem();
  // which minimizes the search results later in the test
  mail.dToRecipients.add(new RecipientItem(ZimbraAccount.AccountA()));
  //
  mail.dSubject = "subject" + ZimbraSeleniumProperties.getUniqueString();
  String subject = "subject" + ZimbraSeleniumProperties.getUniqueString();
  mail.dBodyText = "body" + ZimbraSeleniumProperties.getUniqueString();
  String body = "text" + ZimbraSeleniumProperties.getUniqueString();
 
 
 
 
  // Open the new mail form
  // 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");
 
 
  // Fill out the form with the data
  // Use the FormMailNew object to fill out the fields
  mailform.zFill(mail);
//
// 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:("+ mail.dSubject +")");
// 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 +")");
 
 
 
 
  // TODO: add checks for TO, Subject, Body
  // 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, mail.dSubject, "Verify the subject field is correct");
ZAssert.assertEquals(received.dSubject, subject, "Verify the subject field is correct");
  ZAssert.assertStringContains(received.dBodyText, mail.dBodyText, "Verify the body field is correct");
  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

See Zimbra Selenium 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

Verified Against: unknown Date Created: 11/7/2007
Article ID: https://wiki.zimbra.com/index.php?title=Testing:_Selenium:_ZimbraSelenium_SampleTestCase Date Modified: 2011-01-24



Try Zimbra

Try Zimbra Collaboration with a 60-day free trial.
Get it now »

Want to get involved?

You can contribute in the Community, Wiki, Code, or development of Zimlets.
Find out more. »

Looking for a Video?

Visit our YouTube channel to get the latest webinars, technology news, product overviews, and so much more.
Go to the YouTube channel »

Jump to: navigation, search