[seam-commits] Seam SVN: r10073 - trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Feb 23 04:21:40 EST 2009


Author: jharting
Date: 2009-02-23 04:21:40 -0500 (Mon, 23 Feb 2009)
New Revision: 10073

Modified:
   trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium/SearchTest.java
   trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium/ShoppingCartTest.java
Log:
JBSEAM-3690 dvdstore test browser-compatibility fix

Modified: trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium/SearchTest.java
===================================================================
--- trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium/SearchTest.java	2009-02-22 21:37:46 UTC (rev 10072)
+++ trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium/SearchTest.java	2009-02-23 09:21:40 UTC (rev 10073)
@@ -58,20 +58,18 @@
     /**
      * This test does simple search in two windows verifying they do not affect
      * each other
+    * @throws InterruptedException 
      */
     @Test(dependsOnMethods = { "testSearch" }, dependsOnGroups = { "login.basic" })
-    public void testMultipleWindowSearch() {
+    public void testMultipleWindowSearch() throws InterruptedException {
         String searchString1 = "Forrest Gump";
         String searchString2 = "The Shawshank Redemption";
 
         browser.openWindow(CONTEXT_PATH + getProperty("HOME_PAGE"), "1");
         browser.selectWindow("1");
-        browser.waitForPageToLoad(TIMEOUT);
+        Thread.sleep(10000); // ugly but turned out to be the most browser-compatible solution
         assertTrue("User should be logged in by now.", isLoggedIn(browser));
-        // search for dvd in first window
-        browser.openWindow(CONTEXT_PATH + getProperty("HOME_PAGE"), "2");
-        browser.selectWindow("2");
-        browser.waitForPageToLoad(TIMEOUT);
+        browser.selectWindow(null); // select main window
         assertTrue("User should be logged in by now.", isLoggedIn(browser));
         browser.click(getProperty("SHOP"));
         browser.waitForPageToLoad(TIMEOUT);
@@ -91,7 +89,7 @@
         assertEquals("Unexpected search result in second window.",
                 searchString2, browser
                         .getText(getProperty("SEARCH_RESULT_FIRST_ROW_LINK")));
-        browser.selectWindow("2");
+        browser.selectWindow(null);
         browser.refresh();
         browser.waitForPageToLoad(TIMEOUT);
         assertEquals("Unexpected search result in first window after refresh.",

Modified: trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium/ShoppingCartTest.java
===================================================================
--- trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium/ShoppingCartTest.java	2009-02-22 21:37:46 UTC (rev 10072)
+++ trunk/src/test/ftest/examples/dvdstore/src/org/jboss/seam/example/dvd/test/selenium/ShoppingCartTest.java	2009-02-23 09:21:40 UTC (rev 10073)
@@ -27,9 +27,6 @@
 import java.text.MessageFormat;
 import java.text.NumberFormat;
 import java.text.ParseException;
-import java.util.Currency;
-import java.util.Locale;
-
 import org.testng.annotations.Test;
 
 /**
@@ -40,6 +37,8 @@
  * 
  */
 public class ShoppingCartTest extends SeleniumDvdTest {
+   
+    private NumberFormat nf = NumberFormat.getNumberInstance();
 
     @Test(dependsOnGroups = { "search" })
     public void simpleCartTest() {
@@ -60,8 +59,6 @@
     @Test(dependsOnMethods = { "simpleCartTest" })
     public void testCartCostCalculation() throws ParseException {
         String[] dvds = new String[] { "Top Gun", "Pulp Fiction", "Top Gun" };
-        NumberFormat nf = NumberFormat.getCurrencyInstance();
-        nf.setCurrency(Currency.getInstance(Locale.US));
         BigDecimal expectedSum = BigDecimal.ZERO;
         for (String dvd : dvds) {
             addDVDToCart(dvd);
@@ -72,18 +69,14 @@
                 .intValue();
         assertNotSame("Cart should not be empty.", 0, items);
         for (int i = 0; i < items; i++) {
-            BigDecimal quantity = BigDecimal.valueOf(Double.parseDouble(browser
-                    .getValue(MessageFormat.format(
-                            getProperty("CART_TABLE_QUANTITY_BY_ID"), i))));
-            BigDecimal price = BigDecimal.valueOf(nf.parse(
-                    browser.getText(MessageFormat.format(
-                            getProperty("CART_TABLE_PRICE_BY_ID"), i)))
-                    .doubleValue());
+            BigDecimal quantity = parseBalance(browser.getValue(MessageFormat.format(
+                            getProperty("CART_TABLE_QUANTITY_BY_ID"), i)));
+            BigDecimal price = parseBalance(browser.getText(MessageFormat.format(
+                            getProperty("CART_TABLE_PRICE_BY_ID"), i)));
             BigDecimal priceForCurrentRow = price.multiply(quantity);
             expectedSum = expectedSum.add(priceForCurrentRow);
         }
-        BigDecimal actualSum = BigDecimal.valueOf((nf.parse(browser
-                .getText(getProperty("CART_SUBTOTAL"))).doubleValue()));
+        BigDecimal actualSum = parseBalance(browser.getText(getProperty("CART_SUBTOTAL")));
         assertEquals("Price sum in cart is incorrect.", 0, expectedSum
                 .compareTo(actualSum));
     }
@@ -144,4 +137,9 @@
         browser.click(getProperty("SEARCH_RESULT_UPDATE_BUTTON"));
         browser.waitForPageToLoad(TIMEOUT);
     }
+    
+    private BigDecimal parseBalance(String text) throws ParseException {
+       String number = text.replaceAll("\\$", "").trim();
+       return BigDecimal.valueOf(nf.parse(number).doubleValue());
+    }
 }




More information about the seam-commits mailing list