[seam-commits] Seam SVN: r11505 - in branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest: examples/ui/src/org/jboss/seam/example/ui/test and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Sep 22 02:30:02 EDT 2009


Author: mgencur at redhat.com
Date: 2009-09-22 02:30:02 -0400 (Tue, 22 Sep 2009)
New Revision: 11505

Added:
   branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/htmlunit/
   branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/htmlunit/HtmlUnitUITest.java
   branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/selenium/ui.properties
Modified:
   branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/build.xml
   branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/selenium/SeleniumUITest.java
Log:
JBPAPP-2829 Backported a functional test for ui example

Modified: branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/build.xml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/build.xml	2009-09-21 11:48:11 UTC (rev 11504)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/build.xml	2009-09-22 06:30:02 UTC (rev 11505)
@@ -36,6 +36,9 @@
 	<property name="lib.dir" value="${ftest.dir}/lib" />
 	<property name="log.dir" value="${ftest.dir}/log" />
 
+	<!-- Build resources -->	
+	<import file="${seam.dir}/build/common.build.xml" />
+
 	<path id="selenium.server.classpath">
 		<fileset dir="${lib.dir}">
 			<include name="selenium-server-standalone.jar" />
@@ -206,10 +209,36 @@
 		</sequential>
 	</macrodef>
 
+	<!-- Target for declaring needed libraries for ftest tests  -->
+	<target name="importlibraries">
+				<copyInlineDependencies id="allexamples" scope="compile" todir="${lib.dir}">
+					<dependency groupId="net.sourceforge.htmlunit" artifactId="htmlunit" version="2.3"/>
+					<dependency groupId="commons-httpclient" artifactId="commons-httpclient" version="3.1"/>
+					<dependency groupId="org.w3c" artifactId="sac" version="1.3"/>
+					<dependency groupId="commons-io" artifactId="commons-io" version="1.3.1"/>
+					<dependency groupId="commons-lang" artifactId="commons-lang" version="2.3"/>
+					<dependency groupId="apache-xerces" artifactId="xercesImpl" version="2.9.0"/>
+					<dependency groupId="commons-collections" artifactId="commons-collections" version="3.1"/>
+					<dependency groupId="commons-lang" artifactId="commons-lang" version="2.3"/>
+					<dependency groupId="apache-xalan" artifactId="xalan" version="j_2.7.0"/>
+					<dependency groupId="commons-codec" artifactId="commons-codec" version="1.3"/>
+					<dependency groupId="commons-logging" artifactId="commons-logging" version="1.1.1"/>
+					<dependency groupId="net.sourceforge.cssparser" artifactId="cssparser" version="0.9.5"/>
+					<dependency groupId="net.sourceforge.htmlunit" artifactId="htmlunit-core-js" version="2.4"/>
+					<dependency groupId="net.sourceforge.nekohtml" artifactId="nekohtml" version="1.9.9"/>
+					<dependency groupId="apache-xalan" artifactId="serializer" version="j_2.7.0"/>
+					<dependency groupId="xml-apis" artifactId="xml-apis" version="1.3.03"/>
+				</copyInlineDependencies>
+	</target>
+
 	<macrodef name="callExample">
 		<attribute name="path" />
 		<attribute name="target" />
 		<sequential>
+			
+			<!-- Added for downloading libraries   -->
+			<antcall target="importlibraries"> </antcall>
+
 			<ant dir="@{path}" target="@{target}" inheritall="false">
 				<property name="container" value="${container}">
 				</property>

