[seam-commits] Seam SVN: r12050 - branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/selenium.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri Feb 12 08:44:39 EST 2010


Author: kpiwko at redhat.com
Date: 2010-02-12 08:44:38 -0500 (Fri, 12 Feb 2010)
New Revision: 12050

Modified:
   branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/selenium/WebServiceTestPageTest.java
Log:
JBQA-2983, using AJAX waits for webservices

Modified: branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/selenium/WebServiceTestPageTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/selenium/WebServiceTestPageTest.java	2010-02-12 13:43:38 UTC (rev 12049)
+++ branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/selenium/WebServiceTestPageTest.java	2010-02-12 13:44:38 UTC (rev 12050)
@@ -18,38 +18,33 @@
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */ 
+ */
 package org.jboss.seam.example.seambay.test.selenium;
 
-import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
-import org.testng.annotations.BeforeMethod;
+import static org.testng.AssertJUnit.assertTrue;
+
+import org.jboss.seam.example.common.test.selenium.SeamSelenium;
 import org.testng.annotations.Test;
 
 import com.thoughtworks.selenium.Wait;
 
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import com.thoughtworks.selenium.Wait;
-
 /**
- * This class tests a functionality of web service test page available directly 
+ * This class tests a functionality of web service test page available directly
  * from SeamBay home page
  * 
  * @author Martin Gencur
+ * @author kpiwko
  * 
  */
 public class WebServiceTestPageTest extends SeleniumSeamBayTest
 {
-      
-   protected static final Long TIMEOUT = 35000L; //35 seconds   
    protected static final String HERE_LINK = "xpath=//a[contains(text(),\"here\")]";
-   protected static final String SERVICE_PAGE_HEADING= "seamBay Web Services - Test Page"; 
+   protected static final String SERVICE_PAGE_HEADING = "seamBay Web Services - Test Page";
 
    protected static final String INVOKE_SERVICE_BUTTON = "xpath=//button[contains(@onclick,\"sendRequest\")]";
    protected static final String REQUEST_AREA = "id=serviceRequest";
    protected static final String RESPONSE_AREA = "id=serviceResponse";
-   
+
    protected static final String LOGIN_LINK = "xpath=//a[contains(text(),\"Login\")]";
    protected static final String LIST_CATEGORIES_LINK = "xpath=//a[contains(text(),\"List Categories\")]";
    protected static final String CREATE_NEW_AUCTION_LINK = "xpath=//a[contains(text(),\"Create new auction\")]";
@@ -60,75 +55,110 @@
    protected static final String CONFIRM_AUCTION_LINK = "xpath=//a[contains(text(),\"Confirm auction\")]";
    protected static final String FIND_AUCTIONS_LINK = "xpath=//a[contains(text(),\"Find Auctions\")]";
    protected static final String LOGOUT_LINK = "xpath=//a[contains(text(),\"Logout\")]";
-   
-   /*login parameters*/
+
+   /* login parameters */
    protected static final String LOGIN_INPUT_USERNAME = "id=username";
    protected static final String LOGIN_INPUT_PASSWORD = "id=password";
-   
-   /*create new auction parameters*/
+
+   /* create new auction parameters */
    protected static final String AUCTION_TITLE = "id=title";
    protected static final String AUCTION_DESCRIPTION = "id=description";
    protected static final String AUCTION_CATEGORY_ID = "id=categoryId";
-   
-   /*parameters for other tests*/
+
+   /* parameters for other tests */
    protected static final String SEARCH_TERM = "id=searchTerm";
    protected static final String AUCTION_DURATION = "id=duration";
    protected static final String STARTING_PRICE = "id=price";
+
+   /**
+    * Modifies AJAX waits to match behavior of asynchronous services
+    * 
+    * @return Modified SeamSelenium browser
+    */
+   @Override
+   public SeamSelenium startBrowser()
+   {
+      SeamSelenium newBrowser = new SeamSelenium(HOST, PORT, BROWSER, BROWSER_URL)
+      {
+         /**
+          * Wait until service says it is executing a request
+          */
+         @Override
+         public void waitForAJAXUpdate(String timeout)
+         {
+            waitForCondition("selenium.browserbot.getCurrentWindow().selectedService.active===false", timeout);
+         };
          
+         /**
+          * Check typed result in the request field
+          */
+         @Override
+         public void type(String locator, String value)
+         {            
+            super.type(locator, value);
+            waitForCondition("var elem = selenium.browserbot.getCurrentWindow().document.getElementById('serviceRequest'); elem.value.indexOf('"+value+"')!=-1;", TIMEOUT);
+         }
+      };
+      newBrowser.start();
+      newBrowser.allowNativeXpath("false");
+      newBrowser.setSpeed(SPEED);
+      newBrowser.setTimeout(TIMEOUT);
+      return newBrowser;
+   }
+
    @Test
-   public void simplePageContentTest(){      
+   public void simplePageContentTest()
+   {
       browser.clickAndWait(HERE_LINK);
       waitForElementPresent(RESPONSE_AREA, TIMEOUT);
-      assertTrue("Page should contain service page heading",browser.isTextPresent(SERVICE_PAGE_HEADING));
+      assertTrue("Page should contain service page heading", browser.isTextPresent(SERVICE_PAGE_HEADING));
    }
-   
-   @Test(dependsOnMethods={"simplePageContentTest"})
-   public void loginTest(){      
-      loginService();             
+
+   @Test(dependsOnMethods = { "simplePageContentTest" })
+   public void loginTest()
+   {
+      loginService();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain \"true\"", x.contains(getProperty("LOGIN_RIGHT_RESPONSE")));  
-   }   
-   
-   public void loginService(){
+      assertTrue("Response area should contain \"true\"", x.contains(getProperty("LOGIN_RIGHT_RESPONSE")));
+   }
+
+   public void loginService()
+   {
       String username = "demo";
-      String password = "demo";      
+      String password = "demo";
       browser.clickAndWait(HERE_LINK);
       browser.click(LOGIN_LINK);
       waitForElementPresent(LOGIN_INPUT_PASSWORD, TIMEOUT);
       browser.type(LOGIN_INPUT_USERNAME, username);
-      browser.type(LOGIN_INPUT_PASSWORD, password);      
-      try
-      {
-         Thread.sleep(TIMEOUT/2);
-      }
-      catch (InterruptedException e)
-      {
-      }      
+      browser.type(LOGIN_INPUT_PASSWORD, password);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
    }
-   
-   @Test(dependsOnMethods={"loginTest"})
-   public void listCategoriesTest(){      
-      loginService();      
+
+   @Test(dependsOnMethods = { "loginTest" })
+   public void listCategoriesTest()
+   {
+      loginService();
       waitForElementPresent(LIST_CATEGORIES_LINK, TIMEOUT);
       browser.click(LIST_CATEGORIES_LINK);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain a list of categories.", x.contains(getProperty("LIST_CATEGORIES_RESPONSE")));      
-   }  
-   
-   @Test(dependsOnMethods={"loginTest"})
-   public void createNewAuctionTest(){
-      loginService();      
-      createNewAuctionService();      
+      assertTrue("Response area should contain a list of categories.", x.contains(getProperty("LIST_CATEGORIES_RESPONSE")));
+   }
+
+   @Test(dependsOnMethods = { "loginTest" })
+   public void createNewAuctionTest()
+   {
+      loginService();
+      createNewAuctionService();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain information about creating the auction.", x.contains(getProperty("CREATE_NEW_AUCTION_RESPONSE")));            
-   }  
-   
-   public void createNewAuctionService(){
+      assertTrue("Response area should contain information about creating the auction.", x.contains(getProperty("CREATE_NEW_AUCTION_RESPONSE")));
+   }
+
+   public void createNewAuctionService()
+   {
       String title = "Animals";
       String description = "You can buy an animal here";
       String categoryId = "6";
@@ -139,36 +169,38 @@
       waitForElementPresent(AUCTION_CATEGORY_ID, TIMEOUT);
       browser.type(AUCTION_TITLE, title);
       browser.type(AUCTION_DESCRIPTION, description);
-      browser.type(AUCTION_CATEGORY_ID, categoryId);      
+      browser.type(AUCTION_CATEGORY_ID, categoryId);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);      
+      browser.waitForAJAXUpdate();
    }
-   
-   @Test(dependsOnMethods={"loginTest","createNewAuctionTest"})
-   public void findAuctionsTest(){
-      String searchTerm = "Animals";      
-      loginService();      
-      createNewAuctionService();   
+
+   @Test(dependsOnMethods = { "loginTest", "createNewAuctionTest" })
+   public void findAuctionsTest()
+   {
+      String searchTerm = "Animals";
+      loginService();
+      createNewAuctionService();
       confirmAuctionService();
       waitForElementPresent(FIND_AUCTIONS_LINK, TIMEOUT);
       browser.click(FIND_AUCTIONS_LINK);
-      waitForElementPresent(SEARCH_TERM, TIMEOUT);     
+      waitForElementPresent(SEARCH_TERM, TIMEOUT);
       browser.type(SEARCH_TERM, searchTerm);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain information about finding auction.", x.contains(getProperty("FIND_AUCTIONS_RESPONSE")));      
-   }  
-   
-   @Test(dependsOnMethods={"loginTest","createNewAuctionTest"})
-   public void updateAuctionTest(){
+      assertTrue("Response area should contain information about finding auction.", x.contains(getProperty("FIND_AUCTIONS_RESPONSE")));
+   }
+
+   @Test(dependsOnMethods = { "loginTest", "createNewAuctionTest" })
+   public void updateAuctionTest()
+   {
       String title = "Animals";
       String description = "Another description";
-      String categoryId = "5";          
-      loginService();      
-      createNewAuctionService();      
+      String categoryId = "5";
+      loginService();
+      createNewAuctionService();
       waitForElementPresent(UPDATE_AUCTION_DETAILS_LINK, TIMEOUT);
       browser.click(UPDATE_AUCTION_DETAILS_LINK);
       waitForElementPresent(AUCTION_TITLE, TIMEOUT);
@@ -176,89 +208,96 @@
       waitForElementPresent(AUCTION_CATEGORY_ID, TIMEOUT);
       browser.type(AUCTION_TITLE, title);
       browser.type(AUCTION_DESCRIPTION, description);
-      browser.type(AUCTION_CATEGORY_ID, categoryId);      
+      browser.type(AUCTION_CATEGORY_ID, categoryId);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain information about updating the auction.", x.contains(getProperty("UPDATE_AUCTION_RESPONSE")));      
-   } 
-   
-   @Test(dependsOnMethods={"loginTest","createNewAuctionTest"})
-   public void setAuctionDurationTest(){
-      String duration = "20";            
-      loginService();      
-      createNewAuctionService();      
+      assertTrue("Response area should contain information about updating the auction.", x.contains(getProperty("UPDATE_AUCTION_RESPONSE")));
+   }
+
+   @Test(dependsOnMethods = { "loginTest", "createNewAuctionTest" })
+   public void setAuctionDurationTest()
+   {
+      String duration = "20";
+      loginService();
+      createNewAuctionService();
       waitForElementPresent(SET_AUCTION_DURATION_LINK, TIMEOUT);
       browser.click(SET_AUCTION_DURATION_LINK);
-      waitForElementPresent(AUCTION_DURATION, TIMEOUT);     
+      waitForElementPresent(AUCTION_DURATION, TIMEOUT);
       browser.type(AUCTION_DURATION, duration);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain information about setting duration.", x.contains(getProperty("SET_DURATION_RESPONSE")));      
-   } 
-   
-   @Test(dependsOnMethods={"loginTest","createNewAuctionTest"})
-   public void setStartingPriceTest(){
-      String price = "1000";            
-      loginService();      
-      createNewAuctionService();      
+      assertTrue("Response area should contain information about setting duration.", x.contains(getProperty("SET_DURATION_RESPONSE")));
+   }
+
+   @Test(dependsOnMethods = { "loginTest", "createNewAuctionTest" })
+   public void setStartingPriceTest()
+   {
+      String price = "1000";
+      loginService();
+      createNewAuctionService();
       waitForElementPresent(SET_STARTING_PRICE_LINK, TIMEOUT);
       browser.click(SET_STARTING_PRICE_LINK);
-      waitForElementPresent(STARTING_PRICE, TIMEOUT);     
+      waitForElementPresent(STARTING_PRICE, TIMEOUT);
       browser.type(STARTING_PRICE, price);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain information about setting starting price.", x.contains(getProperty("SET_STARTING_PRICE_RESPONSE")));      
-   } 
-   
-   @Test(dependsOnMethods={"loginTest","createNewAuctionTest"})
-   public void getAuctionDetailsTest(){            
-      loginService();      
-      createNewAuctionService();      
+      assertTrue("Response area should contain information about setting starting price.", x.contains(getProperty("SET_STARTING_PRICE_RESPONSE")));
+   }
+
+   @Test(dependsOnMethods = { "loginTest", "createNewAuctionTest" })
+   public void getAuctionDetailsTest()
+   {
+      loginService();
+      createNewAuctionService();
       waitForElementPresent(GET_AUCTION_DETAILS_LINK, TIMEOUT);
       browser.click(GET_AUCTION_DETAILS_LINK);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain auction details.", x.contains(getProperty("AUCTION_DETAILS_PRICE_RESPONSE")));      
-   } 
-   
-   @Test(dependsOnMethods={"loginTest"})
-   public void logOutTest(){            
-      loginService();      
+      assertTrue("Response area should contain auction details.", x.contains(getProperty("AUCTION_DETAILS_PRICE_RESPONSE")));
+   }
+
+   @Test(dependsOnMethods = { "loginTest" })
+   public void logOutTest()
+   {
+      loginService();
       waitForElementPresent(LOGOUT_LINK, TIMEOUT);
       browser.click(LOGOUT_LINK);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain logout confirmation.", x.contains(getProperty("LOGOUT_RESPONSE")));      
-   }    
-   
-   @Test(dependsOnMethods={"loginTest","createNewAuctionTest"})
-   public void confirmAuctionTest(){            
-      loginService();      
-      createNewAuctionService();      
+      assertTrue("Response area should contain logout confirmation.", x.contains(getProperty("LOGOUT_RESPONSE")));
+   }
+
+   @Test(dependsOnMethods = { "loginTest", "createNewAuctionTest" })
+   public void confirmAuctionTest()
+   {
+      loginService();
+      createNewAuctionService();
       confirmAuctionService();
       String x = browser.getValue(RESPONSE_AREA);
-      assertTrue("Response area should contain information about confirmation.", x.contains(getProperty("CONFIRMATION_RESPONSE")));      
-   }  
-   
-   public void confirmAuctionService(){
+      assertTrue("Response area should contain information about confirmation.", x.contains(getProperty("CONFIRMATION_RESPONSE")));
+   }
+
+   public void confirmAuctionService()
+   {
       waitForElementPresent(CONFIRM_AUCTION_LINK, TIMEOUT);
       browser.click(CONFIRM_AUCTION_LINK);
       waitForElementPresent(INVOKE_SERVICE_BUTTON, TIMEOUT);
       browser.click(INVOKE_SERVICE_BUTTON);
-      waitForElementContent(RESPONSE_AREA, TIMEOUT);
+      browser.waitForAJAXUpdate();
    }
-   
-   public void waitForElementPresent(final String locator, Long timeout){
+
+   protected void waitForElementPresent(final String locator, String timeout)
+   {
       new Wait()
       {
          @Override
@@ -266,18 +305,7 @@
          {
             return browser.isElementPresent(locator);
          }
-      }.wait("Timeout while waiting for element "+ locator +" present.", timeout);
-   } //waitForElementPresent
-   
-   public void waitForElementContent(final String locator, Long timeout){
-      new Wait()
-      {
-         @Override
-         public boolean until()
-         {
-            return (browser.getValue(locator).length() != 0);
-         }
-      }.wait("Timeout while waiting for element content. Element: " + locator+ ", " + "Content length: " 
-            + browser.getValue(locator).length(), timeout);
-   } //waitForElementContent    
+      }.wait("Timeout while waiting for element " + locator + " present.", Long.parseLong(timeout));
+   } // waitForElementPresent
+
 }



More information about the seam-commits mailing list