2 Replies Latest reply on Apr 5, 2010 12:50 PM by Adrien Adrien

    How to test link with target _blank is opened?

    Adrien Adrien Apprentice

      Hi how can i test a page is opened when target is _blank?

       

      <a id="lp" href="/pages/pub/lostpwd.jsf" target="_blank" >Mot de passe oubli&#233;&#63;</a>

       

      test:

      client.click("lp");

      //and now can i do? server.getCurrentViewID() is not the opened page .

       

      Thanks

        • 1. Re: How to test link with target _blank is opened?
          Stan Silvert Master

          Hi Adrien,

           

          Using the HtmlUnit API with JSFUnit has a section on working with multiple windows.  That will take care of the client side.

           

          server.getCurrentViewID() should work as long as the new window is using the same HttpSession.  I took a look at the JSFUnit test suite and I don't have any tests for the server side in that situation.  Please let me know what you find.

           

          Regards,

           

          Stan

          • 2. Re: How to test link with target _blank is opened?
            Adrien Adrien Apprentice

                 A sample if someone need

             

                    //link on my home page

                     <a id="lp" href="/pages/pub/lostpwd.jsf" target="_blank">Lost password</a>

             

                     WebClient webClient = jsfSession.getWebClient();       
                    HtmlPage firstPage = webClient.getPage("http://localhost/");
                    //id of the link
                    HtmlAnchor anchor = firstPage.getHtmlElementById("lp");
                    Page secondPage = anchor.click();
                    //id of button on second page "/pages/pub/lostpwd.jsf
                    assertTrue(secondPage.getWebResponse().getContentAsString().contains("lostpwd:b_getpwd"));