Added: branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/htmlunit/HtmlUnitUITest.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/htmlunit/HtmlUnitUITest.java	                        (rev 0)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/htmlunit/HtmlUnitUITest.java	2009-09-22 06:30:02 UTC (rev 11505)
@@ -0,0 +1,122 @@
+/*
+ * 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.ui.test.htmlunit;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+
+import java.io.IOException;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.BrowserVersion;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlImage;
+import static org.testng.AssertJUnit.fail;
+import java.net.URL;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Functional test for uploadLink and graphicImage testcases of UI example
+ * 
+ * @author mgencur
+ *
+ */
+public class HtmlUnitUITest
+{
+   public static final String PAGE_URL = "http://localhost:8080/seam-ui";
+   public static final String HOME_PAGE_TITLE = "UI Example:";
+   public static final String FILE_UPLOAD_FILE= "//input[@type='file']";
+   public static final String FILE_UPLOAD_UPDATE="//input[@type='submit'][@value='Update']";
+   public static final String IMAGE_TO_UPLOAD = "photo.jpg";
+   public static final String FILE_UPLOAD_RESPONSE="//ul/li[contains(text(),'Successfully updated')]";
+   public static final String FILE_UPLOAD_LINK = "//a[contains(@href,'fileUpload')]";
+   public static final String GRAPHIC_IMAGE_LINK = "//a[contains(@href,'graphicImage')]";
+   public static final String IMAGE = "//img";
+   
+   public WebClient wc;
+   public HtmlPage page;   
+   
+   @BeforeMethod
+   public void setUp() throws Exception{
+      URL url = new URL(PAGE_URL);      
+      wc = new WebClient(BrowserVersion.FIREFOX_2);      
+      page = (HtmlPage) wc.getPage(url);  
+   }
+
+   
+   @AfterMethod
+   public void tearDown() {
+      wc.closeAllWindows();       
+   }
+   
+   
+   @Test
+   public void homePageLoadTest()
+   {      
+      assertEquals("Unexpected page title.", HOME_PAGE_TITLE, page.getTitleText());
+   } 
+   
+   
+   @Test(dependsOnMethods={"homePageLoadTest"})
+   public void fileUploadTest() throws IOException {
+      final HtmlAnchor linkEl = (HtmlAnchor) page.getFirstByXPath(FILE_UPLOAD_LINK);
+      
+      final HtmlPage uploadPage = (HtmlPage) linkEl.click();
+      if (uploadPage == null){
+         fail("Could not read page");
+      }
+            
+      final HtmlInput el1 = (HtmlInput) uploadPage.getFirstByXPath(FILE_UPLOAD_FILE);
+      if (el1 == null) {
+         fail("Element file upload file doesn't exist");
+      } else {         
+         el1.type(IMAGE_TO_UPLOAD);
+      }      
+      
+      final HtmlInput el2 = (HtmlInput) uploadPage.getFirstByXPath(FILE_UPLOAD_UPDATE);
+      final HtmlPage finishPage = (HtmlPage) el2.click();
+      final HtmlElement el3 = (HtmlElement) finishPage.getFirstByXPath(FILE_UPLOAD_RESPONSE);
+      
+      assertFalse("Page should contain \"Successfully updated\"", el3 == null);
+   } 
+   
+   
+   @Test(dependsOnMethods={"homePageLoadTest","fileUploadTest"})
+   public void graphicImageTest() throws IOException { 
+      final HtmlAnchor linkEl = (HtmlAnchor) page.getFirstByXPath(GRAPHIC_IMAGE_LINK);
+      
+      final HtmlPage graphicPage = (HtmlPage) linkEl.click();
+      if (graphicPage == null){
+         fail("Could not read page");
+      }
+      
+      final HtmlImage image = (HtmlImage) graphicPage.getFirstByXPath(IMAGE);
+      
+      assertFalse("Page should contain image of Pete Muir", image == null);      
+   }      
+}

