[weld-commits] Weld SVN: r5321 - ftest and 50 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Thu Dec 17 09:21:13 EST 2009
Author: kpiwko at redhat.com
Date: 2009-12-17 09:21:11 -0500 (Thu, 17 Dec 2009)
New Revision: 5321
Added:
ftest/
ftest/branches/
ftest/common/
ftest/common/branches/
ftest/common/tags/
ftest/common/trunk/
ftest/common/trunk/pom.xml
ftest/common/trunk/src/
ftest/common/trunk/src/main/
ftest/common/trunk/src/main/java/
ftest/common/trunk/src/main/java/org/
ftest/common/trunk/src/main/java/org/jboss/
ftest/common/trunk/src/main/java/org/jboss/weld/
ftest/common/trunk/src/main/java/org/jboss/weld/example/
ftest/common/trunk/src/main/java/org/jboss/weld/example/common/
ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/
ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/
ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/SeleniumDateSelector.java
ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldFunctionalTestListener.java
ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldSelenium.java
ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldSeleniumTest.java
ftest/login/
ftest/login/branches/
ftest/login/tags/
ftest/login/trunk/
ftest/login/trunk/pom.xml
ftest/login/trunk/src/
ftest/login/trunk/src/main/
ftest/login/trunk/src/main/java/
ftest/login/trunk/src/main/java/org/
ftest/login/trunk/src/main/java/org/jboss/
ftest/login/trunk/src/main/java/org/jboss/weld/
ftest/login/trunk/src/main/java/org/jboss/weld/example/
ftest/login/trunk/src/main/java/org/jboss/weld/example/login/
ftest/login/trunk/src/main/java/org/jboss/weld/example/login/test/
ftest/login/trunk/src/main/java/org/jboss/weld/example/login/test/selenium/
ftest/login/trunk/src/main/java/org/jboss/weld/example/login/test/selenium/CommonLoginTest.java
ftest/numberguess/
ftest/numberguess/branches/
ftest/numberguess/tags/
ftest/numberguess/trunk/
ftest/numberguess/trunk/pom.xml
ftest/numberguess/trunk/src/
ftest/numberguess/trunk/src/main/
ftest/numberguess/trunk/src/main/java/
ftest/numberguess/trunk/src/main/java/org/
ftest/numberguess/trunk/src/main/java/org/jboss/
ftest/numberguess/trunk/src/main/java/org/jboss/weld/
ftest/numberguess/trunk/src/main/java/org/jboss/weld/example/
ftest/numberguess/trunk/src/main/java/org/jboss/weld/example/numberguess/
ftest/numberguess/trunk/src/main/java/org/jboss/weld/example/numberguess/test/
ftest/numberguess/trunk/src/main/java/org/jboss/weld/example/numberguess/test/selenium/
ftest/numberguess/trunk/src/main/java/org/jboss/weld/example/numberguess/test/selenium/CommonNumberGuessTest.java
ftest/tags/
ftest/translator/
ftest/translator/branches/
ftest/translator/tags/
ftest/translator/trunk/
ftest/translator/trunk/pom.xml
ftest/translator/trunk/src/
ftest/translator/trunk/src/main/
ftest/translator/trunk/src/main/java/
ftest/translator/trunk/src/main/java/org/
ftest/translator/trunk/src/main/java/org/jboss/
ftest/translator/trunk/src/main/java/org/jboss/weld/
ftest/translator/trunk/src/main/java/org/jboss/weld/example/
ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/
ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/clustertest/
ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/clustertest/selenium/
ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/test/
ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/test/selenium/
ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/test/selenium/TranslatorTest.java
ftest/trunk/
ftest/trunk/pom.xml
Log:
WELD-24,WELD-25
Added: ftest/common/trunk/pom.xml
===================================================================
--- ftest/common/trunk/pom.xml (rev 0)
+++ ftest/common/trunk/pom.xml 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-parent</artifactId>
+ <version>0.1</version>
+ </parent>
+
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-common</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+ <name>Weld Examples Ftest: Common Functionality</name>
+</project>
+
Added: ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/SeleniumDateSelector.java
===================================================================
--- ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/SeleniumDateSelector.java (rev 0)
+++ ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/SeleniumDateSelector.java 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,245 @@
+/*
+ * 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.weld.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(WeldSelenium 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(WeldSelenium 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 text()='<']", "xpath=//div[@class='rich-calendar-tool-btn' and text()='>']", steps);
+ }
+
+ @Override
+ public void setYear(WeldSelenium 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 text()='<<']", "xpath=//div[@class='rich-calendar-tool-btn' and text()='>>'", steps);
+ }
+
+ },
+ ICEFACES
+ {
+ @Override
+ public void setDay(WeldSelenium browser, int day)
+ {
+ String locator = "xpath=//td[@class='iceSelInpDateDay']/a[./span/text()='" + Integer.toString(day) + "']";
+ browser.waitForElement(locator);
+ browser.click(locator);
+ }
+
+ @Override
+ public void setMonth(WeldSelenium browser, int month)
+ {
+ String monthLocator = "xpath=//td[@class='iceSelInpDateMonthYear'][2]";
+ String calMonth = browser.getText(monthLocator).trim();
+ int steps = monthStepsCount(calMonth, month);
+
+ movement(browser, "xpath=//td[@class='iceSelInpDateMonthYear'][1]/a", "xpath=//td[@class='iceSelInpDateMonthYear'][3]/a", steps);
+ }
+
+ @Override
+ public void setYear(WeldSelenium browser, int year)
+ {
+ String yearLocator = "xpath=//td[@class='iceSelInpDateMonthYear'][6]";
+ String calYear = browser.getText(yearLocator).trim();
+ int steps = yearStepsCount(calYear, year);
+
+ movement(browser, "xpath=//td[@class='iceSelInpDateMonthYear'][5]/a", "xpath=//td[@class='iceSelInpDateMonthYear'][7]/a", steps);
+ }
+
+ /**
+ * IceFaces forces partial submit, so we must wait for page reload
+ */
+ @Override
+ protected void click(WeldSelenium browser, String locator)
+ {
+ browser.clickAndWait(locator);
+ }
+
+ };
+
+ /**
+ * Selects date using Selenium browser
+ *
+ * @param browser Selenium browser instance
+ * @param date Date to be selected
+ */
+ public void setDate(WeldSelenium 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(WeldSelenium 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(WeldSelenium 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(WeldSelenium 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(WeldSelenium 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(WeldSelenium browser, String locator)
+ {
+ browser.click(locator);
+ }
+}
Added: ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldFunctionalTestListener.java
===================================================================
--- ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldFunctionalTestListener.java (rev 0)
+++ ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldFunctionalTestListener.java 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,99 @@
+/*
+ * 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.weld.example.common.test.selenium;
+
+import org.testng.ITestContext;
+import org.testng.ITestListener;
+import org.testng.ITestResult;
+
+/**
+ * This listener class is used for capturing snapshot of running web application
+ * and storing HTML source of the browser content. It expects WeldSeleniumTest
+ * or its descendant to retrieve WeldSelenium object.
+ *
+ * @author Martin Gencur
+ * @author kpiwko
+ *
+ */
+public class WeldFunctionalTestListener implements ITestListener
+{
+
+ public void onFinish(ITestContext context)
+ {
+ }
+
+ public void onStart(ITestContext context)
+ {
+ }
+
+ public void onTestFailedButWithinSuccessPercentage(ITestResult result)
+ {
+ }
+
+ public void onTestFailure(ITestResult result)
+ {
+ WeldSeleniumTest testcase = getTest(result);
+ String logPath = testcase.getOutputDirectory() + "/" + result.getName();
+
+ try
+ {
+ testcase.getBrowser().captureScreenshot(logPath + ".png");
+ }
+ catch (Exception e)
+ {
+ }
+ finally
+ {
+ testcase.getBrowser().logHTMLContext(logPath + ".html");
+ testcase.stopBrowser();
+ }
+
+ }
+
+ public void onTestSkipped(ITestResult result)
+ {
+ getTest(result).stopBrowser();
+ }
+
+ public void onTestStart(ITestResult result)
+ {
+ }
+
+ public void onTestSuccess(ITestResult result)
+ {
+ getTest(result).stopBrowser();
+ }
+
+ private WeldSeleniumTest getTest(ITestResult result) throws RuntimeException
+ {
+ try
+ {
+ WeldSeleniumTest testcase = (WeldSeleniumTest) result.getInstance();
+ return testcase;
+ }
+ catch (ClassCastException e)
+ {
+ System.err.println("Running WeldFunctionalTestListener on test not inherited from WeldSeleniumTest");
+ throw new RuntimeException("Running WeldFunctionalTestListener on test not inherited from WeldSeleniumTest", e);
+ }
+ }
+}
Added: ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldSelenium.java
===================================================================
--- ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldSelenium.java (rev 0)
+++ ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldSelenium.java 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,341 @@
+/*
+ * 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.weld.example.common.test.selenium;
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+
+import com.thoughtworks.selenium.DefaultSelenium;
+import com.thoughtworks.selenium.Wait;
+
+/**
+ * This class slightly enhances a Selenium API for controlling a browser.
+ *
+ * @author Jozef Hartinger
+ * @author kpiwko
+ */
+public class WeldSelenium extends DefaultSelenium
+{
+
+ private String timeout = "30000";
+ private boolean icefacesDetection = false;
+ private long icefacesWaitTime = 1000;
+ private long windowMaximizeWaitTime = 5000L;
+
+ private final String ICEFACES_CONNECTION_STATUS = "xpath=//div[@class='iceOutConStat connectionStatus']";
+ private final String ICEFACES_IDLE_VISIBLE = "xpath=//div[@class='iceOutConStatInactv connectionStatusInactv'][@style='visibility: visible;']";
+
+ public WeldSelenium(String serverHost, int serverPort, String browserStartCommand, String browserURL)
+ {
+ super(serverHost, serverPort, browserStartCommand, browserURL);
+ }
+
+ /**
+ * Same as click method but waits for page to load after clicking. Default
+ * timeout can be changed by setTimeout() method.
+ *
+ * @param locator
+ */
+ public void clickAndWait(String locator)
+ {
+ click(locator);
+ waitForPageToLoad();
+ }
+
+ /**
+ * Simulates a user pressing "back" button and waits for page to load.
+ * Default timeout can be changed by setTimeout() method.
+ */
+ public void goBackAndWait()
+ {
+ super.goBack();
+ super.waitForPageToLoad(timeout);
+ }
+
+ /**
+ * Simulates a user pressing "refresh" button and waits for page to load.
+ * Default timeout can be changed by setTimeout() method.
+ */
+ public void refreshAndWait()
+ {
+ super.refresh();
+ super.waitForPageToLoad(timeout);
+ }
+
+ @Override
+ public void setTimeout(String timeout)
+ {
+ super.setTimeout(timeout);
+ this.timeout = timeout;
+ }
+
+ public String getTimeout()
+ {
+ return timeout;
+ }
+
+ public void waitForPageToLoad()
+ {
+
+ waitForPageToLoad(timeout);
+ }
+
+ @Override
+ public void waitForPageToLoad(String timeout)
+ {
+ if (icefacesDetection && isElementPresent(ICEFACES_CONNECTION_STATUS))
+ {
+ waitForIcefaces(icefacesWaitTime, Long.valueOf(timeout));
+ }
+ else
+ {
+ super.waitForPageToLoad(timeout);
+ }
+ }
+
+ /**
+ * Waits until element is asynchronously loaded on page. Uses global Selenium
+ * timeout
+ *
+ * @param locator
+ * Locator of element
+ */
+ public void waitForElement(final String locator)
+ {
+ waitForElement(locator, Long.valueOf(timeout));
+ }
+
+ /**
+ * Waits until element is asynchronously loaded on page.
+ *
+ * @param timeout
+ * Timeout in milliseconds
+ * @param locator
+ * Locator of element
+ */
+ public void waitForElement(final String locator, long timeout)
+ {
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return isElementPresent(locator);
+ }
+ }.wait("Timeout while waiting for asynchronous update of " + locator, timeout);
+ }
+
+ /**
+ * Waits until element is asynchronously unloaded from page. Uses global
+ * Selenium timeout
+ *
+ * @param locator
+ * Locator of element
+ */
+ public void waitForElementNotPresent(final String locator)
+ {
+ waitForElementNotPresent(locator, Long.valueOf(timeout));
+ }
+
+ /**
+ * Waits until element is asynchronously unloaded from page.
+ *
+ * @param timeout
+ * Timeout in milliseconds
+ * @param locator
+ * Locator of element
+ */
+ public void waitForElementNotPresent(final String locator, long timeout)
+ {
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return !isElementPresent(locator);
+ }
+ }.wait("Timeout while waiting for asynchronous update of " + locator, timeout);
+ }
+
+ /**
+ * Waits until element's content is asynchronously loaded on page. Uses
+ * global Selenium timeout
+ *
+ * @param locator
+ * Locator of element
+ */
+ public void waitForElementContent(final String locator)
+ {
+ waitForElementContent(locator, Long.valueOf(timeout));
+ }
+
+ /**
+ * Waits until element's content is asynchronously loaded on page
+ *
+ * @param timeout
+ * Timeout in milliseconds
+ * @param locator
+ * Locator of element
+ */
+ public void waitForElementContent(final String locator, long timeout)
+ {
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return (getValue(locator).length() != 0);
+ }
+ }.wait("Timeout while waiting for asynchronous update of element content. Element: " + locator + ", " + "Content length: "
+ + getValue(locator).length(), timeout);
+ }
+
+ /**
+ * Selects windows by its id. Waits until windows is refreshed.
+ *
+ * @param windowID
+ * Identification of window which is selected
+ */
+ @Override
+ public void selectWindow(String windowID)
+ {
+ super.selectWindow(windowID);
+ refresh();
+ waitForPageToLoad();
+ }
+
+ /**
+ * Returns true if icefaces detection is turned on
+ */
+ public boolean isIcefacesDetection()
+ {
+ return icefacesDetection;
+ }
+
+ /**
+ * Switch icefaces detection on/off
+ *
+ * @param icefacesDetection
+ */
+ public void setIcefacesDetection(boolean icefacesDetection)
+ {
+ this.icefacesDetection = icefacesDetection;
+ }
+
+ /**
+ * This wait time will be used when waiting for response after invoking
+ * icefaces action
+ */
+ public long getIcefacesWaitTime()
+ {
+ return icefacesWaitTime;
+ }
+
+ /**
+ * This wait time will be used when waiting for response after invoking
+ * icefaces action
+ *
+ * @param icefacesWaitTime
+ */
+ public void setIcefacesWaitTime(long icefacesWaitTime)
+ {
+ this.icefacesWaitTime = icefacesWaitTime;
+ }
+
+ /**
+ * Captures a screenshot and stores it into a file. Active windows is
+ * maximized before capturing a screenshot.
+ */
+ @Override
+ public void captureScreenshot(String path)
+ {
+ windowMaximize();
+ try
+ {
+ Thread.sleep(windowMaximizeWaitTime);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ super.captureScreenshot(path);
+ }
+
+ /**
+ * Logs HTML body into a file.
+ *
+ * @param path
+ */
+ public void logHTMLContext(String path)
+ {
+ String source = getHtmlSource();
+ BufferedWriter writer = null;
+ try
+ {
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path)));
+ writer.write(source);
+ writer.flush();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to save HTML body", e);
+ }
+ finally
+ {
+ try
+ {
+ writer.close();
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ }
+
+ private void waitForIcefaces(Long waitTime, Long timeout)
+ {
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return isElementPresent(ICEFACES_IDLE_VISIBLE);
+ }
+ }.wait("Timeout while waiting for icefaces idle state.", timeout);
+ try
+ {
+ Thread.sleep(icefacesWaitTime);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ new Wait()
+ {
+ @Override
+ public boolean until()
+ {
+ return isElementPresent("xpath=//body");
+ }
+ }.wait("Timeout while waiting for document body after icefaces click.", timeout);
+ }
+}
Added: ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldSeleniumTest.java
===================================================================
--- ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldSeleniumTest.java (rev 0)
+++ ftest/common/trunk/src/main/java/org/jboss/weld/example/common/test/selenium/WeldSeleniumTest.java 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,93 @@
+/*
+ * 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.weld.example.common.test.selenium;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Optional;
+import org.testng.annotations.Parameters;
+
+/**
+ * Base class for all Weld based Selenium tests.
+ *
+ * @author jbalunas
+ * @author jharting
+ * @author kpiwko
+ *
+ */
+public abstract class WeldSeleniumTest
+{
+ protected WeldSelenium browser;
+ protected String contextPath;
+ protected String basedir;
+
+ @BeforeMethod(groups={"seleniumSetUp"})
+ @Parameters( { "selenium.server.host", "selenium.server.port", "selenium.browser", "selenium.browser.url", "selenium.speed", "selenium.timeout", "example.context.path", "basedir" })
+ public void setUp(String host, String port, String browserType, String browserUrl, String speed, String timeout, @Optional("") String contextPath, String basedir)
+ {
+ browser = startBrowser(host, Integer.parseInt(port), browserType, browserUrl);
+ browser.allowNativeXpath("false");
+ browser.setSpeed(speed);
+ browser.setTimeout(timeout);
+
+ this.contextPath = contextPath;
+ this.basedir = basedir;
+ }
+
+ // This is stopped automatically by listener
+ // It must be stopped in listener because in case of error
+ // Selenium session is required to exist to retrieve screenshot and HTML code of page
+ //@AfterMethod
+ public void tearDownDeprecated()
+ {
+ stopBrowser();
+ }
+
+ public WeldSelenium startBrowser(String host, int port, String browser, String browserUrl)
+ {
+ WeldSelenium newBrowser = new WeldSelenium(host, port, browser, browserUrl);
+ newBrowser.start();
+ return newBrowser;
+ }
+
+ public void stopBrowser()
+ {
+ if (browser != null)
+ {
+ browser.stop();
+ }
+ }
+
+ /**
+ * Returns WeldSelenium instance of this test case
+ *
+ * @return WeldSelenium instance
+ */
+ public WeldSelenium getBrowser()
+ {
+ return browser;
+ }
+
+ public String getOutputDirectory() {
+ return basedir + "/target/test-output/functional-framework" + contextPath;
+ }
+
+}
Added: ftest/login/trunk/pom.xml
===================================================================
--- ftest/login/trunk/pom.xml (rev 0)
+++ ftest/login/trunk/pom.xml 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-parent</artifactId>
+ <version>0.1</version>
+ </parent>
+
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-login</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+ <name>Weld Examples Ftest: Login</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-common</artifactId>
+ <version>0.1</version>
+ </dependency>
+ </dependencies>
+
+</project>
+
Added: ftest/login/trunk/src/main/java/org/jboss/weld/example/login/test/selenium/CommonLoginTest.java
===================================================================
--- ftest/login/trunk/src/main/java/org/jboss/weld/example/login/test/selenium/CommonLoginTest.java (rev 0)
+++ ftest/login/trunk/src/main/java/org/jboss/weld/example/login/test/selenium/CommonLoginTest.java 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,78 @@
+/*
+ * 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.weld.example.login.test.selenium;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import org.jboss.weld.example.common.test.selenium.WeldSeleniumTest;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests login examples in Weld
+ *
+ * @author kpiwko
+ */
+public class CommonLoginTest extends WeldSeleniumTest
+{
+
+ protected String MAIN_PAGE = "/home.jsf";
+ protected String LOGGED_IN = "xpath=//li[contains(text(),'Welcome')]";
+ protected String LOGGED_OUT = "xpath=//li[contains(text(),'Goodbye')]";
+
+ protected String USERNAME_FIELD = "id=loginForm:username";
+ protected String PASSWORD_FIELD = "id=loginForm:password";
+
+ protected String LOGIN_BUTTON = "id=loginForm:login";
+ protected String LOGOUT_BUTTON = "id=loginForm:logout";
+
+ @BeforeMethod(dependsOnGroups = "seleniumSetUp")
+ public void open()
+ {
+ browser.open(contextPath + MAIN_PAGE);
+ browser.waitForPageToLoad();
+ }
+
+ @Test
+ public void loginTest()
+ {
+ assertFalse(browser.isElementPresent(LOGGED_IN), "User should not be logged in!");
+ browser.type(USERNAME_FIELD, "User");
+ browser.type(PASSWORD_FIELD, "password");
+ browser.clickAndWait(LOGIN_BUTTON);
+ assertTrue(browser.isElementPresent(LOGGED_IN), "User should be logged in!");
+ }
+
+ @Test
+ public void logoutTest()
+ {
+ assertFalse(browser.isElementPresent(LOGGED_IN), "User should not be logged in!");
+ browser.type(USERNAME_FIELD, "User");
+ browser.type(PASSWORD_FIELD, "password");
+ browser.clickAndWait(LOGIN_BUTTON);
+ assertTrue(browser.isElementPresent(LOGGED_IN), "User should be logged in!");
+ browser.clickAndWait(LOGOUT_BUTTON);
+ assertTrue(browser.isElementPresent(LOGGED_OUT), "User should not be logged in!");
+ }
+
+}
Added: ftest/numberguess/trunk/pom.xml
===================================================================
--- ftest/numberguess/trunk/pom.xml (rev 0)
+++ ftest/numberguess/trunk/pom.xml 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-parent</artifactId>
+ <version>0.1</version>
+ </parent>
+
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-numberguess</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+ <name>Weld Examples Ftest: Numberguess</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-common</artifactId>
+ <version>0.1</version>
+ </dependency>
+ </dependencies>
+
+</project>
+
Added: ftest/numberguess/trunk/src/main/java/org/jboss/weld/example/numberguess/test/selenium/CommonNumberGuessTest.java
===================================================================
--- ftest/numberguess/trunk/src/main/java/org/jboss/weld/example/numberguess/test/selenium/CommonNumberGuessTest.java (rev 0)
+++ ftest/numberguess/trunk/src/main/java/org/jboss/weld/example/numberguess/test/selenium/CommonNumberGuessTest.java 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,131 @@
+/*
+ * 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.weld.example.numberguess.test.selenium;
+
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import org.jboss.weld.example.common.test.selenium.WeldSeleniumTest;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests numberguess examples in Weld
+ *
+ * @author Jozef Hartinger
+ * @author kpiwko
+ */
+public class CommonNumberGuessTest extends WeldSeleniumTest
+{
+
+ protected String MAIN_PAGE = "/home.jsf";
+ protected String GUESS_MESSAGES = "id=numberGuess:messages";
+
+ protected String GUESS_FIELD = "id=numberGuess:inputGuess";
+ protected String GUESS_SUBMIT = "id=numberGuess:guessButton";
+ protected String GUESS_RESET = "id=numberGuess:resetButton";
+ protected String GUESS_SMALLEST = "id=numberGuess:smallest";
+ protected String GUESS_BIGGEST = "id=numberGuess:biggest";
+
+ protected String WIN_MSG = "Correct!";
+ protected String LOSE_MSG = "No guesses left!";
+
+ @BeforeMethod(dependsOnGroups = "seleniumSetUp")
+ public void open()
+ {
+ browser.open(contextPath + MAIN_PAGE);
+ browser.waitForPageToLoad();
+ }
+
+ @Test
+ public void smartTest()
+ {
+
+ int min;
+ int max;
+ int guess;
+ int i = 0;
+
+ while (isOnGuessPage())
+ {
+ if (i > 9)
+ {
+ fail("Game should not be longer than 10 guesses");
+ }
+
+ assertTrue(browser.isElementPresent(GUESS_SMALLEST), "Expected smallest number on page");
+ assertTrue(browser.isElementPresent(GUESS_BIGGEST), "Expected biggest number on page");
+
+ min = Integer.parseInt(browser.getText(GUESS_SMALLEST));
+ max = Integer.parseInt(browser.getText(GUESS_BIGGEST));
+ guess = min + ((max - min) / 2);
+ enterGuess(guess);
+ i++;
+ }
+ assertTrue(isOnWinPage(), "Win page expected after playing smart.");
+ }
+
+ @Test
+ public void linearTest()
+ {
+ int guess = 0;
+
+ while (isOnGuessPage())
+ {
+ enterGuess(++guess);
+ assertTrue(guess <= 10, "Guess count exceeded.");
+ }
+ if (guess < 10)
+ {
+ assertTrue(isOnWinPage(), "Player should not lose before 10th guess.");
+ }
+ else
+ {
+ assertTrue(isOnLosePage() || isOnWinPage(), "After 10th guess player should lose or win.");
+ }
+
+ }
+
+ protected void enterGuess(int guess)
+ {
+ browser.type(GUESS_FIELD, String.valueOf(guess));
+ browser.clickAndWait(GUESS_SUBMIT);
+ }
+
+ protected boolean isOnGuessPage()
+ {
+ return !(isOnWinPage() || isOnLosePage());
+ }
+
+ protected boolean isOnWinPage()
+ {
+ String text = browser.getText(GUESS_MESSAGES);
+ return WIN_MSG.equals(text);
+ }
+
+ protected boolean isOnLosePage()
+ {
+ String text = browser.getText(GUESS_MESSAGES);
+ return LOSE_MSG.equals(text);
+ }
+
+}
Added: ftest/translator/trunk/pom.xml
===================================================================
--- ftest/translator/trunk/pom.xml (rev 0)
+++ ftest/translator/trunk/pom.xml 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-parent</artifactId>
+ <version>0.1</version>
+ </parent>
+
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-translator</artifactId>
+ <packaging>jar</packaging>
+ <name>Weld Examples Ftest: Translator</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-common</artifactId>
+ <version>0.1</version>
+ </dependency>
+ </dependencies>
+
+</project>
+
Added: ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/test/selenium/TranslatorTest.java
===================================================================
--- ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/test/selenium/TranslatorTest.java (rev 0)
+++ ftest/translator/trunk/src/main/java/org/jboss/weld/example/translator/test/selenium/TranslatorTest.java 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,62 @@
+/*
+ * 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.weld.example.translator.test.selenium;
+
+import static org.testng.Assert.assertTrue;
+
+import org.jboss.weld.example.common.test.selenium.WeldSeleniumTest;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests translator example in Weld
+ *
+ * @author mgencur
+ */
+public class TranslatorTest extends WeldSeleniumTest
+{
+ protected String MAIN_PAGE = "/home.jsf";
+ protected String INPUT_AREA = "id=TranslatorMain:text";
+ protected String TRANSLATE_BUTTON = "id=TranslatorMain:button";
+ protected String ONE_SENTENCE = "This is only one sentence.";
+ protected String MORE_SENTENCES = "First sentence. Second and last sentence.";
+ protected String ONE_SENTENCE_TRANSLATED = "Lorem ipsum dolor sit amet.";
+ protected String MORE_SENTENCES_TRANSLATED = "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.";
+
+ @BeforeMethod(dependsOnGroups = "seleniumSetUp")
+ public void open()
+ {
+ browser.open(contextPath + MAIN_PAGE);
+ browser.waitForPageToLoad();
+ }
+
+ @Test
+ public void translateTest()
+ {
+ browser.type(INPUT_AREA, ONE_SENTENCE);
+ browser.clickAndWait(TRANSLATE_BUTTON);
+ assertTrue(browser.isTextPresent(ONE_SENTENCE_TRANSLATED), "One sentence translated into latin expected.");
+ browser.type(INPUT_AREA, MORE_SENTENCES);
+ browser.clickAndWait(TRANSLATE_BUTTON);
+ assertTrue(browser.isTextPresent(MORE_SENTENCES_TRANSLATED), "More sentences translated into latin expected.");
+ }
+}
Added: ftest/trunk/pom.xml
===================================================================
--- ftest/trunk/pom.xml (rev 0)
+++ ftest/trunk/pom.xml 2009-12-17 14:21:11 UTC (rev 5321)
@@ -0,0 +1,63 @@
+<?xml version="1.0"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-parent</artifactId>
+ <version>8</version>
+ </parent>
+
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>ftest-parent</artifactId>
+ <version>0.1</version>
+ <packaging>pom</packaging>
+ <name>Weld Examples Functional Tests Parent</name>
+
+ <modules>
+ <module>common</module>
+ <module>numberguess</module>
+ <module>login</module>
+ <module>translator</module>
+ </modules>
+
+ <properties>
+ <testng.version>5.10</testng.version>
+ <selenium.core.version>1.0.1</selenium.core.version>
+ <selenium.java.client.version>1.0.1</selenium.java.client.version>
+ </properties>
+
+ <!-- Common dependencies only -->
+ <dependencies>
+ <dependency>
+ <groupId>org.seleniumhq.selenium.core</groupId>
+ <artifactId>selenium-core</artifactId>
+ <version>${selenium.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.seleniumhq.selenium.client-drivers</groupId>
+ <artifactId>selenium-java-client-driver</artifactId>
+ <version>${selenium.java.client.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>${testng.version}</version>
+ <classifier>jdk15</classifier>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
More information about the weld-commits
mailing list