[richfaces-svn-commits] JBoss Rich Faces SVN: r9012 - in trunk/test-applications/seleniumTest/src/test: java/org/richfaces/testng and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Jun 12 04:50:03 EDT 2008


Author: dsvyatobatsko
Date: 2008-06-12 04:50:03 -0400 (Thu, 12 Jun 2008)
New Revision: 9012

Modified:
   trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
   trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandButtonTest.java
   trunk/test-applications/seleniumTest/src/test/testng/win/testng_default_default_neko.xml
Log:
refactoring

Modified: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java	2008-06-12 06:16:25 UTC (rev 9011)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/SeleniumTestBase.java	2008-06-12 08:50:03 UTC (rev 9012)
@@ -21,13 +21,20 @@
 
 package org.richfaces;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.ajax4jsf.bean.Configurator;
 import org.ajax4jsf.javascript.ScriptUtils;
 import org.ajax4jsf.template.Template;
 import org.openqa.selenium.server.SeleniumServer;
 import org.testng.Assert;
 import org.testng.annotations.AfterSuite;
+import org.testng.annotations.AfterTest;
 import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Parameters;
 
 import com.thoughtworks.selenium.DefaultSelenium;
 
@@ -37,7 +44,7 @@
  * @author Andrey Markavtsov
  * 
  */