Modified: branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/selenium/SeleniumUITest.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/selenium/SeleniumUITest.java	2009-09-21 11:48:11 UTC (rev 11504)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/selenium/SeleniumUITest.java	2009-09-22 06:30:02 UTC (rev 11505)
@@ -1,16 +1,49 @@
+/*
+ * 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.ui.test.selenium;
 
 import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
 
 import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+/**
+ * This class tests functionality of UI example
+ * 
+ * @author Martin Gencur
+ * 
+ */
 public class SeleniumUITest extends SeamSeleniumTest
 {
       public static final String HOME_PAGE = "/index.seam";
       public static final String HOME_PAGE_TITLE = "UI Example:";
-
+      public static final String SELECT_ITEMS_LINK = "xpath=//a[contains(@href,\"selectItems\")]";
+      public static final String FRAGMENT_LINK = "xpath=//a[contains(@href,\"fragment\")]";
+      public static final String FOTMATTED_TEXT_LINK = "xpath=//a[contains(@href,\"formattedText\")]";
+      public static final String BUTTON_AND_SLINK_LINK = "xpath=//a[contains(@href,\"linkAndButton\")]";
+      public static final String CACHE_LINK = "xpath=//a[contains(@href,\"cache\")]";
+               
       @BeforeMethod
       @Override
       public void setUp()
@@ -26,5 +59,87 @@
       public void homePageLoadTest()
       {
          assertEquals("Unexpected page title.", HOME_PAGE_TITLE, browser.getTitle());
+      }        
+         
+      @Test(dependsOnMethods={"homePageLoadTest"})
+      public void selectItemsTest(){      
+         String title = "Mr.";
+         String name = "Martin Gencur";
+         String continent = "Europe";
+         String age = "24";
+         String pet = "Dog (Needs lots of exercise)";
+         String colour1 = "Green", colour2 = "Yellow";
+         String book = "Pride and Prejudice by Jane Austin (British)";
+         String film = "Blade Runner directed by Ridley Scott";
+         browser.clickAndWait(SELECT_ITEMS_LINK);
+         browser.select(getProperty("SELECT_ITEMS_TITLE"), "label="+title);
+         browser.type(getProperty("SELECT_ITEMS_NAME"), name);
+         browser.select(getProperty("SELECT_ITEMS_CONTINENT"), "label="+continent);
+         browser.check(getProperty("SELECT_ITEMS_USER"));
+         browser.check(getProperty("SELECT_ITEMS_ADMIN"));
+         browser.check(getProperty("SELECT_ITEMS_MANAGER"));
+         browser.check(getProperty("SELECT_ITEMS_SUPERADMIN"));
+         browser.select(getProperty("SELECT_ITEMS_AGE"), "label="+age);
+         browser.select(getProperty("SELECT_ITEMS_PET"), "label="+pet);
+         browser.select(getProperty("SELECT_ITEMS_COLOURS"), "label="+colour1);
+         browser.select(getProperty("SELECT_ITEMS_COLOURS"), "label="+colour2);         
+         browser.select(getProperty("SELECT_ITEMS_BOOK"), "label="+book);
+         browser.select(getProperty("SELECT_ITEMS_FILM"), "label="+film); 
+         browser.clickAndWait(getProperty("SELECT_ITEMS_APPLY"));
+         browser.check(getProperty("SELECT_ITEMS_COUNTRY"));
+         browser.clickAndWait(getProperty("SELECT_ITEMS_APPLY"));
+         assertTrue("Page should contain \"Successfully updated\"", browser.isTextPresent("Successfully updated"));
       }
+      
+      
+      @Test(dependsOnMethods={"homePageLoadTest"})
+      public void fragmentTest(){ 
+         browser.clickAndWait(FRAGMENT_LINK);
+         assertTrue("Page should contain \"fragment is rendered\"", browser.isTextPresent("This fragment is rendered whilst"));
+      }      
+      
+      
+      @Test(dependsOnMethods={"homePageLoadTest"})
+      public void formattedTextTest(){ 
+         browser.clickAndWait(FOTMATTED_TEXT_LINK);
+         assertTrue("Page should contain information about Pete Muir working all the time on Seam", browser.isTextPresent("works on Seam, of course"));
+      }
+            
+          
+      @Test(dependsOnMethods={"homePageLoadTest"})
+      public void buttonAndLinkTest(){ 
+         browser.clickAndWait(BUTTON_AND_SLINK_LINK);  
+         assertTrue("Page should contain \"A fragment to jump to\"", browser.isTextPresent("A fragment to jump to"));
+         browser.clickAndWait(getProperty("JUMP_LINK"));
+         browser.clickAndWait(getProperty("JUMP_BUTTON"));
+         browser.clickAndWait(getProperty("LINK_LINK"));
+         browser.clickAndWait(getProperty("DO_ACTION_LINK"));
+         assertTrue("Page should contain \"A simple action was performed\"", browser.isTextPresent("A simple action was performed"));
+         browser.clickAndWait(getProperty("DO_ACTION_BUTTON"));
+         assertTrue("Page should contain \"A simple action was performed\"", browser.isTextPresent("A simple action was performed"));
+         assertTrue("Page should contain disabled link", browser.isElementPresent(getProperty("DISABLED_DO_ACTION_LINK")));
+         assertTrue("Page should contain disabled button", browser.isElementPresent(getProperty("DISABLED_DO_ACTION_BUTTON")));
+         browser.clickAndWait(getProperty("BEGIN_CONVERSATION_LINK"));
+         browser.clickAndWait(getProperty("END_CONVERSATION_BUTTON"));
+         assertTrue("Page shouldn't contain \"A simple action was performed\"", !browser.isTextPresent("A simple action was performed"));
+         browser.clickAndWait(getProperty("ADD_PARAMETER_LINK"));
+         browser.clickAndWait(getProperty("ADD_PARAMETER_BUTTON"));
+         assertTrue("Page should contain \"Foo = bar\"", browser.isTextPresent("Foo = bar"));      
+      }
+      
+      
+      @Test(dependsOnMethods={"homePageLoadTest"})
+      public void cacheTest(){ 
+         browser.clickAndWait(CACHE_LINK);         
+         assertTrue("Page should contain some cached text", browser.isTextPresent("Some cached text"));
+      }
+      
+      
+      /**
+       * Resource download cannot be tested automatically because downloading a file needs user interaction
+       * with a window form 
+       *
+      @Test(dependsOnMethods={"homePageLoadTest"})
+      public void resourceDownloadTest(){         
+      }*/    
 }

