Add a function to do a javascript function call. Retrieving the result of the call would be nice to have (ie for asserting its content or passing it to another call)
Just to bring some contribution I made a first trial of implementation of this function. Not sure all is done the right way. Anyway, here it is (from HtmlUnitDialog) :
I will look at adding this to JWebUnit 2.1. While not strictly part of web application testing (we are testing black-box), it would be useful to have the ability to white-box test the Javascript.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=1623716
Originator: YES
Julien,
Just to bring some contribution I made a first trial of implementation of this function. Not sure all is done the right way. Anyway, here it is (from HtmlUnitDialog) :
public Object executeJavascriptIfPossible(String sourceCode, String elementId)
{
Page page = win.getEnclosedPage();
if (page instanceof HtmlPage)
{
HtmlPage htmlPage = (HtmlPage) page;
HtmlElement htmlElement = elementId == null ? null : getElement(elementId);
ScriptResult scriptResult = htmlPage.executeJavaScriptIfPossible(sourceCode, "jsWebUnit", true, htmlElement);
Page newPage = scriptResult.getNewPage();
if (null != newPage)
{
win.setEnclosedPage(newPage);
form = null;
}
return scriptResult.getJavaScriptResult();
}
return null;
}
Amicalement,
Bernard
I will look at adding this to JWebUnit 2.1. While not strictly part of web application testing (we are testing black-box), it would be useful to have the ability to white-box test the Javascript.