9 Replies Latest reply on May 25, 2009 8:32 AM by nerrve

    client.getContentPage is about:blank

      Hi,
      Im trying to run the following piece of code

      WebClientSpec webClientSpec = new WebClientSpec("/tests.jsf", BrowserVersion.INTERNET_EXPLORER_7);
      JSFSession jsfSession = new JSFSession(webClientSpec);
      JSFServerSession server = jsfSession.getJSFServerSession();
      JSFClientSession client = jsfSession.getJSFClientSession();
      assertEquals("/tests.jsp", server.getCurrentViewID());
      HtmlPage htmlPage = (HtmlPage) client.getContentPage();


      What seems to be wierd is that the
      client.getContentPage
      seems to be pointing to an html page as simple as

      <?xml version="1.0" encoding="ISO-8859-1"?>
      < h.t.m.l /> ( . added purposely)

      Is there something that i am doing wrong???

      Thanks


        • 1. Re: client.getContentPage is about:blank
          ssilvert

          I don't see anything wrong in what you posted. Does the page render properly when you hit /tests.jsf from the browser?

          What do you mean by (. added purposely)? What is that and what is its purpose?

          Stan

          • 2. Re: client.getContentPage is about:blank

            Sorry about the (.)
            Actually the html tag was not rendering in the post, so i had to separate the letters out with dots :)

            The page /tests.jsf renders perfectly well from the browser.

            Ill get back here with some more information soon.

            Thanks

            • 3. Re: client.getContentPage is about:blank

              Hi,
              While analyzing the requests from the browser, i found that there were a few requests send to another servlet which effectively bypasses the faces servlet.
              This servlet doesnt return anything.

              So, the original page to which the request was forwarded i.e tests.jsf, is destroyed, and replaced by about:blank
              Ref: WebWindowImpl#setEnclosedPage of htmlunit

              Is there any way i can stop this from happening by setting some property etc etc? Or do you have something else in mind?

              Thanks for your help.

              • 4. Re: client.getContentPage is about:blank
                ssilvert

                Are you using JSFUnit 1.0.0.GA? That is the kind of problem I used to see in one of the early beta versions. The way things are now, HtmlUnit should make sure that the final Page object returned is the same one you would see in the browser.

                Are you using the latest HtmlUnit jar?

                I could make it possible to replace the JSFUnitWebConnection with your own custom version. That would give you more control over the final Page object returned form getContentPage(). But that would be a pretty radical step. I'd rather figure out why HtmlUnit isn't behaving properly. Is there any way you can create a small test app that demonstrates the problem?

                Stan

                • 5. Re: client.getContentPage is about:blank

                  Yes. I am using the GA version. Although still using HtmlUnit 2.4 as suggested on the JSFUnit page.
                  Ill try upgrading to 2.5 and see if i can reproduce it.

                  Still working on identifying 'exactly' what triggers this behavior. Ill post back with more 'exact' information. :)
                  (Probably with some html this time)

                  Thanks

                  • 6. Re: client.getContentPage is about:blank

                    Hi,
                    I tried upgrading the HtmlUnit jars but to no avail.

                    Also, the problem is because of an element.

                    This element is created dynamically after the page has loaded and its source points to a jsp with the same context path as tests.jsp (My bad here - i had earlier pointed out that it points to another servlet). What i also noticed was that even if you leave the src blank, it shows the same behavior.

                    Is there a quick hack here that i can do?

                    • 7. Re: client.getContentPage is about:blank

                      Yikes!!! My earlier post became a victim of the i.frame tag being rendered...
                      Anyways, Im posting it again...

                      I tried upgrading the HtmlUnit jars but to no avail.

                      Also, the problem is because of an iframe element.

                      This element is created dynamically after the page has loaded and its source points to a jsp with the same context path as tests.jsp (My bad here - i had earlier pointed out that it points to another servlet). What i also noticed was that even if you leave the src blank, it shows the same behavior.

                      Is there a quick hack here that i can do?

                      • 8. Re: client.getContentPage is about:blank
                        ssilvert

                        So perhaps HtmlUnit is leaving you inside this new iFrame?

                        You can explore the frames in the page by calling HtmlPage.getFrames().

                        To tell you the truth, I'm not sure I have a good handle on your problem. An example would be helpful. You also might want to ask about this on the HtmlUnit mailing list since this appears to be an HtmlUnit issue.

                        Stan

                        • 9. Re: client.getContentPage is about:blank

                          Hi,
                          Let me explain my scenario further
                          I had a page like this

                          <h t m l>
                          <b o d y>
                          // Whatever
                          <i f r a m e src="" >
                          < /b o d y>
                          </h t m l>


                          The iframe was added by javascript after the page was loaded.
                          On click on some links of the page, it would download a page and put it in the iframe by setting the right src attribute.

                          Anyways, this is what eventually worked for me

                          HtmlPage htmlPage = (HtmlPage) client.getContentPage();
                          HtmlPage enclosedPage = (HtmlPage)htmlPage.getEnclosingWindow().getParentWindow().getEnclosedPage();


                          Thanks for all ur help till date!!