[seam-commits] Seam SVN: r12300 - in branches/community/Seam_2_2/src/test/ftest: examples/remoting/chatroom and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri Mar 26 03:19:34 EDT 2010


Author: mgencur at redhat.com
Date: 2010-03-26 03:19:34 -0400 (Fri, 26 Mar 2010)
New Revision: 12300

Added:
   branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/jboss5-webdriver.xml
   branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/src/org/jboss/seam/example/remoting/chatroom/test/webdriver/
   branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/src/org/jboss/seam/example/remoting/chatroom/test/webdriver/WebDriverChatroomTest.java
Removed:
   branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/jboss5.xml
Modified:
   branches/community/Seam_2_2/src/test/ftest/build.xml
   branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverTest.java
   branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebElement.java
   branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/DelegatedWebElement.java
Log:
JBSEAM-4610 remoting-chatroom example rewritten to webdriver

Modified: branches/community/Seam_2_2/src/test/ftest/build.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/build.xml	2010-03-26 06:42:26 UTC (rev 12299)
+++ branches/community/Seam_2_2/src/test/ftest/build.xml	2010-03-26 07:19:34 UTC (rev 12300)
@@ -76,7 +76,7 @@
 		<testexample name="openid" />
 		<testexample name="quartz" />
 		<testexample name="registration" />
-		<testexample name="remoting/chatroom" />
+		<testexample name="remoting/chatroom" webdriver="true"/>
 		<testexample name="rss" />
 		<testexample name="seambay" webdriver="true"/>
 		<testexample name="seamdiscs" />
@@ -120,7 +120,7 @@
 		<testexample name="openid" />
 		<testexample name="quartz" />
 		<testexample name="registration" />
-		<testexample name="remoting/chatroom" />
+		<testexample name="remoting/chatroom" webdriver="true"/>
 		<testexample name="remoting/helloworld" />
 		<testexample name="remoting/gwt" />
 		<testexample name="rss" /> 

