Author: jharting
Date: 2010-09-10 10:17:32 -0400 (Fri, 10 Sep 2010)
New Revision: 13733
Added:
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeleniumDateSelector.java
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/GenerateEntitiesTest.java
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/HotDeploymentStaticTest.java
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeleniumSeamGenTest.java
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSelenium.java
Log:
Minor changes in functional tests.
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml 2010-09-10
14:16:53 UTC (rev 13732)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml 2010-09-10
14:17:32 UTC (rev 13733)
@@ -263,13 +263,13 @@
<target name="copy.selenium" unless="copy.selenium.done">
<copyInlineDependencies id="selenium.server" scope="compile"
todir="${ftest.lib.dir}">
- <dependency groupId="org.seleniumhq.selenium.server"
artifactId="selenium-server" version="1.0.1"
classifier="standalone">
+ <dependency groupId="org.seleniumhq.selenium.server"
artifactId="selenium-server" version="1.0.3"
classifier="standalone">
<exclusion groupId="org.seleniumhq.selenium.core"
artifactId="selenium-core" />
<exclusion groupId="org.seleniumhq.selenium.server"
artifactId="selenium-server-coreless" />
<exclusion groupId="org.apache.ant" artifactId="ant-trax"
/>
<exclusion groupId="org.apache.ant" artifactId="ant-nodeps"
/>
</dependency>
- <dependency groupId="org.seleniumhq.selenium.client-drivers"
artifactId="selenium-java-client-driver" version="1.0.1">
+ <dependency groupId="org.seleniumhq.selenium.client-drivers"
artifactId="selenium-java-client-driver" version="1.0.3">
<exclusion groupId="org.codehaus.groovy.maven.runtime"
artifactId="gmaven-runtime-default" />
</dependency>
<dependency groupId="org.subethamail"
artifactId="subethasmtp-smtp" version="1.2" >
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/GenerateEntitiesTest.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/GenerateEntitiesTest.java 2010-09-10
14:16:53 UTC (rev 13732)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/GenerateEntitiesTest.java 2010-09-10
14:17:32 UTC (rev 13733)
@@ -24,10 +24,9 @@
import java.io.InputStream;
import java.util.Date;
+import org.jboss.seam.example.common.test.selenium.SeleniumDateSelector;
import org.testng.annotations.BeforeGroups;
-import com.thoughtworks.selenium.Wait;
-
/**
* This class and its subclasses test seam-gen's "generate-entities"
feature.
* Every test method should be part of "generate-entitiesTest" in order to get
@@ -121,29 +120,15 @@
*/
public void selectDate(Date date)
{
- // TODO
- final String richFaces = "id=person:birthdateField:birthdateDayCell24";
- final String iceFaces =
"id=person:birthdateField:birthdate_calendar_1569";
- final String icefacesCalendarButton =
"person:birthdateField:birthdate_calendarButton";
+ final String richFacesButton =
"id=person:birthdateField:birthdatePopupButton";
+ final String richFacesCalendar =
"xpath=//div[@class='rich-calendar-tool-btn' and
text()='Today']";
- if (browser.isElementPresent(richFaces))
+ if (browser.isElementPresent(richFacesButton))
{
- browser.click(richFaces);
+ browser.click(richFacesButton);
+ browser.waitForElement(richFacesCalendar);
+ SeleniumDateSelector.RICHFACES.setDate(browser, date);
}
- else if (browser.isElementPresent(icefacesCalendarButton))
- {
- browser.click(icefacesCalendarButton);
- new Wait()
- {
-
- @Override
- public boolean until()
- {
- return browser.isElementPresent(iceFaces);
- }
- }.wait("Calendar did not appear.", Long.valueOf(SELENIUM_TIMEOUT));
- browser.click(iceFaces);
- }
else
{
throw new RuntimeException("Unable to select date." +
browser.getHtmlSource());
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/HotDeploymentStaticTest.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/HotDeploymentStaticTest.java 2010-09-10
14:16:53 UTC (rev 13732)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/HotDeploymentStaticTest.java 2010-09-10
14:17:32 UTC (rev 13733)
@@ -35,23 +35,23 @@
/**
* This test verifies hot deployment of static resources. It modifies home.xhtml
- * page and verifies that changes are reflected within the running app. All is done
- * within user session to detect if the whole application was restarted or not.
+ * page and verifies that changes are reflected within the running app. All is
+ * done within user session to detect if the whole application was restarted or
+ * not.
*
* @author Jozef Hartinger
*
*/
public class HotDeploymentStaticTest extends SeleniumSeamGenTest
{
-
+
private String newFeature;
-
- @BeforeClass
- public void modifyHomePage() throws IOException, InterruptedException
+
+ public void modifyHomePage() throws InterruptedException
{
String homePageLocation = WORKSPACE + "/" + APP_NAME +
"/view/home.xhtml";
newFeature = "Works flawlessly as it is tested by Selenium";
-
+
BufferedReader reader = null;
StringBuilder homePageContentBuilder = new StringBuilder();
try
@@ -65,16 +65,27 @@
line = reader.readLine();
}
}
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable to read home page " +
homePageLocation);
+ }
finally
{
- reader.close();
+ try
+ {
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable to close home page reader.");
+ }
}
-
+
String homePageContent = homePageContentBuilder.toString();
-
+
// add new item into the feature list
- homePageContent = homePageContent.replaceAll("<li>Internationalization
support</li>", "<li>Internationalization
support</li>\n<li>" + newFeature + "</li>");
-
+ homePageContent = homePageContent.replaceAll("<li>Internationalization
support</li>", "<li>Internationalization support</li>\n<li
id=\"newFeature\">" + newFeature + "</li>");
+
// write new content
Writer writer = null;
try
@@ -83,21 +94,37 @@
writer.write(homePageContent);
writer.flush();
}
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable write modified home page " +
homePageLocation);
+ }
finally
{
- writer.close();
+ try
+ {
+ writer.close();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Unable to close home page reader.");
+ }
}
-
+
seamGen.deploy();
}
-
+
@Test(dependsOnGroups = { "newProjectGroup" })
- public void hotDeploymentOfFaceletTemplateTest()
+ public void hotDeploymentOfFaceletTemplateTest() throws InterruptedException
{
-
+
login();
-
- assertTrue(browser.isTextPresent(newFeature), "New feature not found. Hot
deployment failure.");
+
+ modifyHomePage();
+
+ waitForAppToDeploy(HOME_PAGE, "id=newFeature");
+
+ browser.open(HOME_PAGE);
+ assertTrue(browser.isElementPresent("id=newFeature"), "New feature
not found. Hot deployment failure.");
assertTrue(isLoggedIn(), "Session lost. Hot deployment failure.");
}
}
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeleniumSeamGenTest.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeleniumSeamGenTest.java 2010-09-10
14:16:53 UTC (rev 13732)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeleniumSeamGenTest.java 2010-09-10
14:17:32 UTC (rev 13733)
@@ -24,6 +24,7 @@
import static org.testng.Assert.assertTrue;
import org.jboss.seam.example.common.test.selenium.SeamSelenium;
+import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
import org.testng.annotations.BeforeMethod;
/**
@@ -142,7 +143,16 @@
i -= step;
if (i <= 0)
{
- throw new RuntimeException("Timeout waiting for " + element +
" at " + url);
+ String logPath = OUTPUT_DIR + APP_NAME + "/" +
element.replace(":", "");
+ try {
+ SeamSeleniumTest.browser.captureScreenshot(logPath +
".png");
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ SeamSeleniumTest.browser.logHTMLContext(logPath + ".html");
+ stopBrowser();
+ }
+ throw new RuntimeException("Timeout waiting for " + element +
" at " + url + " after " + DEPLOY_TIMEOUT + "
miliseconds");
}
Thread.sleep(step);
browser.open(url); // try again
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSelenium.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSelenium.java 2010-09-10
14:16:53 UTC (rev 13732)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeamSelenium.java 2010-09-10
14:17:32 UTC (rev 13733)
@@ -27,6 +27,7 @@
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Wait;
+import com.thoughtworks.selenium.SeleniumException;
/**
* This class slightly enhaces a Selenium API for controlling a browser.
@@ -274,4 +275,18 @@
}
}.wait("Timeout while waiting for document body after icefaces click.",
timeout);
}
+
+ @Override
+ public void open(String url)
+ {
+ try
+ {
+ super.open(url);
+ }
+ catch (SeleniumException e)
+ {
+ // since 1.0.3 Selenium throws SeleniumException when a server returns 404
+ // we suppress this behavior in order to retain backward compatibility
+ }
+ }
}
Added:
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeleniumDateSelector.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeleniumDateSelector.java
(rev 0)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/src/main/org/jboss/seam/example/common/test/selenium/SeleniumDateSelector.java 2010-09-10
14:17:32 UTC (rev 13733)
@@ -0,0 +1,221 @@
+/*
+ * 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.common.test.selenium;
+
+import java.text.DateFormatSymbols;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+/**
+ * Selects date using Selenium in calendar provided by framework. Each framework
+ * is responsible for managing movement in calendar grid
+ *
+ * @author kpiwko
+ *
+ */
+public enum SeleniumDateSelector
+{
+ RICHFACES
+ {
+ @Override
+ public void setDay(SeamSelenium browser, int day)
+ {
+ String locator = "xpath=//td[contains(@class, 'rich-calendar-cell')
and not(contains(@class,'rich-calendar-boundary-dates')) and text() ='" +
Integer.toString(day) + "']";
+ browser.waitForElement(locator);
+ browser.click(locator);
+ }
+
+ @Override
+ public void setMonth(SeamSelenium browser, int month)
+ {
+ String monthLocator = "xpath=//div[@class='rich-calendar-tool-btn'
and contains(.,',')]";
+ StringTokenizer stk = new StringTokenizer(browser.getText(monthLocator),
",");
+ String calMonth = stk.nextToken().trim();
+ int steps = monthStepsCount(calMonth, month);
+
+ movement(browser, "xpath=//div[@class='rich-calendar-tool-btn' and
normalize-space(text())='<']",
"xpath=//div[@class='rich-calendar-tool-btn' and
normalize-space(text())='>']", steps);
+ }
+
+ @Override
+ public void setYear(SeamSelenium browser, int year)
+ {
+ String yearLocator = "xpath=//div[@class='rich-calendar-tool-btn'
and contains(.,',')]";
+ StringTokenizer stk = new StringTokenizer(browser.getText(yearLocator),
",");
+ // omit first token
+ stk.nextToken();
+ String calYear = stk.nextToken().trim();
+ int steps = yearStepsCount(calYear, year);
+
+ movement(browser, "xpath=//div[@class='rich-calendar-tool-btn' and
normalize-space(text())='<<']",
"xpath=//div[@class='rich-calendar-tool-btn' and
normalize-space(text())='>>']", steps);
+ }
+
+ };
+
+ /**
+ * Selects date using Selenium browser
+ *
+ * @param browser
+ * Selenium browser instance
+ * @param date
+ * Date to be selected
+ */
+ public void setDate(SeamSelenium browser, Date date)
+ {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(date);
+
+ setYear(browser, cal.get(Calendar.YEAR));
+ setMonth(browser, cal.get(Calendar.MONTH));
+ setDay(browser, cal.get(Calendar.DAY_OF_MONTH));
+ }
+
+ /**
+ * Selects day in calendar
+ *
+ * @param browser
+ * Selenium browser instance
+ * @param day
+ * Integer containing the day to be selected, indexing from 1
+ */
+ protected abstract void setDay(SeamSelenium browser, int day);
+
+ /**
+ * Selects month in calendar
+ *
+ * @param browser
+ * Selenium browser instance
+ * @param month
+ * Integer containing the month to be selected, indexing from 1
+ */
+ protected abstract void setMonth(SeamSelenium browser, int month);
+
+ /**
+ * Selects year in calendar
+ *
+ * @param browser
+ * Selenium browser instance
+ * @param year
+ * Integer containing the year to be selected
+ */
+ protected abstract void setYear(SeamSelenium browser, int year);
+
+ /**
+ * Determines direction of month in calendar interface
+ *
+ * @param calMonth
+ * Which month is currently shown on calendar
+ * @param month
+ * Which month is desired to be set, indexing from 1
+ * @return Number of steps which must be done in either of direction, where
+ * sign has meaning:
+ * <ul>
+ * <li>- goes to past</li>
+ * <li>+ goes to future</li>
+ * </ul>
+ */
+ protected int monthStepsCount(String calMonth, int month)
+ {
+ final List<String> months = Arrays.asList((new
DateFormatSymbols()).getMonths());
+ int mindex = months.indexOf(calMonth);
+ if (mindex == -1)
+ throw new IllegalArgumentException("Unknown month: " + calMonth +
" for locale: " + Locale.getDefault());
+
+ return month - (mindex + 1);
+ }
+
+ /**
+ * Determines direction of year in calendar interface
+ *
+ * @param calYear
+ * Which year is currently shown on calendar
+ * @param year
+ * Which month is desired to be set, indexing from 1
+ * @return Number of steps which must be done in either of direction, where
+ * sign has meaning:
+ * <ul>
+ * <li>- goes to past</li>
+ * <li>+ goes to future</li>
+ * </ul>
+ */
+ protected final int yearStepsCount(String calYear, int year)
+ {
+ int yindex;
+ try
+ {
+ yindex = Integer.valueOf(calYear);
+ }
+ catch (NumberFormatException nfe)
+ {
+ throw new IllegalArgumentException("Invalid year: " + calYear, nfe);
+ }
+
+ return year - yindex;
+ }
+
+ /**
+ * Moves in either backward or forward direction according to step count.
+ * Uses locator of element for both directions.
+ *
+ * @param browser
+ * Selenium browser instance
+ * @param backLocator
+ * Element which moves calendar to past
+ * @param forwardLocator
+ * Element which moves calendar to future
+ * @param steps
+ * Number of steps to be done, determined by monthStepsCount() or
+ * yearStepsCount() function
+ * @see SeleniumDateSelector#monthStepsCount(String, int)
+ * @see SeleniumDateSelector#yearStepsCount(String, int)
+ */
+ protected void movement(SeamSelenium browser, String backLocator, String
forwardLocator, int steps)
+ {
+ // going to past
+ if (steps < 0)
+ {
+ for (int i = 0; i > steps; i--)
+ click(browser, backLocator);
+ }
+ // going to future
+ else
+ {
+ for (int i = 0; i < steps; i++)
+ click(browser, forwardLocator);
+ }
+ }
+
+ /**
+ * Clicks on element. Allow differentiate action according to framework, such
+ * as wait for page to load for IceFaces
+ *
+ * @param browser Selenium browser
+ * @param locator Locator of element to be clicked on
+ */
+ protected void click(SeamSelenium browser, String locator)
+ {
+ browser.click(locator);
+ }
+}