commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r988279 - /commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml
Date Mon, 23 Aug 2010 19:45:26 GMT
Author: jbeard
Date: Mon Aug 23 19:45:26 2010
New Revision: 988279

URL: http://svn.apache.org/viewvc?rev=988279&view=rev
Log:
Added task for running in-browser unit tests.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml?rev=988279&r1=988278&r2=988279&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/build.xml Mon Aug 23 19:45:26 2010
@@ -22,7 +22,7 @@
 	<property name="selenium_host" value="localhost"/>
 	<property name="selenium_port" value="4444"/>
 	<property name="selenium_root_url" value="http://localhost:8081/"/>
-	<property name="selenium_timeout" value="10000"/>
+	<property name="selenium_timeout" value="20000"/>
 
 	<property name="selenium_firefox_id" value="*firefox"/>
 	<property name="selenium_ie_id" value="*iexplore"/>
@@ -254,7 +254,7 @@
 						window.oldDohOnEnd = window.doh._onEnd;
 						window.doh._onEnd = function() { window.dohIsComplete = true; window.oldDohOnEnd.apply(window.doh);
};
 					</script>
-					<script src="../test/testHelpers.js" type="text/javascript">true;</script>
+					<script src="../../../../test/testHelpers.js" type="text/javascript">true;</script>
 					<script>
 						var resultText;
 
@@ -689,6 +689,108 @@
 		]]></rhinoscript>
 	</target>
 
+
+	<target name="run-in-browser-unit-tests-with-selenium" depends="preprocess-stylesheets,generate-in-browser-unit-test-html">
+		<rhinoscript><![CDATA[
+			//TODO: consolidate this code
+			function unitTestWithSelenium(sel,url,timeout){
+				sel.open(url);
+
+				sel.waitForPageToLoad("5000");
+				
+				// wait for all the tests to finish
+				sel.waitForCondition("window.dohIsComplete", timeout );
+				
+				// get the results
+				var testCount = Number(sel.getEval("window.doh._testCount"));
+				var failCount = Number(sel.getEval("window.doh._failureCount"));
+				var errorCount = Number(sel.getEval("window.doh._errorCount"));
+				
+				return {
+					testCount:testCount,
+					failCount:failCount,
+					errorCount:errorCount,
+					testsPassed:(testCount - failCount - errorCount)
+				};
+			}
+
+			print("Running Selenium unit tests...");
+
+			var unitTestResults = [];
+
+			browsers.split(",").forEach(function(browserName){
+
+				print("Running test for " + browserName + "...");
+
+				var browserId = project.getProperty("selenium_" + browserName + "_id");
+
+				var bSel = new Packages.com.thoughtworks.selenium.DefaultSelenium(selenium_host, selenium_port,
browserId, selenium_root_url);
+
+				print("bSel",bSel);
+
+				bSel.start();
+
+				//list comprehension to get the cartesian product
+				var configurations = [{forIE:forIE,backend:backend,testPath:testPath}
+					for each (forIE in project.getProperty("for-ie").split(','))
+					for each (backend in backends.split(','))
+					for each (testPath in Array.prototype.slice.call(scxml_tests_xml.list()))];
+
+				//use pattern matching in the parameter
+				configurations.forEach(function({forIE:forIE,backend:backend,testPath:testPath}){
+		
+					print("forIE:"+forIE+","+"backend:"+backend+","+"testPath:"+testPath);
+
+					//get path to html test
+					//@{for-ie}-@{backend}-@{test-path}-unit-test-html-location
+					var unitTestHtmlLocationPropertyName=forIE + "-" + backend + "-" + testPath + "-in-browser-unit-test-html-location";
+					var unitTestHtmlLocation = project.getProperty(unitTestHtmlLocationPropertyName);
+
+					print("unitTestHtmlLocation:"+unitTestHtmlLocation);
+					
+					//ensure we are not testing an ie html test
+					//on a non-ie browser
+					if(browserName==ie_browser_name && forIE==is_for_ie ||
+						browserName!=ie_browser_name && forIE==is_not_for_ie){
+
+						var unitTestResult = unitTestWithSelenium(bSel,unitTestHtmlLocation,selenium_timeout);

+
+						print("unitTestResult:" + unitTestResult); 
+
+						var unitTestResultObj = {
+							data : unitTestResult,
+							browser : browserName,
+							scxmlTest : testPath,
+							backend : backend
+						};
+
+						unitTestResults.push(unitTestResultObj);
+
+						//report errors and failures that may occur
+						if(unitTestResult.failCount || unitTestResult.errorCount){
+							print("UNIT TEST ERROR");
+							//TODO: add better error handling here that integrates with Ant
+						}
+
+					}
+				});
+
+				bSel.stop();
+			});
+
+			var totalTests = unitTestResults.reduce(function(a,b){return a + b.data.testCount},0);
+			var totalTestsFailed = unitTestResults.reduce(function(a,b){return a + b.data.errorCount},0);
+			var totalTestsErrored = unitTestResults.reduce(function(a,b){return a + b.data.failCount},0);
+			var totalTestsPassed = unitTestResults.reduce(function(a,b){return a + b.data.testsPassed},0);
+
+			print("Test Results:");
+			print("Total Tests: " + totalTests);
+			print("Total Tests Failed: " + totalTestsFailed);
+			print("Total Tests Errored: " + totalTestsErrored);
+			print("Total Tests Passed: " + totalTestsPassed);
+		]]></rhinoscript>
+	</target>
+
 	<target name="run-unit-tests-with-rhino" depends="generate-javascript">
 		<rhinoscript>
 			//load requirejs



Mime
View raw message