The problem that we face is when there is a javascript function refering to a variable/ function of an included js file, we get a ScriptException.
For example,
<script language="JavaScript" src="someScript.js" />
<script language="JavaScript">
function testFunction() {
var retValue = someFunction(); //Here some function is part of "SomeScript.js"
}
</script>
Regards
pooja
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the feedback. I've tried this with the latest svn trunk version with the following test code and it works. You might want to use the latest
svn trunk version or give more specific information on your setup and why it fails.
I have personally used httpunit with UML2PHP which by default uses quite a bit of javascript sources and did not run into this problem.
/**
* test for function in external javascript
* https://sourceforge.net/forum/forum.php?thread_id=1406498&forum_id=20294
* @throws Exception
*/
public void testJavaScriptFromSource() throws Exception {
defineResource( "someScript.js","function someFunction() {\n"+
" alert('somefunction called')"+
"}\n");
defineResource( "Script.html","<html><head>\n"+
"<script language='JavaScript' src='someScript.js' />\n"+
"<script language='JavaScript'>\n" +
"function testFunction() {\n"+
" var retValue = someFunction(); //Here some function is part of SomeScript.js\n"+
"}\n"+
"</script></head><body onload='testFunction()'></body></html>");
WebConversation wc = new WebConversation();
WebResponse response = wc.getResponse( getHostPath() + "/Script.html" );
// com.meterware.httpunit.ScriptException: Event 'testFunction()' failed: org.mozilla.javascript.EcmaError: ReferenceError: "someFunction" is not defined. (httpunit#1)
String alert1=wc.popNextAlert();
assertEquals("somefunction called",alert1);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The problem that we face is when there is a javascript function refering to a variable/ function of an included js file, we get a ScriptException.
For example,
<script language="JavaScript" src="someScript.js" />
<script language="JavaScript">
function testFunction() {
var retValue = someFunction(); //Here some function is part of "SomeScript.js"
}
</script>
Regards
pooja
Thanks for the feedback. I've tried this with the latest svn trunk version with the following test code and it works. You might want to use the latest
svn trunk version or give more specific information on your setup and why it fails.
I have personally used httpunit with UML2PHP which by default uses quite a bit of javascript sources and did not run into this problem.
/**
* test for function in external javascript
* https://sourceforge.net/forum/forum.php?thread_id=1406498&forum_id=20294
* @throws Exception
*/
public void testJavaScriptFromSource() throws Exception {
defineResource( "someScript.js","function someFunction() {\n"+
" alert('somefunction called')"+
"}\n");
defineResource( "Script.html","<html><head>\n"+
"<script language='JavaScript' src='someScript.js' />\n"+
"<script language='JavaScript'>\n" +
"function testFunction() {\n"+
" var retValue = someFunction(); //Here some function is part of SomeScript.js\n"+
"}\n"+
"</script></head><body onload='testFunction()'></body></html>");
WebConversation wc = new WebConversation();
WebResponse response = wc.getResponse( getHostPath() + "/Script.html" );
// com.meterware.httpunit.ScriptException: Event 'testFunction()' failed: org.mozilla.javascript.EcmaError: ReferenceError: "someFunction" is not defined. (httpunit#1)
String alert1=wc.popNextAlert();
assertEquals("somefunction called",alert1);
}