[seam-commits] Seam SVN: r12261 - in branches/community/Seam_2_2/src/test/ftest: examples and 6 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Mar 24 08:36:37 EDT 2010
Author: kpiwko at redhat.com
Date: 2010-03-24 08:36:35 -0400 (Wed, 24 Mar 2010)
New Revision: 12261
Added:
branches/community/Seam_2_2/src/test/ftest/examples/seambay/jboss5-webdriver.xml
branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/webdriver/
branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/webdriver/seambay/
branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/webdriver/seambay/WebServicesTest.java
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriver.java
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverFactory.java
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
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/FirefoxAjaxDriver.java
Modified:
branches/community/Seam_2_2/src/test/ftest/build.xml
branches/community/Seam_2_2/src/test/ftest/examples/build.xml
branches/community/Seam_2_2/src/test/ftest/examples/seambay/jboss5.xml
Log:
JBSEAM-4610, WebDriver infrastructure + SeamBay webservices test
Modified: branches/community/Seam_2_2/src/test/ftest/build.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/build.xml 2010-03-24 11:27:19 UTC (rev 12260)
+++ branches/community/Seam_2_2/src/test/ftest/build.xml 2010-03-24 12:36:35 UTC (rev 12261)
@@ -78,7 +78,7 @@
<testexample name="registration" />
<testexample name="remoting/chatroom" />
<testexample name="rss" />
- <testexample name="seambay" />
+ <testexample name="seambay" webdriver="true"/>
<testexample name="seamdiscs" />
<testexample name="seampay" />
<testexample name="seamspace" />
@@ -123,8 +123,8 @@
<testexample name="remoting/chatroom" />
<testexample name="remoting/helloworld" />
<testexample name="remoting/gwt" />
- <testexample name="rss" />
- <testexample name="seambay" />
+ <testexample name="rss" />
+ <testexample name="seambay" webdriver="true"/>
<testexample name="seampay" />
<testexample name="seamspace" />
<testexample name="spring" />
@@ -132,7 +132,7 @@
<testexample name="todo" />
<testexample name="ui" />
<testexample name="wicket" />
- <testexample name="wicket-runtime" />
+ <testexample name="wicket-runtime" />
<antcall target="stop.selenium.server" />
<antcall target="stop.container" />
</target>
@@ -146,7 +146,7 @@
<testexample name="messages" />
<testexample name="numberguess" />
<testexample name="registration" />
- <testexample name="seambay" />
+ <testexample name="seambay" webdriver="true"/>
<testexample name="seampay" />
<testexample name="todo" />
<testexample name="booking" />
@@ -195,7 +195,7 @@
<antcall target="start.selenium.server" />
<!-- Execute tests for a specific example-->
- <testexample name="${test}" />
+ <testexample name="${test}" webdriver="${webdriver}" />
<antcall target="stop.selenium.server" />
</target>
@@ -311,6 +311,7 @@
<macrodef name="testexample">
<attribute name="name" />
<attribute name="path" default="examples/@{name}" />
+ <attribute name="webdriver" default="false" />
<attribute name="message" default="Running functional tests on @{name} example" />
<sequential>
<groovy>
@@ -325,7 +326,7 @@
]]>
</groovy>
<echo>@{message}</echo>
- <callExample path="@{path}" target="test" />
+ <callExample path="@{path}" target="test" webdriver="@{webdriver}"/>
</sequential>
</macrodef>
@@ -350,10 +351,11 @@
<macrodef name="callExample">
<attribute name="path" />
<attribute name="target" />
+ <attribute name="webdriver" default="false"/>
<sequential>
<ant dir="@{path}" target="@{target}" inheritall="false">
- <property name="container" value="${container}">
- </property>
+ <property name="container" value="${container}" />
+ <property name="webdriver" value="@{webdriver}" />
</ant>
</sequential>
</macrodef>
Modified: branches/community/Seam_2_2/src/test/ftest/examples/build.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/build.xml 2010-03-24 11:27:19 UTC (rev 12260)
+++ branches/community/Seam_2_2/src/test/ftest/examples/build.xml 2010-03-24 12:36:35 UTC (rev 12261)
@@ -101,7 +101,7 @@
<!-- TODO we should compile this once to a common place not build for each example -->
<!-- TODO if needed we should allow examples to exclude/include src under
common dvd does not care about booking for example-->
- <target name="build.common" depends="copy.htmlunit, copy.selenium" description="Compiles the common selenium test code">
+ <target name="build.common" depends="copy.htmlunit, copy.selenium, copy.webdriver" description="Compiles the common selenium test code">
<mkdir dir="${classes.dir}" />
<javac srcdir="${common.src.dir}" destdir="${classes.dir}" classpathref="classpath.build" debug="true" />
<copy todir="${classes.dir}">
@@ -141,6 +141,27 @@
</testng>
</target>
+ <target name="webdriver.test" depends="webdriver.test.present, build, container.properties" description="Run Tests (WebDriver)" if="test.webdriver">
+ <taskdef resource="testngtasks" classpathref="classpath.test" />
+ <mkdir dir="${test.output.dir}" />
+ <echo message="${test.webdriver}" />
+ <!-- execute testng tests -->
+ <testng haltonfailure="false" outputdir="${test.output.dir}" classpathref="classpath.test">
+ <xmlfileset file="${container}-webdriver.xml" />
+ <sysproperty key="browser" value="${selenium.browser}" />
+ <sysproperty key="server.url" value="${selenium.browser.url}" />
+ <sysproperty key="context.path" value="${context.path}" />
+ </testng>
+ </target>
+
+ <target name="webdriver.test.present">
+ <condition property="test.webdriver">
+ <not>
+ <equals arg1="${webdriver}" arg2="false"/>
+ </not>
+ </condition>
+ </target>
+
<target name="simpletest" depends="build, container.properties" description="Run Tests" unless="cluster">
<!-- TODO all of these jboss commands must be optional with checks -->
<!-- TODO go get JBoss and extract -->
@@ -154,6 +175,7 @@
<!-- execute testng tests -->
<antcall target="selenium.test" />
+ <antcall target="webdriver.test"/>
<!-- undeploy the example -->
<antcall target="undeploy.example" />
@@ -356,4 +378,14 @@
<property name="copy.selenium.done" value="true" />
</target>
+ <target name="copy.webdriver" unless="copy.webdriver.done">
+ <copyInlineDependencies id="webdriver.driver" scope="compile" todir="${ftest.lib.dir}">
+ <dependency groupId="org.seleniumhq.webdriver" artifactId="webdriver-firefox" version="0.9.7376">
+ </dependency>
+ <dependency groupId="org.seleniumhq.webdriver" artifactId="webdriver-support" version="0.9.7376">
+ </dependency>
+ </copyInlineDependencies>
+ <property name="copy.webdriver.done" value="true" />
+ </target>
+
</project>
Added: branches/community/Seam_2_2/src/test/ftest/examples/seambay/jboss5-webdriver.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/seambay/jboss5-webdriver.xml (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/examples/seambay/jboss5-webdriver.xml 2010-03-24 12:36:35 UTC (rev 12261)
@@ -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 Seambay example" verbose="2" parallel="false">
+ <test name="seambay_jboss5_webdriver">
+ <packages>
+ <package name="org.jboss.seam.example.test.webdriver.seambay" />
+ </packages>
+ </test>
+</suite>
Modified: branches/community/Seam_2_2/src/test/ftest/examples/seambay/jboss5.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/seambay/jboss5.xml 2010-03-24 11:27:19 UTC (rev 12260)
+++ branches/community/Seam_2_2/src/test/ftest/examples/seambay/jboss5.xml 2010-03-24 12:36:35 UTC (rev 12261)
@@ -20,13 +20,14 @@
<test name="seambay_jboss5">
<parameter name="PROPERTY_FILE"
value="/org/jboss/seam/example/seambay/test/selenium/seambay.properties" />
- <classes>
+ <classes>
<class
name="org.jboss.seam.example.seambay.test.selenium.RegistrationTest" />
<class name="org.jboss.seam.example.seambay.test.selenium.SellTest" />
<class name="org.jboss.seam.example.seambay.test.selenium.SearchTest" />
- <class name="org.jboss.seam.example.seambay.test.selenium.BidTest" />
+ <class name="org.jboss.seam.example.seambay.test.selenium.BidTest" /> <!--
<class name="org.jboss.seam.example.seambay.test.selenium.WebServiceTestPageTest" />
+ -->
</classes>
</test>
</suite>
Added: branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/webdriver/seambay/WebServicesTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/webdriver/seambay/WebServicesTest.java (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/examples/seambay/src/org/jboss/seam/example/seambay/test/webdriver/seambay/WebServicesTest.java 2010-03-24 12:36:35 UTC (rev 12261)
@@ -0,0 +1,265 @@
+package org.jboss.seam.example.test.webdriver.seambay;
+
+import static junit.framework.Assert.assertTrue;
+
+import org.jboss.seam.example.common.test.webdriver.AjaxWebDriverTest;
+import org.jboss.seam.example.common.test.webdriver.AjaxWebElement;
+import org.openqa.selenium.By;
+import org.testng.annotations.Test;
+
+/**
+ * Tests Web Services of Seambay example. Uses WebDriver to test, browser is
+ * chosen according to parameter passed
+ *
+ * @author kpiwko
+ *
+ */
+public class WebServicesTest extends AjaxWebDriverTest
+{
+
+ protected static final By HERE_LINK = By.partialLinkText("here");
+ protected static final String SERVICE_PAGE_URL = "test.seam";
+
+ protected static final By INVOKE_SERVICE_BUTTON = By.xpath("//button[contains(@onclick,'sendRequest')]");
+ protected static final By REQUEST_AREA = By.id("serviceRequest");
+ protected static final By RESPONSE_AREA = By.id("serviceResponse");
+
+ protected static final By LOGIN_LINK = By.partialLinkText("Login");
+ protected static final By LIST_CATEGORIES_LINK = By.partialLinkText("List Categories");
+ protected static final By CREATE_NEW_AUCTION_LINK = By.partialLinkText("Create new auction");
+ protected static final By UPDATE_AUCTION_DETAILS_LINK = By.partialLinkText("Update auction details");
+ protected static final By SET_AUCTION_DURATION_LINK = By.partialLinkText("Set auction duration");
+ protected static final By SET_STARTING_PRICE_LINK = By.partialLinkText("Set starting price");
+ protected static final By GET_AUCTION_DETAILS_LINK = By.partialLinkText("Get the auction details");
+ protected static final By CONFIRM_AUCTION_LINK = By.partialLinkText("Confirm auction");
+ protected static final By FIND_AUCTIONS_LINK = By.partialLinkText("Find Auctions");
+ protected static final By LOGOUT_LINK = By.partialLinkText("Logout");
+
+ /* login parameters */
+ protected static final By LOGIN_INPUT_USERNAME = By.id("username");
+ protected static final By LOGIN_INPUT_PASSWORD = By.id("password");
+
+ /* create new auction parameters */
+ protected static final By AUCTION_TITLE = By.id("title");
+ protected static final By AUCTION_DESCRIPTION = By.id("description");
+ protected static final By AUCTION_CATEGORY_ID = By.id("categoryId");
+
+ /* parameters for other tests */
+ protected static final By SEARCH_TERM = By.id("searchTerm");
+ protected static final By AUCTION_DURATION = By.id("duration");
+ protected static final By STARTING_PRICE = By.id("price");
+
+ /* responses */
+ protected static final String LIST_CATEGORIES_RESPONSE = "<ns2:listCategoriesResponse xmlns:ns2=\"http://seambay.example.seam.jboss.org/\"><return><categoryId>1</categoryId><name>Antiques</name></return><return><categoryId>2</categoryId><name>Art</name></return><return><categoryId>3</categoryId><name>Books</name></return><return><categoryId>4</categoryId><name>Cameras and Photography</name></return><return><categoryId>5</categoryId><name>Cars and Boats</name></return><return><categoryId>6</categoryId><name>Cell Phones</name></return><return><categoryId>7</categoryId><name>Clothing and Shoes</name></return><return><categoryId>8</categoryId><name>Computers</name></return><return><categoryId>9</categoryId><name>Music</name></return><return><categoryId>10</categoryId><name>Electronics</name></return><return><categoryId>11</categoryId><name>Home and Garden</name></return><return><categoryId>12</categoryId><name>Musical Instruments</name></return><return><categoryId>13</catego!
ryId><name>Sporting goods</name></return><return><categoryId>14</categoryId><name>Toys</name></return><return><categoryId>15</categoryId><name>Video Games</name></return><return><categoryId>1001</categoryId><name>Furniture</name><parent><categoryId>1</categoryId><name>Antiques</name></parent></return><return><categoryId>1002</categoryId><name>Silverware</name><parent><categoryId>1</categoryId><name>Antiques</name></parent></return><return><categoryId>2001</categoryId><name>Paintings</name><parent><categoryId>2</categoryId><name>Art</name></parent></return><return><categoryId>2002</categoryId><name>Prints</name><parent><categoryId>2</categoryId><name>Art</name></parent></return><return><categoryId>2003</categoryId><name>Sculptures</name><parent><categoryId>2</categoryId><name>Art</name></parent></return><return><categoryId>3001</categoryId><name>Fiction</name><parent><categoryId>3</categoryId><name>Books</name></parent></return><return><categoryId>3002</categoryId><name>Non !
Fiction</name><parent><categoryId>3</categoryId><name>Books</n!
ame></pa
rent></return><return><categoryId>3003</categoryId><name>Comic Books</name><parent><categoryId>3</categoryId><name>Books</name></parent></return><return><categoryId>3004</categoryId><name>Children</name><parent><categoryId>3</categoryId><name>Books</name></parent></return><return><categoryId>4001</categoryId><name>Digital Cameras</name><parent><categoryId>4</categoryId><name>Cameras and Photography</name></parent></return><return><categoryId>4002</categoryId><name>Memory Cards</name><parent><categoryId>4</categoryId><name>Cameras and Photography</name></parent></return><return><categoryId>4003</categoryId><name>Film Cameras</name><parent><categoryId>4</categoryId><name>Cameras and Photography</name></parent></return><return><categoryId>4004</categoryId><name>Video Cameras</name><parent><categoryId>4</categoryId><name>Cameras and Photography</name></parent></return><return><categoryId>5001</categoryId><name>Cars</name><parent><categoryId>5</categoryId><name>Cars and Boats</na!
me></parent></return><return><categoryId>5002</categoryId><name>Motorcycles</name><parent><categoryId>5</categoryId><name>Cars and Boats</name></parent></return><return><categoryId>5003</categoryId><name>Car Parts</name><parent><categoryId>5</categoryId><name>Cars and Boats</name></parent></return><return><categoryId>6001</categoryId><name>Mobile Phones</name><parent><categoryId>6</categoryId><name>Cell Phones</name></parent></return><return><categoryId>6002</categoryId><name>Mobile Accessories</name><parent><categoryId>6</categoryId><name>Cell Phones</name></parent></return><return><categoryId>6003</categoryId><name>Prepaid cards</name><parent><categoryId>6</categoryId><name>Cell Phones</name></parent></return><return><categoryId>7001</categoryId><name>Women</name><parent><categoryId>7</categoryId><name>Clothing and Shoes</name></parent></return><return><categoryId>7002</categoryId><name>Men</name><parent><categoryId>7</categoryId><name>Clothing and Shoes</name></parent></!
return><return><categoryId>7003</categoryId><name>Girls</name>!
<parent>
<categoryId>7</categoryId><name>Clothing and Shoes</name></parent></return><return><categoryId>7004</categoryId><name>Boys</name><parent><categoryId>7</categoryId><name>Clothing and Shoes</name></parent></return><return><categoryId>7005</categoryId><name>Babies</name><parent><categoryId>7</categoryId><name>Clothing and Shoes</name></parent></return><return><categoryId>8001</categoryId><name>Notebooks</name><parent><categoryId>8</categoryId><name>Computers</name></parent></return><return><categoryId>8002</categoryId><name>Desktop PCs</name><parent><categoryId>8</categoryId><name>Computers</name></parent></return><return><categoryId>8003</categoryId><name>Servers</name><parent><categoryId>8</categoryId><name>Computers</name></parent></return><return><categoryId>8004</categoryId><name>Hardware</name><parent><categoryId>8</categoryId><name>Computers</name></parent></return><return><categoryId>8005</categoryId><name>Software</name><parent><categoryId>8</categoryId><name>Computers!
</name></parent></return><return><categoryId>9001</categoryId><name>CDs</name><parent><categoryId>9</categoryId><name>Music</name></parent></return><return><categoryId>9002</categoryId><name>Records</name><parent><categoryId>9</categoryId><name>Music</name></parent></return><return><categoryId>10001</categoryId><name>Home Audio</name><parent><categoryId>10</categoryId><name>Electronics</name></parent></return><return><categoryId>10002</categoryId><name>MP3 Players</name><parent><categoryId>10</categoryId><name>Electronics</name></parent></return><return><categoryId>10003</categoryId><name>Television</name><parent><categoryId>10</categoryId><name>Electronics</name></parent></return><return><categoryId>10004</categoryId><name>Home theatre</name><parent><categoryId>10</categoryId><name>Electronics</name></parent></return><return><categoryId>11001</categoryId><name>Kitchen</name><parent><categoryId>11</categoryId><name>Home and Garden</name></parent></return><return><categoryId!
>11002</categoryId><name>Real Estate</name><parent><categoryId!
>11</cat
egoryId><name>Home and Garden</name></parent></return><return><categoryId>11003</categoryId><name>Furniture</name><parent><categoryId>11</categoryId><name>Home and Garden</name></parent></return><return><categoryId>12001</categoryId><name>Guitars</name><parent><categoryId>12</categoryId><name>Musical Instruments</name></parent></return><return><categoryId>12002</categoryId><name>Pianos and Keyboards</name><parent><categoryId>12</categoryId><name>Musical Instruments</name></parent></return><return><categoryId>12003</categoryId><name>Percussion</name><parent><categoryId>12</categoryId><name>Musical Instruments</name></parent></return><return><categoryId>12004</categoryId><name>Orchestral</name><parent><categoryId>12</categoryId><name>Musical Instruments</name></parent></return><return><categoryId>13001</categoryId><name>Golf</name><parent><categoryId>13</categoryId><name>Sporting goods</name></parent></return><return><categoryId>13002</categoryId><name>Fishing</name><parent><c!
ategoryId>13</categoryId><name>Sporting goods</name></parent></return><return><categoryId>13003</categoryId><name>Tennis</name><parent><categoryId>13</categoryId><name>Sporting goods</name></parent></return><return><categoryId>14001</categoryId><name>Remote control</name><parent><categoryId>14</categoryId><name>Toys</name></parent></return><return><categoryId>14002</categoryId><name>Cars and trucks</name><parent><categoryId>14</categoryId><name>Toys</name></parent></return><return><categoryId>14003</categoryId><name>Dolls</name><parent><categoryId>14</categoryId><name>Toys</name></parent></return><return><categoryId>14004</categoryId><name>Educational</name><parent><categoryId>14</categoryId><name>Toys</name></parent></return><return><categoryId>15001</categoryId><name>PC</name><parent><categoryId>15</categoryId><name>Video Games</name></parent></return><return><categoryId>15002</categoryId><name>Nintendo Wii</name><parent><categoryId>15</categoryId><name>Video Games</name>!
</parent></return><return><categoryId>15003</categoryId><name>!
Sony Pla
ystation 3</name><parent><categoryId>15</categoryId><name>Video Games</name></parent></return><return><categoryId>15004</categoryId><name>XBox 360</name><parent><categoryId>15</categoryId><name>Video Games</name></parent></return></ns2:listCategoriesResponse>";
+ protected static final String LOGIN_RIGHT_RESPONSE = "<return>true</return>";
+ protected static final String CREATE_NEW_AUCTION_RESPONSE = "<ns2:createAuctionResponse xmlns:ns2=\"http://seambay.example.seam.jboss.org/\"/>";
+ protected static final String FIND_AUCTIONS_RESPONSE = "<description>You can buy an animal here</description>";
+ protected static final String UPDATE_AUCTION_RESPONSE = "<ns2:updateAuctionDetailsResponse xmlns:ns2=\"http://seambay.example.seam.jboss.org/\"/>";
+ protected static final String SET_DURATION_RESPONSE = "<ns2:setAuctionDurationResponse xmlns:ns2=\"http://seambay.example.seam.jboss.org/\"/>";
+ protected static final String SET_STARTING_PRICE_RESPONSE = "<ns2:setAuctionPriceResponse xmlns:ns2=\"http://seambay.example.seam.jboss.org/\"/>";
+ protected static final String AUCTION_DETAILS_PRICE_RESPONSE = "<ns2:getNewAuctionDetailsResponse xmlns:ns2=\"http://seambay.example.seam.jboss.org/\"><return><account><accountId>1</accountId><feedbackPercent>0.0</feedbackPercent><feedbackScore>0</feedbackScore><location>Sydney, NSW, Australia</location>";
+ protected static final String LOGOUT_RESPONSE = "<ns2:logoutResponse xmlns:ns2=\"http://seambay.example.seam.jboss.org/\"><return>true</return></ns2:logoutResponse>";
+ protected static final String CONFIRMATION_RESPONSE = "<env:Body><ns2:confirmAuctionResponse xmlns:ns2=\"http://seambay.example.seam.jboss.org/\"/></env:Body>";
+
+ @Test
+ public void testGoToWSPage()
+ {
+ driver.get(serverURL + contextPath);
+ driver.findElement(HERE_LINK).click();
+
+ assertTrue("URL contains web services page", driver.getCurrentUrl().contains(SERVICE_PAGE_URL));
+ }
+
+ @Test(dependsOnMethods = {
+ "testGoToWSPage"
+ })
+ public void testLoginService()
+ {
+ loginService();
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+
+ // the same as Selenium, must use getValue to retrieve text inside
+ // <textarea></textarea>
+ assertTrue("Response area should contain \"true\"", response.getValue().contains(LOGIN_RIGHT_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService"
+ })
+ public void listCategoriesTest()
+ {
+ loginService();
+ driver.findElement(LIST_CATEGORIES_LINK).clickAndWait();
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+
+ assertTrue("Response area should contain a list of categories.", response.getValue().contains(LIST_CATEGORIES_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService"
+ })
+ public void testCreateNewAuction()
+ {
+ loginService();
+ createNewAuctionService();
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+
+ assertTrue("Response area should contain information about creating the auction.", response.getValue().contains(CREATE_NEW_AUCTION_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService", "testCreateNewAuction"
+ })
+ public void findAuctionsTest()
+ {
+ String searchTerm = "Animals";
+ loginService();
+ createNewAuctionService();
+ confirmAuctionService();
+ driver.findElement(FIND_AUCTIONS_LINK).clickAndWait();
+ driver.findElement(SEARCH_TERM).clearAndSendKeys(searchTerm);
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+
+ assertTrue("Response area should contain information about finding auction.", response.getValue().contains(FIND_AUCTIONS_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService", "testCreateNewAuction"
+ })
+ public void updateAuctionTest()
+ {
+ String title = "Animals";
+ String description = "Another description";
+ String categoryId = "5";
+ loginService();
+ createNewAuctionService();
+
+ driver.findElement(UPDATE_AUCTION_DETAILS_LINK).clickAndWait();
+ driver.findElement(AUCTION_TITLE).clearAndSendKeys(title);
+ driver.findElement(AUCTION_DESCRIPTION).clearAndSendKeys(description);
+ driver.findElement(AUCTION_CATEGORY_ID).clearAndSendKeys(categoryId);
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+
+ assertTrue("Response area should contain information about updating the auction.", response.getValue().contains(UPDATE_AUCTION_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService", "testCreateNewAuction"
+ })
+ public void setAuctionDurationTest()
+ {
+ String duration = "20";
+ loginService();
+ createNewAuctionService();
+
+ driver.findElement(SET_AUCTION_DURATION_LINK).clickAndWait();
+ driver.findElement(AUCTION_DURATION).clearAndSendKeys(duration);
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+ assertTrue("Response area should contain information about setting duration.", response.getValue().contains(SET_DURATION_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService", "testCreateNewAuction"
+ })
+ public void setStartingPriceTest()
+ {
+ String price = "1000";
+ loginService();
+ createNewAuctionService();
+
+ driver.findElement(SET_STARTING_PRICE_LINK).clickAndWait();
+ driver.findElement(STARTING_PRICE).clearAndSendKeys(price);
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+ assertTrue("Response area should contain information about setting starting price.", response.getValue().contains(SET_STARTING_PRICE_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService", "testCreateNewAuction"
+ })
+ public void getAuctionDetailsTest()
+ {
+ loginService();
+ createNewAuctionService();
+
+ driver.findElement(GET_AUCTION_DETAILS_LINK).clickAndWait();
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+ assertTrue("Response area should contain auction details.", response.getValue().contains(AUCTION_DETAILS_PRICE_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService"
+ })
+ public void logOutTest()
+ {
+ loginService();
+ driver.findElement(LOGOUT_LINK).clickAndWait();
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+ assertTrue("Response area should contain logout confirmation.", response.getValue().contains(LOGOUT_RESPONSE));
+ }
+
+ @Test(dependsOnMethods = {
+ "testLoginService", "testCreateNewAuction"
+ })
+ public void confirmAuctionTest()
+ {
+ loginService();
+ createNewAuctionService();
+ confirmAuctionService();
+
+ AjaxWebElement response = driver.findElement(RESPONSE_AREA);
+ assertTrue("Response area should contain information about confirmation.", response.getValue().contains(CONFIRMATION_RESPONSE));
+ }
+
+ /**
+ * Goes to web services page and logs user in
+ */
+ protected void loginService()
+ {
+
+ String username = "demo";
+ String password = "demo";
+
+ driver.get(serverURL + contextPath);
+ driver.findElement(HERE_LINK).click();
+
+ driver.findElement(By.partialLinkText("Login")).clickAndWait();
+
+ driver.findElement(LOGIN_INPUT_USERNAME).clearAndSendKeys(username);
+ driver.findElement(LOGIN_INPUT_PASSWORD).clearAndSendKeys(password);
+
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+ }
+
+ protected void confirmAuctionService()
+ {
+ driver.findElement(CONFIRM_AUCTION_LINK).clickAndWait();
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+ }
+
+ protected void createNewAuctionService()
+ {
+ String title = "Animals";
+ String description = "You can buy an animal here";
+ String categoryId = "6";
+ driver.findElement(CREATE_NEW_AUCTION_LINK).clickAndWait();
+ driver.findElement(AUCTION_TITLE).clearAndSendKeys(title);
+ driver.findElement(AUCTION_DESCRIPTION).clearAndSendKeys(description);
+ driver.findElement(AUCTION_CATEGORY_ID).clearAndSendKeys(categoryId);
+ driver.findElement(INVOKE_SERVICE_BUTTON).clickAndWait();
+ }
+
+}
Added: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriver.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriver.java (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriver.java 2010-03-24 12:36:35 UTC (rev 12261)
@@ -0,0 +1,19 @@
+package org.jboss.seam.example.common.test.webdriver;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+
+/**
+ * Modifies WebDriver to return elements with enhanced AJAX functionality
+ *
+ * @author kpiwko
+ *
+ */
+public interface AjaxWebDriver extends WebDriver
+{
+
+ //@Override
+ public AjaxWebElement findElement(By by);
+
+ public void setWaitTime(int millis);
+}
Added: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverFactory.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverFactory.java (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverFactory.java 2010-03-24 12:36:35 UTC (rev 12261)
@@ -0,0 +1,41 @@
+package org.jboss.seam.example.common.test.webdriver;
+
+/**
+ * Creates appropriate WebDriver driver according to passed string.
+ * To hold a compatibility with Selenium, it is able to use Selenium
+ * based browser names
+ * @author kpiwko
+ */
+public class AjaxWebDriverFactory
+{
+ public static enum Browser
+ {
+ firefox
+ {
+ //@Override
+ public AjaxWebDriver getDriver()
+ {
+ return new FirefoxAjaxDriver();
+ }
+ };
+
+ public abstract AjaxWebDriver getDriver();
+ }
+
+ public static final AjaxWebDriver getDriver(String browser) throws IllegalArgumentException, NullPointerException
+ {
+ if(browser.contains("firefox")) {
+ return Browser.firefox.getDriver();
+ }
+
+ return Browser.valueOf(browser).getDriver();
+ }
+
+ public static final String availableBrowsers()
+ {
+ StringBuilder sb = new StringBuilder();
+ for (Browser b : Browser.values())
+ sb.append("'").append(b.toString()).append("' ");
+ return sb.toString();
+ }
+}
Added: 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 (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebDriverTest.java 2010-03-24 12:36:35 UTC (rev 12261)
@@ -0,0 +1,51 @@
+package org.jboss.seam.example.common.test.webdriver;
+
+import static org.testng.Assert.fail;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Parameters;
+
+/**
+ * Abstract class for all WebDriver tests. Provides running a WebDriverInstance
+ * before each executed test and shuts it down after its execution.
+ *
+ * @author kpiwko
+ *
+ */
+public abstract class AjaxWebDriverTest
+{
+ protected AjaxWebDriver driver;
+ protected String serverURL;
+ protected String contextPath;
+
+ @BeforeMethod
+ @Parameters(value = {
+ "browser", "server.url", "context.path"
+ })
+ public void createDriver(String browser, String serverURL, String contextPath)
+ {
+ try
+ {
+ this.driver = AjaxWebDriverFactory.getDriver(browser);
+ }
+ catch (IllegalArgumentException e)
+ {
+ fail("Unable to instantiate browser of type: " + browser + ", available browsers are: " + AjaxWebDriverFactory.availableBrowsers());
+ }
+ catch (NullPointerException e)
+ {
+ fail("Unable to instantiate browser of type: " + browser + ", available browsers are: " + AjaxWebDriverFactory.availableBrowsers());
+ }
+
+ this.serverURL = serverURL;
+ this.contextPath = contextPath;
+ }
+
+ @AfterMethod
+ public void closeDriver()
+ {
+ driver.close();
+ }
+
+}
Added: 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 (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/AjaxWebElement.java 2010-03-24 12:36:35 UTC (rev 12261)
@@ -0,0 +1,25 @@
+package org.jboss.seam.example.common.test.webdriver;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+/**
+ * Adds AJAX functionality to an ordinary WebElement
+ *
+ * @author kpiwko
+ *
+ */
+public interface AjaxWebElement extends WebElement
+{
+
+ public static final int DEFAULT_WAIT_TIME = 3000;
+
+ //@Override
+ public AjaxWebElement findElement(By by);
+
+ public void setWaitTime(int millis);
+
+ public void clickAndWait();
+
+ public void clearAndSendKeys(CharSequence... keysToSend);
+}
Added: 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 (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/DelegatedWebElement.java 2010-03-24 12:36:35 UTC (rev 12261)
@@ -0,0 +1,134 @@
+package org.jboss.seam.example.common.test.webdriver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+/**
+ * Adds AjaxWebElement functionality to an ordinary WebElement
+ *
+ * @author kpiwko
+ *
+ */
+public class DelegatedWebElement implements AjaxWebElement {
+
+ private int waitTime;
+ private WebElement element;
+
+ public DelegatedWebElement(WebElement element) {
+ this(element, DEFAULT_WAIT_TIME);
+ }
+
+ public DelegatedWebElement(WebElement element, int waitTime) {
+ this.element = element;
+ this.waitTime = waitTime;
+ }
+
+ //@Override
+ public void clear() {
+ element.clear();
+ }
+
+ //@Override
+ public void clearAndSendKeys(CharSequence...keysToSend) {
+ element.clear();
+ element.sendKeys(keysToSend);
+ }
+
+ //@Override
+ public void click() {
+ element.click();
+ }
+
+ //@Override
+ public void clickAndWait() {
+ element.click();
+ try {
+ Thread.sleep(waitTime);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ //@Override
+ public AjaxWebElement findElement(By by) {
+ return new DelegatedWebElement(element.findElement(by));
+ }
+
+ //@Override
+ public List<WebElement> findElements(By by) {
+ List<WebElement> elements = new ArrayList<WebElement>();
+ List<WebElement> original = element.findElements(by);
+ if (original == null || original.size() == 0)
+ return Collections.emptyList();
+
+ for (WebElement e : original)
+ elements.add(new DelegatedWebElement(e));
+
+ return elements;
+ }
+
+ //@Override
+ public String getAttribute(String name) {
+ return element.getAttribute(name);
+ }
+
+ @Deprecated
+ //@Override
+ public String getElementName() {
+ return element.getElementName();
+ }
+
+ //@Override
+ public String getTagName() {
+ return element.getTagName();
+ }
+
+ //@Override
+ public String getText() {
+ return element.getText();
+ }
+
+ //@Override
+ public String getValue() {
+ return element.getValue();
+ }
+
+ //@Override
+ public boolean isEnabled() {
+ return element.isEnabled();
+ }
+
+ //@Override
+ public boolean isSelected() {
+ return element.isSelected();
+ }
+
+ //@Override
+ public void sendKeys(CharSequence... keysToSend) {
+ element.sendKeys(keysToSend);
+ }
+
+ //@Override
+ public void setSelected() {
+ element.setSelected();
+ }
+
+ //@Override
+ public void setWaitTime(int millis) {
+ this.waitTime = millis;
+ }
+
+ //@Override
+ public void submit() {
+ element.submit();
+ }
+
+ //@Override
+ public boolean toggle() {
+ return element.toggle();
+ }
+
+}
Added: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/FirefoxAjaxDriver.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/FirefoxAjaxDriver.java (rev 0)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/webdriver/FirefoxAjaxDriver.java 2010-03-24 12:36:35 UTC (rev 12261)
@@ -0,0 +1,32 @@
+package org.jboss.seam.example.common.test.webdriver;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.firefox.FirefoxDriver;
+
+public class FirefoxAjaxDriver extends FirefoxDriver implements AjaxWebDriver
+{
+
+ private int waitTime;
+
+ public FirefoxAjaxDriver()
+ {
+ this(AjaxWebElement.DEFAULT_WAIT_TIME);
+ }
+
+ public FirefoxAjaxDriver(int waitTime)
+ {
+ this.waitTime = waitTime;
+ }
+
+ //@Override
+ public AjaxWebElement findElement(By by)
+ {
+ return new DelegatedWebElement(super.findElement(by), waitTime);
+ }
+
+ //@Override
+ public void setWaitTime(int millis)
+ {
+ this.waitTime = millis;
+ }
+}
More information about the seam-commits
mailing list