-public abstract class SeleniumTestBase {
+public abstract class SeleniumTestBase implements RichSeleniumTest {
 
     /** Specifies the time to wait for page rendering */
     private static final Integer pageRenderTime = 5000;
@@ -64,19 +71,19 @@
     /** Protocol */
     public String protocol;
 
-	private String filterPrefix;
+    private String filterPrefix;
 
-	private SeleniumServer seleniumServer;
+    private SeleniumServer seleniumServer;
 
+    private Object[][] data;
+
     /** Defines the name of current j2ee application name */
     public static final String APPLICATION_NAME = "seleniumTest";
 
-    public static final String DATA_TABLE_TEMPLATE = "dataTable";
+    public SeleniumTestBase() {
+        this("http", "localhost", serverPort);
+    }
 
-    public static final String MODAL_PANEL_TEMPLATE = "modalPanel";
-
-    public static final String SIMPLE_TEMPLATE = "simple";
-
     public SeleniumTestBase(String protocol, String host, String port) {
         this.host = host;
         this.port = port;
@@ -89,16 +96,62 @@
     	seleniumServer.start();
     }
 
+    @DataProvider(name = "templates")
+    protected Object[][] templates() {
+        return new Object[][] { { Template.SIMPLE }, { Template.DATA_TABLE }, { Template.MODAL_PANEL } };
+        //return this.data;
+    }
 
+    /**
+     * This method are invoked before selenium tests started
+     */
+    @BeforeTest
+    @Parameters({"browser", "filterPrefix"})
+    public void startSelenium(String browser, String filterPrefix) {
+        synchronized (MUTEX) {
+            this.filterPrefix = filterPrefix;
+            selenium = createSeleniumClient(protocol + "://" + host + ":" + port + "/", browser);
+            selenium.start();
+        }
+    }
+
+    @BeforeTest
+    @Parameters({"loadStyleStrategy", "loadScriptStrategy"})
+    protected void loadConfiguration(String loadStyleStrategy, String loadScriptStrategy) throws Exception {
+        Configurator.setLoadScriptStrategy(loadScriptStrategy);
+        Configurator.setLoadStyleStrategy(loadStyleStrategy);
+    }
+
+    /**
+     * This method are invoked after selenium tests completed
+     */
+    @AfterTest(alwaysRun=true)
+    public void stopSelenium() {
+        synchronized (MUTEX) {
+            selenium.stop();
+            selenium = null;
+        }
+    }
+
+    protected void loadTemplates(String templateExpr) {
+        String[] array = new String[]{};
+        if(null != templateExpr) {
+            array = templateExpr.split(",");
+        }
+
+        List<Object[]> list = new ArrayList<Object[]>();
+        for (String string : array) {
+            Object[] elem = new Object[] {Template.valueOf(string)};
+            list.add(elem);
+        }
+
+        this.data = (Object[][]) list.toArray(new Object[0][0]);
+    }
+
     @AfterSuite
     public void stopSeleniumServer() throws Exception {
     	seleniumServer.stop();
     }
- 
-    protected void loadConfiguration(String loadStyleStrategy, String loadScriptStrategy) throws Exception {
-    	Configurator.setLoadScriptStrategy(loadScriptStrategy);
-    	Configurator.setLoadStyleStrategy(loadStyleStrategy);
-    }
 
     /**
      * @param url
@@ -110,29 +163,8 @@
     }
 
     private static final Object MUTEX = new Object();
-    
-    /**
-     * This method are invoking before selenium tests started
-     */
-    protected void startSelenium(String browser, String filterPrefix) {
-    	synchronized (MUTEX) {
-        	this.filterPrefix = filterPrefix;
-        	selenium = createSeleniumClient(protocol + "://" + host + ":" + port + "/", browser);
-            selenium.start();
-		}
-    }
 
     /**
-     * This method are invoking after selenium tests completed
-     */
-    protected void stopSelenium() {
-    	synchronized (MUTEX) {
-	        selenium.stop();
-	        selenium = null;
-    	}
-    }
-    
-    /**
      * Renders page
      */
     protected void renderPage(Template template) {
@@ -154,10 +186,9 @@
 
     }
 
-
     /**
      * Writes status message on client side
-     * 
+     *
      * @param message
      */
     public void writeStatus(String message) {
@@ -658,8 +689,5 @@
      *
      * @return
      */
-    protected String getTestUrl() {
-        return null;
-    }
-
+    public abstract String getTestUrl();
 }

Modified: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandButtonTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandButtonTest.java	2008-06-12 06:16:25 UTC (rev 9011)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/testng/AjaxCommandButtonTest.java	2008-06-12 08:50:03 UTC (rev 9012)
@@ -1,58 +1,19 @@
 package org.richfaces.testng;
 
 import org.ajax4jsf.template.Template;
-import org.richfaces.RichSeleniumTest;
 import org.richfaces.SeleniumTestBase;
 import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Parameters;
 import org.testng.annotations.Test;
 
 
-public class AjaxCommandButtonTest extends SeleniumTestBase implements RichSeleniumTest {
+public class AjaxCommandButtonTest extends SeleniumTestBase {
 
-    
-    public AjaxCommandButtonTest() {
-        super("http", "localhost", serverPort);
-    }
-    
-    /**
-     * This method are invoking before selenium tests started
-     */
-    @BeforeMethod
-    @Parameters({"browser", "filterPrefix"})
-    public void startSelenium(String browser, String filterPrefix) {
-    	super.startSelenium(browser, filterPrefix);
-    }
-    
-    
-    @BeforeMethod
-    @Parameters({"loadStyleStrategy", "loadScriptStrategy"})
-    protected void loadConfiguration(String loadStyleStrategy, String loadScriptStrategy) throws Exception {
-	super.loadConfiguration(loadStyleStrategy, loadScriptStrategy);
-    }
-    
-    /**
-     * This method are invoking after selenium tests completed
-     */
-    @AfterMethod(alwaysRun=true)
-    public void stopSelenium() {
-    	super.stopSelenium();
-    }
-
-    @Test
-    public void testAjaxCommandButtonComponent() throws Exception {
-    	_testAjaxCommandButtonComponent(Template.SIMPLE);
-    	_testAjaxCommandButtonComponent(Template.DATA_TABLE);
-    	_testAjaxCommandButtonComponent(Template.MODAL_PANEL);
-    }
-
-    private void _testAjaxCommandButtonComponent(Template template) {
+    @Test(dataProvider = "templates")
+    public void testAjaxCommandButtonComponent(Template template) {
         renderPage(template);
-    
+
     	String parentId = getParentId() + "_form:";
-    	
+
     	String buttonId = parentId + "b1";
     	boolean ajaxSingle = false;
     	boolean immediate = false;
@@ -92,10 +53,8 @@
     	waitForAjaxCompletion();
     	waitForOnCompleteHndler();
     	checkButton(buttonId, true, ajaxSingle, immediate, true, true, true, false);
-    	
-      
     }
-    
+
     private void setValidation(boolean success) {
     	StringBuffer buffer = new StringBuffer("setValidation(");
     	buffer.append(success);
@@ -127,11 +86,10 @@
     	if (result != null && result.length() > 0) {
     		Assert.fail("<a4j:commandButton> [ajaxSingle="+ajaxSingle+" ; immediate="+immediate+"] test failure caused by " + result);
     	}
-    	
     }
 
-	public String getTestUrl() {
-		return "pages/ajaxCommandButton/ajaxButtonTest.xhtml";
-	}
+    public String getTestUrl() {
+        return "pages/ajaxCommandButton/ajaxButtonTest.xhtml";
+    }
 
 }

Modified: trunk/test-applications/seleniumTest/src/test/testng/win/testng_default_default_neko.xml
===================================================================
--- trunk/test-applications/seleniumTest/src/test/testng/win/testng_default_default_neko.xml	2008-06-12 06:16:25 UTC (rev 9011)
+++ trunk/test-applications/seleniumTest/src/test/testng/win/testng_default_default_neko.xml	2008-06-12 08:50:03 UTC (rev 9012)
@@ -1,21 +1,22 @@
-<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
 <suite name="seleniumTestDDNe">
-  <test name="IEFunctionalTests">
-    <parameter name="browser" value="*iexplore"/>
-    <parameter name="loadStyleStrategy" value="DEFAULT"/>
-   <parameter name="loadScriptStrategy" value="DEFAULT"/>
-   <parameter name="filterPrefix" value="/faces/NEKO/"/>
-    <packages>
-      <package name="org.richfaces.testng" />
-    </packages>
-  </test>
-  <test name="FireFoxFunctionalTestsDDNe">
-   <parameter name="loadStyleStrategy" value="DEFAULT"/>
-   <parameter name="loadScriptStrategy" value="DEFAULT"/>
-   <parameter name="filterPrefix" value="/faces/NEKO/"/>
-    <parameter name="browser" value="*firefox"/>
-    <packages>
-      <package name="org.richfaces.testng" />
-    </packages>
-  </test>
+	<parameter name="templates" value="SIMPLE,DATA_TABLE,MODAL_PANEL" />
+	<test name="IEFunctionalTests">
+		<parameter name="browser" value="*iexplore" />
+		<parameter name="loadStyleStrategy" value="DEFAULT" />
+		<parameter name="loadScriptStrategy" value="DEFAULT" />
+		<parameter name="filterPrefix" value="/faces/NEKO/" />
+		<packages>
+			<package name="org.richfaces.testng" />
+		</packages>
+	</test>
+	<test name="FireFoxFunctionalTestsDDNe">
+		<parameter name="browser" value="*firefox" />
+		<parameter name="loadStyleStrategy" value="DEFAULT" />
+		<parameter name="loadScriptStrategy" value="DEFAULT" />
+		<parameter name="filterPrefix" value="/faces/NEKO/" />
+		<packages>
+			<package name="org.richfaces.testng" />
+		</packages>
+	</test>
 </suite>




More information about the richfaces-svn-commits mailing list