Author: mposolda(a)redhat.com
Date: 2009-06-22 09:24:53 -0400 (Mon, 22 Jun 2009)
New Revision: 13476
Added:
branches/JBoss_Portal_Branch_2_7/testsuite/ui-tests/src/org/jboss/portal/test/selenium/PortalBookstoreSampleTestCase.java
Log:
PortalBookstoreSampleTestCase added to the ui testsuite.
Added:
branches/JBoss_Portal_Branch_2_7/testsuite/ui-tests/src/org/jboss/portal/test/selenium/PortalBookstoreSampleTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/testsuite/ui-tests/src/org/jboss/portal/test/selenium/PortalBookstoreSampleTestCase.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/testsuite/ui-tests/src/org/jboss/portal/test/selenium/PortalBookstoreSampleTestCase.java 2009-06-22
13:24:53 UTC (rev 13476)
@@ -0,0 +1,385 @@
+package org.jboss.portal.test.selenium;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * The Class PortalBookstoreSamplesTestCase is used for testing Bookstore sample
application with usage of selenium.
+ * BookstoreSample application is used for demonstrating coordination features like
events and public render parameters.
+ * So the main focus is maked to test the communication between portlets.
+ *
+ * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
+ *
+ */
+@Test(groups = { "test_samples" }, enabled = true)
+public class PortalBookstoreSampleTestCase extends JBossPortalSeleniumTestCase {
+
+ /** prefix for locator properties = samples.bookstore. */
+ public static String casePfx = "samples.bookstore.";
+
+ private final String ADR_BOOKSTORE_SAMPLES = getLoc(casePfx+"adr",
"/portal/portal/default/Bookstore+sample");
+ private final String PORTLET_MODE_NORMAL = getMess(casePfx+"pmode.normal",
"portlet-mode-normal");
+ private final String PORTLET_MODE_MINIMIZED =
getMess(casePfx+"pmode.minimized", "portlet-mode-minimized");
+
+ private final String BOOK_1000_TITLE = getMess(casePfx+"book.1000.title",
"Foundation Flash Cartoon Animation");
+ private final String BOOK_1000_AUTHOR = getMess(casePfx+"book.1000.author",
"Tim Jones");
+ private final String BOOK_1000_IMAGE = getMess(casePfx+"book.1000.img",
"animation.jpg");
+ private final String BOOK_1001_TITLE = getMess(casePfx+"book.1001.title",
"Head First Design Patterns");
+ private final String BOOK_1001_AUTHOR = getMess(casePfx+"book.1001.author",
"Elisabeth Freeman");
+ private final String BOOK_1001_IMAGE = getMess(casePfx+"book.1001.img",
"patterns.jpg");
+ private final String BOOK_1004_TITLE = getMess(casePfx+"book.1004.title",
"Java Servlet and JSP Cookbook");
+ private final String BOOK_1004_AUTHOR = getMess(casePfx+"book.1004.author",
"Bruce Perry");
+ private final String BOOK_1004_IMAGE = getMess(casePfx+"book.1004.img",
"servlets.jpg");
+ private final String BOOK_1005_TITLE = getMess(casePfx+"book.1005.title",
"Mommywood");
+ private final String BOOK_1005_AUTHOR = getMess(casePfx+"book.1005.author",
"Tori Spelling");
+ private final String BOOK_1005_IMAGE = getMess(casePfx+"book.1005.img",
"mommywood.jpg");
+ private final String BOOK_1007_TITLE = getMess(casePfx+"book.1007.title",
"The Picture of Dorian Gray");
+ private final String BOOK_1007_AUTHOR = getMess(casePfx+"book.1007.author",
"Oscar Wilde");
+ private final String BOOK_1007_IMAGE = getMess(casePfx+"book.1007.img",
"dorian.jpg");
+
+ // BookstorePortlet
+ private final String BOOKSTORE_PORTLET_START_SHOPPING_LINK =
getLoc(casePfx+"bookstore.lnk.start", "link=Start Shopping");
+ private final String BOOKSTORE_PORTLET_BOOK_DETAIL_LINK =
getLoc(casePfx+"bookstore.lnk.detail", "link=Java Servlet and JSP
Cookbook");
+
+ // BookCatalogPortlet
+ private final String CATALOG_PORTLET_FIRST_ICON =
getLoc(casePfx+"catalog.icon",
"//div[@id='regionA']/div[2]/table/tbody/tr[1]/td[2]/div[2]/span[1]/a@class");
+
+ private final String CATALOG_PORTLET_TABLE_TR_PREFFIX =
getLoc(casePfx+"catalog.tr.pref",
"//tr[@id='BookCatalogPortlet_");
+ private final String CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX =
getLoc(casePfx+"catalog.tr.suf.detail", "']/td[1]/a/strong");
+ private final String CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX =
getLoc(casePfx+"catalog.tr.suf.add", "']/td[4]/p/strong/a");
+ private final String CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX =
getLoc(casePfx+"catalog.tr.suf.count", "']/td[3]");
+
+ private final String CATALOG_PORTLET_TITLE = getMess(casePfx+"catalog.title",
"Book Catalog Portlet");
+ private final String CATALOG_PORTLET_CHOOSE =
getMess(casePfx+"catalog.choose", "Please choose from our
selections:");
+
+ // BookDetailPortlet
+ private final String DETAIL_PORTLET_IMAGE_PREFIX =
getLoc(casePfx+"detail.image.pref", "//img[@alt='");
+ private final String DETAIL_PORTLET_IMAGE_SUFFIX =
getLoc(casePfx+"detail.image.suf", "']");
+ private final String DETAIL_PORTLET_BOOK_TITLE =
getLoc(casePfx+"detail.bktitle", "bookDetailPortlet_title");
+ private final String DETAIL_PORTLET_BOOK_AUTHOR =
getLoc(casePfx+"detail.bkauthor", "bookDetailPortlet_author");
+ private final String DETAIL_PORTLET_ADD_LINK =
getLoc(casePfx+"detail.lnk.add", "BookDetailPortlet_AddBookLink");
+
+ // BookShowCartPortlet
+ private final String SHOWCART_PORTLET_CLEAR_CART_LINK =
getLoc(casePfx+"showcart.lnk.clear", "link=Clear Cart");
+ private final String SHOWCART_PORTLET_HEADER =
getLoc(casePfx+"showcart.header", "BookShowCartPortlet_header");
+ private final String SHOWCART_PORTLET_TABLE = getLoc(casePfx+"showcart.table",
"BookShowCartPortlet_cardTable");
+ private final String SHOWCART_PORTLET_TABLE_TR_PREFIX =
getLoc(casePfx+"showcart.table.tr.pref",
"//tr[@id='BookShowCartPortlet_cardTable_");
+ private final String SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX =
getLoc(casePfx+"showcart.table.tr.count.suf", "']/td[1]");
+ private final String SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX =
getLoc(casePfx+"showcart.table.tr.title.suf",
"']/td[2]/strong/a");
+ private final String SHOWCART_PORTLET_TABLE_TR_REMOVE_SUFFIX =
getLoc(casePfx+"showcart.table.tr.remove.suf",
"']/td[4]/strong/a");
+
+ private final String SHOWCART_PORTLET_EMPTY_CARD =
getMess(casePfx+"showcart.header.card.empty", "Your cart is empty.");
+ private final String SHOWCART_PORTLET_CARD_ITEMS_PREFIX =
getMess(casePfx+"showcart.header.card.pref", "Your shopping cart contains
");
+ private final String SHOWCART_PORTLET_CARD_ITEMS_SUFFIX =
getMess(casePfx+"showcart.header.card.pref", " items.");
+
+ // BookCashierPortlet
+ private final String CASHIER_PORTLET_AMOUNT = getLoc(casePfx+"cashier.amount",
"BookCashierPortlet_amount");
+ private final String CASHIER_PORTLET_INPUT_NAME =
getLoc(casePfx+"cashier.inp.name", "cardname");
+ private final String CASHIER_PORTLET_INPUT_NUMBER =
getLoc(casePfx+"cashier.inp.num", "cardnum");
+ private final String CASHIER_PORTLET_SUBMIT = getLoc(casePfx+"cashier.submit",
"cashierSubmit");
+
+ // BookReceiptPortlet
+ private final String RECEIPT_PORTLET_HEADER = getLoc(casePfx+"receipt.header",
"BookReceiptPortlet_header");
+ private final String RECEIPT_PORTLET_SUCCESS =
getMess(casePfx+"receipt.success", "Thank you for purchasing your books
from us ");
+ private final String RECEIPT_PORTLET_FAILURE =
getMess(casePfx+"receipt.failure", "Your order could not be completed due
to insufficient inventory.");
+ private final String RECEIPT_PORTLET_FAILURE_MESSAGE =
getMess(casePfx+"receipt.failure.mess", "Not enough books with title:
Foundation Flash Cartoon Animation in inventory.");
+
+ /**
+ * This runs before each test.
+ */
+ @BeforeMethod(groups = { "log" })
+ protected void beforeTest() {
+ selenium.open(ADR_BOOKSTORE_SAMPLES);
+ selenium.waitForPageToLoad(PAGE_LOAD);
+ // clear shopping cart if somethink is on it
+ if (selenium.isElementPresent(SHOWCART_PORTLET_CLEAR_CART_LINK)) {
+ clickAndWait(SHOWCART_PORTLET_CLEAR_CART_LINK);
+ }
+ }
+
+ /**
+ * This runs after each test.
+ */
+ @AfterMethod(groups = { "log" })
+ protected void logoutAfterTest() {
+ }
+
+ /**
+ * Test of ShowCatalogEvent. While clicking on "Start Shopping" link in
Bookstore portlet, than the event should be thrown and
+ * BookCatalogPortlet should be put from minimized state to normal state.
+ */
+ @Test(enabled = true)
+ public void testBookstorePortletShowCatalog() {
+ Assert.assertTrue(selenium.isTextPresent(CATALOG_PORTLET_TITLE));
+ // Book Catalog portlet is minimized, so the "normalize portlet" icon is
presented.
+ Assert.assertEquals(selenium.getAttribute(CATALOG_PORTLET_FIRST_ICON),
PORTLET_MODE_NORMAL);
+ Assert.assertFalse(selenium.isTextPresent(CATALOG_PORTLET_CHOOSE));
+
+ // Click to "Start Shopping" and verify that portlet is shown in normal state
and so "minimize portlet" icon is presented.
+ Assert.assertTrue(selenium.isElementPresent(BOOKSTORE_PORTLET_START_SHOPPING_LINK));
+ clickAndWait(BOOKSTORE_PORTLET_START_SHOPPING_LINK);
+ Assert.assertEquals(selenium.getAttribute(CATALOG_PORTLET_FIRST_ICON),
PORTLET_MODE_MINIMIZED);
+ Assert.assertTrue(selenium.isTextPresent(CATALOG_PORTLET_CHOOSE));
+ }
+
+ /**
+ * Test of bookDetailId_Bookstore public render parameter. While clicking on book link
at Bookstore portlet,
+ * the book detail should be shown in BookDetailPortlet.
+ */
+ @Test(enabled = true)
+ public void testBookstorePortletShowBookDetail() {
+ // No detail of any book is shown
+ Assert.assertFalse(selenium.isElementPresent(DETAIL_PORTLET_IMAGE_PREFIX +
BOOK_1004_IMAGE + DETAIL_PORTLET_IMAGE_SUFFIX));
+ // Click to the detail link in Bookstore portlet
+ Assert.assertTrue(selenium.isElementPresent(BOOKSTORE_PORTLET_BOOK_DETAIL_LINK));
+ clickAndWait(BOOKSTORE_PORTLET_BOOK_DETAIL_LINK);
+ // Assert that book is shown in BookDetail portlet.
+ Assert.assertEquals(BOOK_1004_TITLE, selenium.getText(DETAIL_PORTLET_BOOK_TITLE));
+ Assert.assertEquals(BOOK_1004_AUTHOR,
selenium.getText(DETAIL_PORTLET_BOOK_AUTHOR));
+ Assert.assertTrue(selenium.isElementPresent(DETAIL_PORTLET_IMAGE_PREFIX +
BOOK_1004_IMAGE + DETAIL_PORTLET_IMAGE_SUFFIX));
+ }
+
+ /**
+ * Test of bookDetailId_BookCatalog public render parameter. While clicking on book
detail link in BookCatalogPortlet
+ * the book detail should be shown in BookDetailPortlet.
+ */
+ @Test(enabled = true, dependsOnMethods={ "testBookstorePortletShowCatalog"
})
+ public void testBookCatalogPortletShowBookDetail() {
+ // assert that book with id 1000 is shown in BookDetailPortlet while click to it in
BookCatalogPortlet
+ Assert.assertTrue(selenium.isElementPresent(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1000" + CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX));
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX);
+ Assert.assertEquals(BOOK_1000_TITLE, selenium.getText(DETAIL_PORTLET_BOOK_TITLE));
+ Assert.assertEquals(BOOK_1000_AUTHOR, selenium.getText(DETAIL_PORTLET_BOOK_AUTHOR));
+ Assert.assertTrue(selenium.isElementPresent(DETAIL_PORTLET_IMAGE_PREFIX +
BOOK_1000_IMAGE + DETAIL_PORTLET_IMAGE_SUFFIX));
+ // assert that book with id 1001 is shown in BookDetailPortlet while click to it in
BookCatalogPortlet
+ Assert.assertEquals(BOOK_1001_TITLE, selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX
+ "1001" + CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX));
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX);
+ Assert.assertEquals(BOOK_1001_TITLE, selenium.getText(DETAIL_PORTLET_BOOK_TITLE));
+ Assert.assertEquals(BOOK_1001_AUTHOR, selenium.getText(DETAIL_PORTLET_BOOK_AUTHOR));
+ Assert.assertTrue(selenium.isElementPresent(DETAIL_PORTLET_IMAGE_PREFIX +
BOOK_1001_IMAGE + DETAIL_PORTLET_IMAGE_SUFFIX));
+ // assert that book with id 1007 is shown in BookDetailPortlet while click to it in
BookCatalogPortlet
+ Assert.assertEquals(BOOK_1007_TITLE, selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX
+ "1007" + CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX));
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1007" +
CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX);
+ Assert.assertEquals(BOOK_1007_TITLE, selenium.getText(DETAIL_PORTLET_BOOK_TITLE));
+ Assert.assertEquals(BOOK_1007_AUTHOR, selenium.getText(DETAIL_PORTLET_BOOK_AUTHOR));
+ Assert.assertTrue(selenium.isElementPresent(DETAIL_PORTLET_IMAGE_PREFIX +
BOOK_1007_IMAGE + DETAIL_PORTLET_IMAGE_SUFFIX));
+ }
+
+ /**
+ * Test of AddBookEvent_Explicit sent from BookCatalogPortlet. While clicking on
"Add to cart" link in BookCatalogPortlet
+ * the book should be added to BookShowCartPortlet.
+ */
+ @Test(enabled = true, dependsOnMethods={ "testBookstorePortletShowCatalog"
})
+ public void testBookCatalogPortletAddBook() {
+ // Card is empty in BookShowCartPortlet
+ Assert.assertEquals(SHOWCART_PORTLET_EMPTY_CARD,
selenium.getText(SHOWCART_PORTLET_HEADER));
+ Assert.assertFalse(selenium.isElementPresent(SHOWCART_PORTLET_TABLE));
+ // Book is added in BookCatalogPortlet and it should be shown in BookShowCartPortlet
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ Assert.assertEquals(SHOWCART_PORTLET_CARD_ITEMS_PREFIX + "1 item.",
selenium.getText(SHOWCART_PORTLET_HEADER));
+ Assert.assertEquals("1", selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX +
"1001" + SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals(BOOK_1001_TITLE, selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX
+ "1001" + SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX));
+ Assert.assertEquals(4, countTableRows((SHOWCART_PORTLET_TABLE)));
+ // Add more books
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1005" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1007" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ // Test that books are added
+ Assert.assertEquals(7, countTableRows(SHOWCART_PORTLET_TABLE));
+ Assert.assertEquals(SHOWCART_PORTLET_CARD_ITEMS_PREFIX + "8" +
SHOWCART_PORTLET_CARD_ITEMS_SUFFIX, selenium.getText(SHOWCART_PORTLET_HEADER));
+ Assert.assertEquals("2", selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX +
"1000" + SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("4", selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX +
"1001" + SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("1", selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX +
"1005" + SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("1", selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX +
"1007" + SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals(BOOK_1000_TITLE, selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX
+ "1000" + SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX));
+ Assert.assertEquals(BOOK_1005_TITLE, selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX
+ "1005" + SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX));
+ Assert.assertEquals(BOOK_1007_TITLE, selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX
+ "1007" + SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX));
+ }
+
+ /**
+ * Test of AddBookEvent_Explicit sent from BookDetailPortlet. While clicking on
"Add to cart" link in BookDetailPortlet
+ * the book should be added to BookShowCartPortlet.
+ */
+ @Test(enabled = true, dependsOnMethods={ "testBookstorePortletShowCatalog"
})
+ public void testBookDetailPortletAddBook() {
+ // Show book 1000 to BookDetailPortlet - add it two times
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX);
+ clickAndWait(DETAIL_PORTLET_ADD_LINK);
+ clickAndWait(DETAIL_PORTLET_ADD_LINK);
+ // Show book 1001 to BookDetailPortlet - add it two times
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX);
+ clickAndWait(DETAIL_PORTLET_ADD_LINK);
+ clickAndWait(DETAIL_PORTLET_ADD_LINK);
+ // Book 1004 from first portlet - one timme
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1004" +
CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX);
+ clickAndWait(DETAIL_PORTLET_ADD_LINK);
+ // 1001 another time
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_DETAIL_SUFFIX);
+ clickAndWait(DETAIL_PORTLET_ADD_LINK);
+ // Test that books are added
+ Assert.assertEquals(6, countTableRows((SHOWCART_PORTLET_TABLE)));
+ Assert.assertEquals(SHOWCART_PORTLET_CARD_ITEMS_PREFIX + "6" +
SHOWCART_PORTLET_CARD_ITEMS_SUFFIX, selenium.getText(SHOWCART_PORTLET_HEADER));
+ Assert.assertEquals("2", selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX +
"1000" + SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("3", selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX +
"1001" + SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("1", selenium.getText(SHOWCART_PORTLET_TABLE_TR_PREFIX +
"1004" + SHOWCART_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ }
+
+ /**
+ * Test of bookDetailId_ShowCart public render parameter, which is sent from
BookShowCartPortlet. While clicking to some book link in BookShowCartPortlet, the book
should be shown
+ * in BookDetailPortlet
+ */
+ @Test(enabled = true, dependsOnMethods={ "testBookstorePortletShowCatalog" })
+ public void testBookShowCartPortletBookDetail() {
+ // Add some books from catalog to shopping cart
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1005" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+
+ // Click to detail links in BookShowCartPortlet and test that books are shown in
BookDetailPortlet
+ clickAndWait(SHOWCART_PORTLET_TABLE_TR_PREFIX + "1000" +
SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX);
+ Assert.assertEquals(BOOK_1000_TITLE, selenium.getText(DETAIL_PORTLET_BOOK_TITLE));
+ Assert.assertEquals(BOOK_1000_AUTHOR, selenium.getText(DETAIL_PORTLET_BOOK_AUTHOR));
+ Assert.assertTrue(selenium.isElementPresent(DETAIL_PORTLET_IMAGE_PREFIX +
BOOK_1000_IMAGE + DETAIL_PORTLET_IMAGE_SUFFIX));
+
+ clickAndWait(SHOWCART_PORTLET_TABLE_TR_PREFIX + "1001" +
SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX);
+ Assert.assertEquals(BOOK_1001_TITLE, selenium.getText(DETAIL_PORTLET_BOOK_TITLE));
+ Assert.assertEquals(BOOK_1001_AUTHOR, selenium.getText(DETAIL_PORTLET_BOOK_AUTHOR));
+ Assert.assertTrue(selenium.isElementPresent(DETAIL_PORTLET_IMAGE_PREFIX +
BOOK_1001_IMAGE + DETAIL_PORTLET_IMAGE_SUFFIX));
+
+ clickAndWait(SHOWCART_PORTLET_TABLE_TR_PREFIX + "1005" +
SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX);
+ Assert.assertEquals(BOOK_1005_TITLE, selenium.getText(DETAIL_PORTLET_BOOK_TITLE));
+ Assert.assertEquals(BOOK_1005_AUTHOR, selenium.getText(DETAIL_PORTLET_BOOK_AUTHOR));
+ Assert.assertTrue(selenium.isElementPresent(DETAIL_PORTLET_IMAGE_PREFIX +
BOOK_1005_IMAGE + DETAIL_PORTLET_IMAGE_SUFFIX));
+ }
+
+ /**
+ * Test that totalAmount public render parameter is correctly sent and amount is
correctly shown in BookCashierPortlet.
+ */
+ @Test(enabled = true, dependsOnMethods={ "testBookstorePortletShowCatalog" })
+ public void testBookShowCartPortletTotalAmount() {
+ // Add some books from catalog to shopping cart
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1005" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ // verify 1
+ Assert.assertTrue(valueEqualsCurrency(selenium.getText(CASHIER_PORTLET_AMOUNT),
149.93));
+
+ // Add books from details portlet
+ clickAndWait(SHOWCART_PORTLET_TABLE_TR_PREFIX + "1000" +
SHOWCART_PORTLET_TABLE_TR_TITLE_SUFFIX);
+ clickAndWait(DETAIL_PORTLET_ADD_LINK);
+ clickAndWait(DETAIL_PORTLET_ADD_LINK);
+ // verify 2
+ Assert.assertTrue(valueEqualsCurrency(selenium.getText(CASHIER_PORTLET_AMOUNT),
229.91));
+
+ // Remove some books
+ clickAndWait(SHOWCART_PORTLET_TABLE_TR_PREFIX + "1005" +
SHOWCART_PORTLET_TABLE_TR_REMOVE_SUFFIX);
+ clickAndWait(SHOWCART_PORTLET_TABLE_TR_PREFIX + "1000" +
SHOWCART_PORTLET_TABLE_TR_REMOVE_SUFFIX);
+ clickAndWait(SHOWCART_PORTLET_TABLE_TR_PREFIX + "1000" +
SHOWCART_PORTLET_TABLE_TR_REMOVE_SUFFIX);
+ // verify 3
+ Assert.assertTrue(valueEqualsCurrency(selenium.getText(CASHIER_PORTLET_AMOUNT),
124.93));
+
+ // Clear card
+ clickAndWait(SHOWCART_PORTLET_CLEAR_CART_LINK);
+ // verify 4
+ Assert.assertTrue(valueEqualsCurrency(selenium.getText(CASHIER_PORTLET_AMOUNT),
0.00));
+ }
+
+ /**
+ * Test the SendReceiptEvent event and cardName public render parameters. The oreder of
all books is submit in Cashier portlet and the successfull message
+ * is shown in BookReceiptPortlet.
+ */
+ @Test(enabled = true, dependsOnMethods={ "testBookstorePortletShowCatalog" })
+ public void testBookCashierPortletSubmitSuccessfull() {
+ // Add some books from catalog to shopping cart
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1004" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1004" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ Assert.assertEquals(SHOWCART_PORTLET_CARD_ITEMS_PREFIX + "5" +
SHOWCART_PORTLET_CARD_ITEMS_SUFFIX, selenium.getText(SHOWCART_PORTLET_HEADER));
+ Assert.assertTrue(valueEqualsCurrency(selenium.getText(CASHIER_PORTLET_AMOUNT),
214.83));
+ Assert.assertEquals("3", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1000" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("4", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1001" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("9", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1004" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ // Fill the name and number in BookCashierPortlet and submit
+ selenium.type(CASHIER_PORTLET_INPUT_NAME, "Joseph Carry");
+ selenium.type(CASHIER_PORTLET_INPUT_NUMBER, "1111 2222 3333");
+ clickAndWait(CASHIER_PORTLET_SUBMIT);
+ // check BookShowCartPortlet and BookReceivePortlet
+ Assert.assertEquals(SHOWCART_PORTLET_EMPTY_CARD,
selenium.getText(SHOWCART_PORTLET_HEADER));
+ Assert.assertEquals(RECEIPT_PORTLET_SUCCESS + "Joseph Carry.",
selenium.getText(RECEIPT_PORTLET_HEADER));
+ Assert.assertEquals("1", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1000" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("3", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1001" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("7", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1004" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ // Test second successfull shopping
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ Assert.assertEquals(SHOWCART_PORTLET_CARD_ITEMS_PREFIX + "2" +
SHOWCART_PORTLET_CARD_ITEMS_SUFFIX, selenium.getText(SHOWCART_PORTLET_HEADER));
+ selenium.type(CASHIER_PORTLET_INPUT_NAME, "Martin Carry");
+ selenium.type(CASHIER_PORTLET_INPUT_NUMBER, "1111 2222 3333");
+ clickAndWait(CASHIER_PORTLET_SUBMIT);
+ Assert.assertEquals(SHOWCART_PORTLET_EMPTY_CARD,
selenium.getText(SHOWCART_PORTLET_HEADER));
+ Assert.assertEquals(RECEIPT_PORTLET_SUCCESS + "Martin Carry.",
selenium.getText(RECEIPT_PORTLET_HEADER));
+ Assert.assertEquals("0", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1000" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("2", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1001" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ }
+
+ /**
+ * Test the SendReceiptEvent event and exceptionMessage public render parameters. The
oreder of all books is submit in Cashier portlet but the error message
+ * is shown in BookReceivePortlet.
+ */
+ @Test(enabled = true, dependsOnMethods={
"testBookCashierPortletSubmitSuccessfull" })
+ public void testBookCashierPortletSubmitFailure() {
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1000" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ clickAndWait(CATALOG_PORTLET_TABLE_TR_PREFFIX + "1001" +
CATALOG_PORTLET_TABLE_TR_ADD_SUFFIX);
+ Assert.assertEquals(SHOWCART_PORTLET_CARD_ITEMS_PREFIX + "2" +
SHOWCART_PORTLET_CARD_ITEMS_SUFFIX, selenium.getText(SHOWCART_PORTLET_HEADER));
+ selenium.type(CASHIER_PORTLET_INPUT_NAME, "Martin Carry");
+ selenium.type(CASHIER_PORTLET_INPUT_NUMBER, "1111 2222 3333");
+ clickAndWait(CASHIER_PORTLET_SUBMIT);
+ // Check that order exception occured and order was not performed
+ Assert.assertEquals(RECEIPT_PORTLET_FAILURE,
selenium.getText(RECEIPT_PORTLET_HEADER));
+ Assert.assertTrue(selenium.isTextPresent(RECEIPT_PORTLET_FAILURE_MESSAGE));
+ Assert.assertEquals(SHOWCART_PORTLET_CARD_ITEMS_PREFIX + "2" +
SHOWCART_PORTLET_CARD_ITEMS_SUFFIX, selenium.getText(SHOWCART_PORTLET_HEADER));
+ // Remove the item and it should be fine after it
+ clickAndWait(SHOWCART_PORTLET_TABLE_TR_PREFIX + "1000" +
SHOWCART_PORTLET_TABLE_TR_REMOVE_SUFFIX);
+ Assert.assertEquals(SHOWCART_PORTLET_CARD_ITEMS_PREFIX + "1 item.",
selenium.getText(SHOWCART_PORTLET_HEADER));
+ clickAndWait(CASHIER_PORTLET_SUBMIT);
+ // verify success
+ Assert.assertEquals(SHOWCART_PORTLET_EMPTY_CARD,
selenium.getText(SHOWCART_PORTLET_HEADER));
+ Assert.assertEquals(RECEIPT_PORTLET_SUCCESS + "Martin Carry.",
selenium.getText(RECEIPT_PORTLET_HEADER));
+ Assert.assertEquals("0", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1000" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ Assert.assertEquals("1", selenium.getText(CATALOG_PORTLET_TABLE_TR_PREFFIX +
"1001" + CATALOG_PORTLET_TABLE_TR_COUNT_SUFFIX));
+ }
+
+ /**
+ * Test if given currency String equals to given value. For example:
+ * Params: ("$39.99", 39.99) - true
+ * Params: ("¤ 281,79", 281.79) - true
+ * Params: ("¤ 281,79", 18.15) - false
+ *
+ * @param currencyString
+ * @param value
+ * @return
+ */
+ private boolean valueEqualsCurrency(String currencyString, double value) {
+ String s = currencyString.replace(',', '.');
+ for (int i=0 ; i<s.length(); i++) {
+ if (("0".compareTo(currencyString) < -1) &&
((s.compareTo("9") <= 1) || (s.charAt(0) == '9'))) {
+ double d = Double.parseDouble(s);
+ return d == value;
+ }
+ else {
+ s = s.substring(1);
+ }
+ }
+ return false;
+ }
+
+}