|
From: <et...@us...> - 2011-08-01 11:13:46
|
Revision: 4432
http://mxquery.svn.sourceforge.net/mxquery/?rev=4432&view=rev
Author: etterth
Date: 2011-08-01 11:13:40 +0000 (Mon, 01 Aug 2011)
Log Message:
-----------
added JavaScript tests
Added Paths:
-----------
trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/JsApi.java
trunk/XQIB_Testing/webapps/test/js-call1.html
trunk/XQIB_Testing/webapps/test/jsapi1.html
Added: trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/JsApi.java
===================================================================
--- trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/JsApi.java (rev 0)
+++ trunk/XQIB_Testing/src/ch/ethz/mxquery/browsertests/JsApi.java 2011-08-01 11:13:40 UTC (rev 4432)
@@ -0,0 +1,46 @@
+package ch.ethz.mxquery.browsertests;
+
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import ch.ethz.mxquery.testsuite.XQueryTestBase;
+
+public class JsApi extends XQueryTestBase {
+
+
+ @Test
+ /**
+ * call js from xqib
+ */
+ public void js_call() throws Exception {
+ driver.get("http://127.0.0.1:8090/test/js-call1.html");
+ String resultstr = driver.findElementById("a").getText();
+ Assert.assertEquals("the text was \"XQIB\"", resultstr);
+
+ }
+
+ @Test
+ /**
+ * call xqib from js
+ */
+ public void js_api() throws Exception {
+ driver.get("http://127.0.0.1:8090/test/jsapi1.html");
+ WebElement button = driver.findElementById("button");
+ button.click();
+
+ List<WebElement> result = driver.findElementsByXPath("//div[@id='output']/div");
+
+ Assert.assertEquals(result.size(), 2);
+ Assert.assertEquals(result.get(0).getText(),"div generated by XQIB with \"Some Text\" which was passed from JS");
+ Assert.assertEquals(result.get(1).getText(),"div generated by XQIB with \"Some more text\" which was passed from JS");
+
+
+
+ };
+
+}
Added: trunk/XQIB_Testing/webapps/test/js-call1.html
===================================================================
--- trunk/XQIB_Testing/webapps/test/js-call1.html (rev 0)
+++ trunk/XQIB_Testing/webapps/test/js-call1.html 2011-08-01 11:13:40 UTC (rev 4432)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+<script type="text/javascript">
+ foo = function (arg1){ return 'the text was "' + arg1 + '"';};
+</script>
+ <script type="application/xquery">
+ let $x := b:js-call('window.foo', string(b:dom()/id('a')/text()))
+ return
+ replace value of node b:dom()/id('a') with $x
+ </script>
+ </head>
+ <body>
+ <h1 id='a'>XQIB</h1>
+ </body>
+</html>
Added: trunk/XQIB_Testing/webapps/test/jsapi1.html
===================================================================
--- trunk/XQIB_Testing/webapps/test/jsapi1.html (rev 0)
+++ trunk/XQIB_Testing/webapps/test/jsapi1.html 2011-08-01 11:13:40 UTC (rev 4432)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>XQIB: Sample page</title>
+ <meta charset="UTF-8"/>
+ <link href="style.css" rel="stylesheet" type="text/css">
+ <script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
+ <script type="application/xquery" >
+ module namespace m = "http://www.XQIB.org/module";
+
+ declare function m:generateDiv($node as node()+) {
+ for $x in $node/text()
+ return
+ <div>{concat('div generated by XQIB with "',$x,'" which was passed from JS')}</div>
+ };
+ </script>
+ <script type="text/javascript" >
+ handle = function () {
+ var output = xqib.call('http://www.XQIB.org/module','generateDiv',document.getElementsByTagName('h1'))
+ for (i=0;i<output.length;i++){
+ document.getElementById('output').appendChild(output[i]);
+ }
+ };
+ </script>
+ </head>
+ <body>
+ <a href="index.html"><< Index</a>
+ <h1>Some Text</h1>
+ <h1>Some more text</h1>
+ <div><a href="ModuleImport_new.html">Page</a> | <a href="ModuleImport_new_source.html">Source</a></div>
+ <input type='button' value='Test calling XQIB' onclick='handle()' id='button'/>
+<div id='output' />
+ </body>
+</html>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|