[Webtest] Re: new window

Marc Guillemot webtest@lists.canoo.com
Thu, 13 May 2004 11:48:48 +0200


Hi,

comment in text below

Dierk Koenig wrote:
> Hi,
> 
> I just got a similar bug report and investigated the issue.
> 
> The behaviour comes with links that bear the attribute
> target="_blank"
> 
> After a "click()" on such a link, HttpUnit opens those pages in a new
> "WebWindow" and adds this
> window to the open windows list. However, the
> webconversation.getCurrentPage()
> does not return this page, but still the previous one.
> 
> I'm not absolutely sure, but it seems this behaviour was introduced
> with the JavaScript support for clicklink.
> Marc: could you please verify this?

I guess that you're right.
Before the change for js support, a fully new request was performed and its result was cosdered as the current page. Now 
we let httpunit "click" the link. In the case where a target is set, it seems that httpunit doesn't update what is 
considered as the current page.

> We failed to include a test for target attributes into our suite of
> selftests.
> Now I created some and will include them in the distribution as soon as the
> issue is solved. Here it is: (html files attached)
>     <target name="testClickLinkWithTarget">
>         <testSpec name="Clicklink with Target">
>             &sharedConfiguration;
>             <steps>
>                 <invoke stepid="start"
>                     url="linkpage.html"/>
>                 <clicklink label="Link to some other Window"/>
> 				<verifytext text="new almost empty page"/>
>                 <previousresponse/>
>                 <clicklink label="Link to top Window"/>
> 				<verifytext text="new almost empty page"/>
>                 <previousresponse/>
>                 <clicklink label="Link to new Window"/>
> 				<verifytext text="new almost empty page"/>
>                 <previousresponse/>
>             </steps>
>         </testSpec>
>     </target>
> 
> This is an HttpUnit test to expose the handling there:
>     public void testBlankTarget() throws IOException, SAXException,
> MalformedURLException {
>         WebConversation wc = new WebConversation();
>         WebResponse resp =
> wc.getResponse("http://localhost:9090/selftest/linkpage.html");
>         WebLink blankLink = resp.getLinkWith("Link to new Window");
>         assertEquals("_blank", blankLink.getTarget());
>         blankLink.click();
>         WebWindow[] windows = wc.getOpenWindows();
>         String newPage =
> windows[windows.length-1].getCurrentPage().getText();
>         assertTrue(newPage, newPage.indexOf("new almost empty page") > -1);
>     }
> 
> It would be fairly easy to solve the issue in "clicklink" for the special
> case
> of "_blank". I suspect that "_top" etc. may also cause problems (e.g. with
> framesets).
> Marc, all: do you have any idea how we can do this cleanly?

The logic would be to consider as current window the one in which the content of the just clicked link is shown (the one 
you see on top when surfing with your prefered browser).
The big problem according to my tests is httpunit behavior: when calling click() on a link with target="_blank" for 
instance, the returned WebResponse is the original one, not the one called by the link.

Once again: what about htmlunit? With htmlunit this works just normally and the HtmlPage object has a method 
getEnclosingWindow().

Marc.