newbie questions about login into a page
by Arnold Maderthaner
Hi !
I just started today to use jsfunit. I have an application which needs
a login before you can do anything so I wrote a little login test
which seams to get over the login but afterwards I get an exception.
Here is my test code:
System.out.println("Starting the test");
// Send an HTTP request for the initial page
JSFSession jsfSession = new JSFSession("/index.jsp");
// A JSFClientSession emulates the browser and lets you test HTML
JSFClientSession client = jsfSession.getJSFClientSession();
// A JSFServerSession gives you access to JSF state
JSFServerSession server = jsfSession.getJSFServerSession();
// Test navigation to initial viewID
// System.out.println("Test navigation to inital viewID");
// assertEquals("/index.jsf", server.getCurrentViewID());
// Assert that the prompt component is in the component tree
and rendered
// UIComponent username = server.findComponent("j_username");
// assertTrue(username.isRendered());
System.out.println("setting username");
client.setValue("j_username", "test");
System.out.println("Setting password");
client.setValue("j_password", "test");
System.out.println("Click on login");
client.click("btLoginSubmit");
System.out.println(client.getPageAsText());
And here the exception I get:
15:06:24,935 INFO [STDOUT] 15:06:24,935 WARN [HTMLDocument]
getElementById(script1251723984932) did a getElementByName for
Internet Explorer
15:06:25,336 INFO [STDOUT] 15:06:25,336 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:25,476 INFO [STDOUT] 15:06:25,476 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:25,616 INFO [STDOUT] 15:06:25,616 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:25,676 INFO [STDOUT] 15:06:25,675 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,037 INFO [STDOUT] 15:06:26,037 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,223 INFO [STDOUT] 15:06:26,223 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,296 INFO [STDOUT] 15:06:26,296 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,400 INFO [STDOUT] 15:06:26,400 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,569 INFO [STDOUT] 15:06:26,569 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,602 INFO [STDOUT] 15:06:26,602 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,614 INFO [STDOUT] 15:06:26,614 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,682 INFO [STDOUT] 15:06:26,682 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,696 INFO [STDOUT] 15:06:26,695 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,710 INFO [STDOUT] 15:06:26,710 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,815 INFO [STDOUT] 15:06:26,815 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,835 INFO [STDOUT] 15:06:26,835 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,886 INFO [STDOUT] 15:06:26,886 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:26,909 INFO [STDOUT] 15:06:26,909 WARN [HtmlPage] Obsolete
content type encountered: 'text/javascript'.
15:06:30,553 INFO [STDOUT] 15:06:30,553 INFO
[NicelyResynchronizingAjaxController] Re-synchronized call to http://localhost:8080/PatientViewer/patientviewer/patientviewer.jsf
15:06:33,555 ERROR [[ServletRedirector]] Servlet.service() for servlet
ServletRedirector threw exception
java.lang.IllegalStateException: No script object associated with the
Page
at com.gargoylesoftware.htmlunit.html.DomNode.getScriptObject
(DomNode.java:869)
at com.gargoylesoftware.htmlunit.html.DomNode.getScriptObject
(DomNode.java:871)
at com.gargoylesoftware.htmlunit.html.HtmlElement.getEventHandler
(HtmlElement.java:834)
at
com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded
(HtmlPage.java:1247)
at com.gargoylesoftware.htmlunit.html.HtmlPage.cleanUp(HtmlPage.java:
218)
at com.gargoylesoftware.htmlunit.WebWindowImpl.destroyChildren
(WebWindowImpl.java:159)
at com.gargoylesoftware.htmlunit.TopLevelWindow.close
(TopLevelWindow.java:106)
at org.jboss.jsfunit.framework.WebClientSpec.valueUnbound
(WebClientSpec.java:308)
at org.apache.catalina.session.StandardSession.removeAttributeInternal
(StandardSession.java:1649)
at org.apache.catalina.session.StandardSession.expire
(StandardSession.java:756)
at org.apache.catalina.session.StandardSession.expire
(StandardSession.java:660)
at org.apache.catalina.session.StandardSession.invalidate
(StandardSession.java:1111)
at org.apache.catalina.session.StandardSessionFacade.invalidate
(StandardSessionFacade.java:150)
at org.jboss.jsfunit.framework.JSFUnitServletRedirector.cleanUp
(JSFUnitServletRedirector.java:68)
at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost
(JSFUnitServletRedirector.java:47)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0
(ServletTestRedirector.java:72)
at
org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice
(ServletTestRedirector.java:217)
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:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter
(JSFUnitFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter
(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke
(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke
(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke
(AuthenticatorBase.java:524)
at org.jboss.web.tomcat.security.JaccContextValve.invoke
(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke
(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke
(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service
(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process
(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
446)
at java.lang.Thread.run(Thread.java:637)
Anyone can help on this topic ?
yours
Arnold
15 years, 3 months
Login form with spring security
by Bernd Winterstein
Hi,
I'm trying to write a test for a JSF application with spring security.
I see in the logfiles that the test successfully passes the login
dialog and the welcome page (secured) is loaded.
Nevertheless the test quits with an exception when creating the
JSFSession instance:
IllegalStateException: getAttribute Session already invalidated at
org.apache.catalina.session.StandardSession.getAttribute(StandardSession.java:1032)
at
org.apache.catalina.session.StandardSessionFacade.getAttribute(StandardSessionFacade.java:110)
at
org.jboss.jsfunit.framework.FacesContextBridge.getCurrentInstance(FacesContextBridge.java:56)
at
org.jboss.jsfunit.jsfsession.JSFServerSession.pageCreated(JSFServerSession.java:213)
at
org.jboss.jsfunit.jsfsession.JSFServerSession.<init>(JSFServerSession.java:56)
at
org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:83) at
JSFUnitTest.testInitialPage(JSFUnitTest.java:43)
regards,
Bernd
My test code is:
WebClientSpec wcSpec = new WebClientSpec("/pages/summary.faces",
BrowserVersion.FIREFOX_3);
FormAuthenticationStrategy formAuth = new
FormAuthenticationStrategy("test", "test", "loginButton",
"j_username", "j_password");
wcSpec.setInitialRequestStrategy(formAuth);
JSFSession jsfSession = new JSFSession(wcSpec); // <-- CRASHES
JSFClientSession client = jsfSession.getJSFClientSession();
RichFacesClient ajaxClient = new RichFacesClient(client);
15 years, 4 months