-
1. How to manage Login Session using JSFUnit
ssilvert Mar 28, 2011 3:56 PM (in response to samssams)That was a very old post and I'm pretty sure it was before we integrated the Authentication Strategy classes. Have you seen this article about managing logins?
Stan
-
2. How to manage Login Session using JSFUnit
samssams Mar 28, 2011 4:05 PM (in response to ssilvert)Yes I did see it but login authentication is in seperate JSFUnit test(for testing I have 2 tests 1st for login and 2nd to create member in same class).
So when 2nd test is being excecuted it has new server session object becuase we are using again below code to create new JSFSession. Thanks a lot for your reply.
WebClientSpec wcSpec = new WebClientSpec("url to request");
wcSpec.setInitialRequestStrategy(new WebSphereRequestStrategy());
JSFSession jsfSession = new JSFSession(wcSpec);
-
3. How to manage Login Session using JSFUnit
ssilvert Mar 28, 2011 4:30 PM (in response to samssams)You will need to incorporate the WebSphere logic and login logic into one single InitialRequestStrategy.
You can not expect to stay logged in from one JSFSession to the next. Each JSFSession starts with a clean HttpSession. If the session were dirty it would not be a valid test. So you must log in for each new JSFSession. You just build an InitialRequestStrategy that meets your needs and then reuse that code each time you need a JSFSession.
Stan
-
4. How to manage Login Session using JSFUnit
samssams Mar 29, 2011 10:30 AM (in response to ssilvert)WebClientSpec is only take one url as argument but we have 2 url one for login and one for actual test. how we can use both url togther.
if we start customizing the JSF unit looks like we need to cusmmtomize erverything e.g. InitialRequestStrategy , Page , WebClientSpec etc.
Could you plz post something that will help us to proceed on this.
-
5. Re: How to manage Login Session using JSFUnit
ssilvert Mar 29, 2011 12:38 PM (in response to samssams)You only need to write an InitialRequestStrategy. Start by putting the URL you eventually want to go to inside WebClientSpec and proceed as shown:
WebClientSpec wcSpec = new WebClientSpec("/mysecurepage.jsf"); MyInitialRequestStrategy myStrategy = new MyInitialRequestStrategy(); wcSpec.setInitialRequestStrategy(myStrategy); JSFSession jsfSession = new JSFSession(wcSpec);
JSFSession will call MyInitialRequestStrategy to start the session.
MyInitialRequestStrategy should probably extend SimpleInitialRequestStrategy. Inside your doInitialRequest() method, call wcSpec.getWebClient() and use the HtmlUnit API to do whatever login is needed. You can hit any URLs you want and do any kind of setup needed before eventually calling super.doInitialRequest(wcSpec).
Just make sure that you get your WebClient object from wcSpec.getWebClient(). If you create a WebClient on your own then JSFUnit won't be able to find your session.
Stan
-
6. Re: How to manage Login Session using JSFUnit
samssams Mar 29, 2011 11:26 PM (in response to ssilvert)I am trying to customize InitialRequestStrategy by extending SimpleInitialRequestStrategy so I can use login thing before the actual test case but I am getting exception.when i disbaled javascript by webClient.setJavaScriptEnabled(false); execution will pass that line but on submit its throwing exception for some javascript method not found.
import java.io.IOException;
import java.net.URL;
import org.jboss.jsfunit.framework.SimpleInitialRequestStrategy;
import org.jboss.jsfunit.framework.WebClientSpec;
import org.jboss.jsfunit.framework.WebConversationFactory;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class TestRequestStrategy extends SimpleInitialRequestStrategy{
@Override
public Page doInitialRequest(WebClientSpec wcSpec) throws IOException {
WebClient webClient = wcSpec.getWebClient();
URL url = new URL(WebConversationFactory.getWARURL()+"url.faces");
// I tried String version too
HtmlPage page = webClient.getPage(url); // this line throws exception.
HtmlForm form = page.getFormByName("formname");
form.getElementById("test").setAttribute("value", "test");
form.getElementById("testusr").setAttribute("value", "test");
form.getElementById("testpass").setAttribute("value", "test");
form.getElementById("submitId").click();
return super.doInitialRequest(wcSpec);
}
}
Automation server can't create object (script in " .... URL..."s from (20, 31) to (152, 11)#25)
======= EXCEPTION START ========
Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException]
com.gargoylesoftware.htmlunit.ScriptException: Automation server can't create object (script in " .... URL..."s from (20, 31) to (152, 11)#25)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:601)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:531)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:906)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:197)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:216)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:696)
at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:885)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:890)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1156)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:212)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:436)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:369)
at ----------------------------------------doInitialRequest(TestInitialRequestStrategy.java:21)
at org.jboss.jsfunit.framework.WebClientSpec.doInitialRequest(WebClientSpec.java:259)
at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:81)
at -----------------------------------------------------------------------------------
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:119)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:445)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:504)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:301)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:275)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: Automation server can't create object (script in " .... URL..."s from (20, 31) to (152, 11)#25)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.runtimeError(StrictErrorReporter.java:81)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:961)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:1017)
at com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject.jsConstructor(ActiveXObject.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:172)
at net.sourceforge.htmlunit.corejs.javascript.FunctionObject.call(FunctionObject.java:419)
at net.sourceforge.htmlunit.corejs.javascript.BaseFunction.construct(BaseFunction.java:374)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1748)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:845)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:429)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:269)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3162)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:82)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:559)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:524)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)
... 70 more
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: Automation server can't create object (script in " .... URL..."s from (20, 31) to (152, 11)#25)
at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.runtimeError(StrictErrorReporter.java:81)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:961)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:1017)
at com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject.jsConstructor(ActiveXObject.java:130)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:172)
at net.sourceforge.htmlunit.corejs.javascript.FunctionObject.call(FunctionObject.java:419)
at net.sourceforge.htmlunit.corejs.javascript.BaseFunction.construct(BaseFunction.java:374)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1748)
at script.getmachinename(script in " .... URL..."s from (20, 31) to (152, 11):25)
at script(onload event for HtmlBody[<body onload="ClearField();if(strComputer==null){getmachinename();getClubNumber(); settingFocus();}">] in " .... URL..."s)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:845)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:429)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:269)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3162)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:82)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:559)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:524)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:531)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:906)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:197)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:216)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:696)
at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:885)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:890)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1156)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:212)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:436)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:369)
---------------------------------------------------------------------------------------------------------
at org.jboss.jsfunit.framework.WebClientSpec.doInitialRequest(WebClientSpec.java:259)
at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:81)
------------------------------------------------------------------------------------------
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:119)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:445)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:504)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:301)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:275)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
== CALLING JAVASCRIPT ==
function () {
[native code, arity=0]
}
-
7. Re: How to manage Login Session using JSFUnit
ssilvert Mar 30, 2011 7:59 AM (in response to samssams)That's an HtmlUnit problem. A few things to try:
- Make sure you are using HtmlUnit 2.8 and not an earlier version
- Set the BrowserVersion to a different value
- Google for the error message (htmlunit "Automation server can't create object")
- Ask for help on the HtmlUnit mailing list
Stan
-
8. How to manage Login Session using JSFUnit
samssams Mar 30, 2011 12:45 PM (in response to ssilvert)Above error looks like pages was using some active x object so when we used jacob.jar(and dll) and set webClient.setActiveXNative(true); error was gone but now even I have commented that line I am not getting that error any more even after re-starting the server. So now I am good on that error.
In below InitialRequestStrategy when I use wcSpec.getWebClient(); then on submit of the form using form.getElementById("").click(); is not executing action call at all. looks like not submitting the form. but when I use new WebClient(BrowserVersion.INTERNET_EXPLORER_8); it will go to login action and execute it and in Both cases server.getFacesContext() is null where JSFSession jsfSession = new JSFSession(wcSpec); and
JSFServerSession server = jsfSession.getJSFServerSession();
I have feeling that since application and test is deployed on websphere server actual application code is using some different FacesConectext and JSFUnit is using some different FacesContextIn debug I see some bean getting populated with values but when we try to get thise value back it will show null.
Thanks a lot for your help.
public class testInitialRequestStrategy extends SimpleInitialRequestStrategy{
@Override
public Page doInitialRequest(WebClientSpec wcSpec) throws IOException {
WebClient webClient = wcSpec.getWebClient();
//WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
BrowserVersion version = webClient.getBrowserVersion();
//webClient.setActiveXNative(true);
URL url = new URL(WebConversationFactory.getWARURL()+"url.faces");
//webClient.setJavaScriptEnabled(true);
HtmlPage page = webClient.getPage(url);
HtmlForm form = page.getFormByName("");
form.getElementById("").setAttribute("value", "");
form.getElementById("").setAttribute("value", "");
form.getElementById("").setAttribute("value", "");
form.getElementById("").click();
return super.doInitialRequest(wcSpec);
}
}
-
9. How to manage Login Session using JSFUnit
samssams Mar 30, 2011 1:02 PM (in response to samssams)addional code..
public void Test() {
WebClientSpec wcSpec = new WebClientSpec("/url2.faces",BrowserVersion.INTERNET_EXPLORER_8);
wcSpec.setInitialRequestStrategy(new testInitialRequestStrategy());
----
}
-
10. How to manage Login Session using JSFUnit
samssams Mar 30, 2011 5:46 PM (in response to samssams)My Problem resolved. I forgot to add cookie for websphere. If webpage has activex objext you need jacob.jar and related DLL. +
import java.io.IOException;
import java.net.URL;
import org.jboss.jsfunit.framework.SimpleInitialRequestStrategy;
import org.jboss.jsfunit.framework.WebClientSpec;
import org.jboss.jsfunit.framework.WebConversationFactory;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class TestInitialRequestStrategy extends SimpleInitialRequestStrategy{
@Override
public Page doInitialRequest(WebClientSpec wcSpec) throws IOException {
String jsessionid = wcSpec.removeCookie("JSESSIONID");
// cache ID is 0000 by default
wcSpec.addCookie("JSESSIONID", "0000" + jsessionid);
WebClient webClient = wcSpec.getWebClient();
//WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
webClient.setActiveXNative(true);
URL url = new URL(WebConversationFactory.getWARURL()+"url.faces");
webClient.setJavaScriptEnabled(true);
HtmlPage page = webClient.getPage(url);
HtmlForm form = page.getFormByName("AuthForm");
form.getElementById("id1").setAttribute("value", "value1");
form.getElementById("id2").setAttribute("value", "value2");
form.getElementById("id3").setAttribute("value", "value3");
form.getElementById("buttonid").click();
return super.doInitialRequest(wcSpec);
}
}