Added: branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/selenium/ui.properties
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/selenium/ui.properties	                        (rev 0)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/ui/src/org/jboss/seam/example/ui/test/selenium/ui.properties	2009-09-22 06:30:02 UTC (rev 11505)
@@ -0,0 +1,34 @@
+SELECT_ITEMS_TITLE=xpath\=//select[option[contains(@value,'MR')]]
+SELECT_ITEMS_NAME=xpath\=//input[contains(@value,'Peter Muir')]
+SELECT_ITEMS_CONTINENT=xpath\=//select[option[contains(text(),'Europe')]]
+SELECT_ITEMS_USER=xpath\=//input[@type\='checkbox'][@value\='USER']
+SELECT_ITEMS_ADMIN=xpath\=//input[@type\='checkbox'][@value\='ADMIN']
+SELECT_ITEMS_MANAGER=xpath\=//input[@type\='checkbox'][@value\='MANAGER']
+SELECT_ITEMS_SUPERADMIN=xpath\=//input[@type\='checkbox'][@value\='SUPERADMIN']
+SELECT_ITEMS_AGE=xpath\=//select[option[contains(text(),'24')]]
+SELECT_ITEMS_PET=xpath\=//form/div/div/span/select[option[contains(text(),'Dog')]]
+SELECT_ITEMS_COLOURS=xpath\=//select[option[contains(text(),'Green')]]
+SELECT_ITEMS_BOOK=xpath\=//select[option[contains(text(),'Pride and Prejudice by Jane Austin (British)')]]
+SELECT_ITEMS_FILM=xpath\=//select[option[contains(text(),'Blade Runner directed by Ridley Scott')]]
+SELECT_ITEMS_APPLY=xpath\=//input[@type\='submit'][@value\='Apply']
+SELECT_ITEMS_COUNTRY=xpath\=//input[@type\='radio'][@value\='18']
+JUMP_LINK=xpath\=//a[contains(text(),'Jump')]
+JUMP_BUTTON=xpath\=//input[@type\='button'][@value\='Jump']
+LINK_LINK=xpath\=//a[contains(text(),'Link')]
+DO_ACTION_LINK=xpath\=//a[contains(text(),'Do action')]
+DO_ACTION_BUTTON=xpath\=//input[@type\='button'][@value\='Do action']
+DISABLED_DO_ACTION_LINK=xpath\=//a[contains(text(),'Do action')][not(@href)]
+DISABLED_DO_ACTION_BUTTON=xpath\=//input[@type\='button'][@value\='Do action'][@disabled\='disabled']
+BEGIN_CONVERSATION_LINK=xpath\=//a[contains(text(),'Begin conversation')]
+END_CONVERSATION_BUTTON=xpath\=//input[@type\='button'][@value\='End conversation']
+ADD_PARAMETER_LINK=xpath\=//a[contains(text(),'Add a page parameter')]
+ADD_PARAMETER_BUTTON=xpath\=//input[@type\='button'][@value\='Add a page parameter']
+NAME_INPUT=xpath\=//input[@type\='text'][contains(@name,'name')][not(contains(@name,'nameVerification'))]
+NAME_VERIFICATION_INPUT=xpath\=//input[@type\='text'][contains(@name,'nameVerification')]
+CHECK_NAME_BUTTON=xpath\=//input[@type\='submit'][@value\='Check name']
+MINIMUM_AGE_INPUT=xpath\=//input[@type\='text'][contains(@name,'min')][not(contains(@name,'minVerification'))]
+MAXIMUM_AGE_INPUT=xpath\=//input[@type\='text'][contains(@name,'minVerification')]
+CHECK_AGES_BUTTON=xpath\=//input[@type\='submit'][@value\='Check ages']
+DATE_INPUT=xpath\=//input[contains(@name,'date')][not(contains(@name,'dateVerification'))]
+DATE_VERIFICATION_INPUT=xpath\=//input[contains(@name,'dateVerification')]
+CHECK_DATE_BUTTON=xpath\=//input[@type\='submit'][@value\='Check date']



More information about the seam-commits mailing list