Added: branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/jboss5-webdriver.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/jboss5-webdriver.xml	                        (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/jboss5-webdriver.xml	2010-03-26 07:19:34 UTC (rev 12300)
@@ -0,0 +1,25 @@
+
+	<!--
+		JBoss, Home of Professional Open Source Copyright 2008, Red Hat
+		Middleware LLC, and individual contributors by the @authors tag. See
+		the copyright.txt in the distribution for a full listing of individual
+		contributors. This is free software; you can redistribute it and/or
+		modify it under the terms of the GNU Lesser General Public License as
+		published by the Free Software Foundation; either version 2.1 of the
+		License, or (at your option) any later version. This software is
+		distributed in the hope that it will be useful, but WITHOUT ANY
+		WARRANTY; without even the implied warranty of MERCHANTABILITY or
+		FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+		License for more details. You should have received a copy of the GNU
+		Lesser General Public 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.
+	--> 
+<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
+<suite name="Web Driver Chatroom example" verbose="2" parallel="false">
+	<test name="chatroom_jboss5_webdriver">
+		<packages>
+			<package name="org.jboss.seam.example.remoting.chatroom.test.webdriver" />
+		</packages>
+	</test>
+</suite>

Deleted: branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/jboss5.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/jboss5.xml	2010-03-26 06:42:26 UTC (rev 12299)
+++ branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/jboss5.xml	2010-03-26 07:19:34 UTC (rev 12300)
@@ -1,27 +0,0 @@
-
-	<!--
-		JBoss, Home of Professional Open Source Copyright 2008, Red Hat
-		Middleware LLC, and individual contributors by the @authors tag. See
-		the copyright.txt in the distribution for a full listing of individual
-		contributors. This is free software; you can redistribute it and/or
-		modify it under the terms of the GNU Lesser General Public License as
-		published by the Free Software Foundation; either version 2.1 of the
-		License, or (at your option) any later version. This software is
-		distributed in the hope that it will be useful, but WITHOUT ANY
-		WARRANTY; without even the implied warranty of MERCHANTABILITY or
-		FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
-		License for more details. You should have received a copy of the GNU
-		Lesser General Public 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.
-	--> 
-<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
-<suite name="Chatroom example" verbose="2" parallel="false">
-	<test name="chatroom_jboss5">
-		<parameter name="PROPERTY_FILE" value="" />
-		<classes>
-			<class
-				name="org.jboss.seam.example.remoting.chatroom.test.selenium.SeleniumChatroomTest" />
-		</classes>
-	</test>
-</suite>

Added: branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/src/org/jboss/seam/example/remoting/chatroom/test/webdriver/WebDriverChatroomTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/src/org/jboss/seam/example/remoting/chatroom/test/webdriver/WebDriverChatroomTest.java	                        (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/examples/remoting/chatroom/src/org/jboss/seam/example/remoting/chatroom/test/webdriver/WebDriverChatroomTest.java	2010-03-26 07:19:34 UTC (rev 12300)
@@ -0,0 +1,230 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * 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.remoting.chatroom.test.webdriver;
+
+
+//import static junit.framework.Assert.assertTrue;
+
+import org.jboss.seam.example.common.test.webdriver.AjaxWebDriverFactory;
+import org.jboss.seam.example.common.test.webdriver.AjaxWebDriverTest;
+import org.jboss.seam.example.common.test.webdriver.AjaxWebElement;
+import org.jboss.seam.example.common.test.webdriver.AjaxWebDriver;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.NoSuchElementException;
+import org.testng.annotations.Test;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.assertNull;
+import static org.testng.Assert.fail;
+
+/**
+ * This class tests functionality of remoting/chatroom example. 
+ * The test opens two browsers and tests communication between users.
+ * 
+ * @author Martin Gencur
+ * 
+ */
+public class WebDriverChatroomTest extends AjaxWebDriverTest
+{
+   public static int timeout = 16000;
+   
+   public static final String NAME1 = "Martin";
+   public static final String NAME2 = "Jozef";
+   public static final String MESSAGE_FROM_MARTIN = "Hello";
+   public static final String MESSAGE_FROM_JOZEF = "Good evening";
+   public static final String HOME_PAGE = "/chatroom.seam";
+   
+   public static final String HOME_PAGE_TITLE = "Chat Room Example";
+   public static final By NAME_INPUT = By.id("username");
+   public static final By CONNECT_BUTTON = By.id("btnConnect");
+   public static final By DISCONNECT_BUTTON = By.id("btnDisconnect");
+   public static final By CONNECT_BUTTON_DISABLED = By.xpath("//input[@id='btnConnect'][@disabled]");
+   public static final By DISCONNECT_BUTTON_DISABLED = By.xpath("//input[@id='btnDisconnect'][@disabled]");
+   public static final By MESSAGE_INPUT = By.id("messageText");
+   public static final By CHAT_AREA = By.id("channelDisplay");
+   public static final By MARTIN_CONNECTED = By.xpath("//div[@id='channelDisplay']/span[contains(text(),'Martin connected.')]");
+   public static final By MARTIN_LISTED = By.xpath("//div/select[@id='userList']/option[contains(text(),'Martin')]");
+   public static final By JOZEF_CONNECTED = By.xpath("//div[@id='channelDisplay']/span[contains(text(),'Jozef connected.')]");
+   public static final By JOZEF_LISTED = By.xpath("//div/select[@id='userList']/option[contains(text(),'Jozef')]");
+   public static final By JOZEF_DISCONNECTED = By.xpath("//div[@id='channelDisplay']/span[contains(text(),'Jozef disconnected.')]");
+   public static final By MARTIN_GT = By.xpath("//div[@id='channelDisplay']/span[contains(text(),'Martin>')]");
+   public static final By HELLO = By.xpath("//div[@id='channelDisplay']/text()[contains(.,'"+ MESSAGE_FROM_MARTIN +"')]");   
+   public static final By JOZEF_GT = By.xpath("//div[@id='channelDisplay']/span[contains(text(),'Jozef>')]");
+   public static final By GOOD_MORNING = By.xpath("//div[@id='channelDisplay']/text()[contains(.,'" + MESSAGE_FROM_JOZEF + "')]");
+         
+   protected AjaxWebDriver driver2;
+   
+   @BeforeMethod
+   public void setUp() 
+   {
+      startSecondBrowser();      
+      driver.get(serverURL + contextPath + HOME_PAGE);
+      driver2.get(serverURL + contextPath + HOME_PAGE);
+   }
+   
+   @AfterMethod
+   public void tearDown() 
+   {
+       stopSecondBrowser();
+   }
+   
+   @Test
+   public void homePageLoadTest() 
+   {
+      assertTrue("Unexpected page title.", driver.getTitle().contains(HOME_PAGE_TITLE));
+   }
+   
+   @Test(dependsOnMethods={"homePageLoadTest"})
+   public void connectAndChatTest()
+   {
+      /*connect user to chat*/
+      connect();      
+      /*verify that user is connected and is seen by other users*/
+      verifyConnecting();      
+      /*exchange several messages*/
+      chat();      
+      /*disconnect user from chat*/
+      disconnect();      
+      /*verify that user is disconnected and is not in a list of users anymore*/
+      verifyDisconnecting();
+   }
+      
+   public void connect()
+   {
+      driver.findElement(NAME_INPUT).clearAndSendKeys(NAME1);
+      driver.setWaitTime(timeout);
+      driver.findElement(CONNECT_BUTTON).clickAndWait();
+   }
+   
+   public void verifyConnecting()
+   {
+      driver.findElement(MARTIN_LISTED);      
+      driver2.setWaitTime(timeout);
+      driver2.findElement(NAME_INPUT).clearAndSendKeys(NAME2);
+      driver2.findElement(CONNECT_BUTTON).clickAndWait();
+      driver2.findElement(JOZEF_LISTED);
+      driver2.findElement(MARTIN_LISTED);
+      driver.findElement(JOZEF_CONNECTED);
+      driver.findElement(JOZEF_LISTED);
+   }
+   
+   public void disconnect()
+   {
+      driver2.findElement(DISCONNECT_BUTTON).clickAndWait();
+   }
+   
+   public void verifyDisconnecting()
+   {
+      
+      AjaxWebElement el = null;
+      try
+      {
+         el = driver2.findElement(JOZEF_LISTED);
+      }
+      catch (NoSuchElementException e)
+      {         
+      }    
+      assertNull("Jozef should not be listed in second browser window", el);
+
+      driver2.findElement(DISCONNECT_BUTTON_DISABLED);
+      driver.findElement(JOZEF_DISCONNECTED);
+      
+      AjaxWebElement el2 = null;
+      try
+      {
+         el2 = driver.findElement(JOZEF_LISTED);
+      }
+      catch (NoSuchElementException e)
+      {         
+      } 
+      assertNull("Jozef should not be listed in first browser window", el2);
+      
+      driver.findElement(DISCONNECT_BUTTON).clickAndWait();
+
+      AjaxWebElement el3 = null;
+      try
+      {
+         el3 = driver.findElement(MARTIN_LISTED);
+      }
+      catch (NoSuchElementException e)
+      {         
+      }
+      assertNull("Martin should not be listed in first browser window", el3);
+
+      driver.findElement(DISCONNECT_BUTTON_DISABLED);
+   }
+   
+   public void chat()
+   {
+      /*first user is sending a message*/
+      driver.findElement(MESSAGE_INPUT).clearAndSendKeys(MESSAGE_FROM_MARTIN);
+      driver.findElement(MESSAGE_INPUT).sendKeys(Keys.RETURN);
+
+      try 
+      {
+         Thread.sleep(timeout);
+      } catch (InterruptedException e) 
+      {
+      }
+      
+      driver.findElement(MARTIN_GT);
+      driver.findElement(HELLO);
+      driver2.findElement(MARTIN_GT);
+      driver2.findElement(HELLO);   
+      driver2.findElement(MESSAGE_INPUT).clearAndSendKeys(MESSAGE_FROM_JOZEF, Keys.RETURN);
+      
+      try 
+      {
+         Thread.sleep(timeout);
+      } catch (InterruptedException e) 
+      {
+      }
+      
+      driver2.findElement(JOZEF_GT);
+      driver2.findElement(GOOD_MORNING);
+      driver.findElement(JOZEF_GT);
+      driver.findElement(GOOD_MORNING);
+   }
+      
+   public void startSecondBrowser()
+   {
+      try
+      {
+         this.driver2 = AjaxWebDriverFactory.getDriver(this.browser);
+      }
+      catch (IllegalArgumentException e)
+      {
+         fail("Unable to instantiate browser of type: " + this.browser + ", available browsers are: " + AjaxWebDriverFactory.availableBrowsers());
+      }
+      catch (NullPointerException e)
+      {
+         fail("Unable to instantiate browser of type: " + this.browser + ", available browsers are: " + AjaxWebDriverFactory.availableBrowsers());
+      }
+   }
+   
+   public void stopSecondBrowser()
+   {
+      driver2.close();
+   }
+}

Modified: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverTest.java	2010-03-26 06:42:26 UTC (rev 12299)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverTest.java	2010-03-26 07:19:34 UTC (rev 12300)
@@ -18,6 +18,7 @@
    protected AjaxWebDriver driver;
    protected String serverURL;
    protected String contextPath;
+   protected String browser;
 
    @BeforeMethod
    @Parameters(value = {
@@ -40,6 +41,7 @@
 
       this.serverURL = serverURL;
       this.contextPath = contextPath;
+      this.browser = browser;
    }
 
    @AfterMethod

Modified: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebElement.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebElement.java	2010-03-26 06:42:26 UTC (rev 12299)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebElement.java	2010-03-26 07:19:34 UTC (rev 12300)
@@ -20,6 +20,8 @@
    public void setWaitTime(int millis);
 
    public void clickAndWait();
+   
+   public void clickAndWait(int millis);
 
    public void clearAndSendKeys(CharSequence... keysToSend);
 }

Modified: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/DelegatedWebElement.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/DelegatedWebElement.java	2010-03-26 06:42:26 UTC (rev 12299)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/DelegatedWebElement.java	2010-03-26 07:19:34 UTC (rev 12300)
@@ -51,7 +51,15 @@
 		} catch (InterruptedException e) {
 		}
 	}
-
+	
+	public void clickAndWait(int millis) {
+	   element.click();
+	   try {
+	      Thread.sleep(millis);
+	   } catch (InterruptedException e) {
+	   }
+	}
+	
 	//@Override
 	public AjaxWebElement findElement(By by) {
 		return new DelegatedWebElement(element.findElement(by));



More information about the seam-commits mailing list