1

I have started learning HTTPUNIT and found one basic example.

In this example it will visit this site. And it will search for the link containing HTTPUNIT. And it will print the number of links on the HTTPUNIT. I tried this example on my machine and it works.

        WebConversation wc = new WebConversation();
        WebRequest request = new GetMethodWebRequest( "http://www.meterware.com" );
        WebResponse response = wc.getResponse( request );
        WebLink httpunitLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "HttpUnit" );
        response = httpunitLink.click();
        System.out.println( "The HttpUnit main page contains " + response.getLinks().length + " links" );

Now i have changed the code to

  WebConversation wc = new WebConversation();
  WebRequest request = new GetMethodWebRequest( "http://www.google.com" );
  WebResponse response = wc.getResponse( request );
  WebLink httpunitLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "News" );
  response = httpunitLink.click();
  System.out.println( "The HttpUnit main page contains " + response.getLinks().length + " links" );

And now it is giving the error below.

ConversionError: The undefined value has no properties. (httpunit; line 4)

Why it is not able to visit google news and get the number of links?

Thank you in advance.

skaffman
  • 398,947
  • 96
  • 818
  • 769
vikiiii
  • 9,246
  • 9
  • 49
  • 68

1 Answers1

2

The google home page is rendered from JavaScript.

HTTPUNIT has partial support for JavaScript. If you need to test pages with heavy JavaScript, take a look at Selenium

Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
  • More specifically, "WebDriver", which is part of Selenium. – djangofan Mar 31 '12 at 16:24
  • @Devon Is it something like QTP? ""Quick Test Professional" – vikiiii Mar 31 '12 at 16:34
  • @vikii Conceptually similar. Selenium Webdriver hooks into the browser to let you control its interaction with a website. – Devon_C_Miller Mar 31 '12 at 18:04
  • @Devon Can you provide me an example where i can see the example? I have never heard of Selenium Webdriver.So dont know where to begin with. – vikiiii Apr 02 '12 at 08:14
  • @vikiii I won't have time until later in the week, but I'll update this with an example. Meanwhile, have a read through http;//seleniumhq.org/docs – Devon_C_Miller Apr 03 '12 at 04:19
  • @Devon thanks.i will do it.Let me know when you have develop an example.It will be good if you take an example of www.google.com itself. – vikiiii Apr 04 '12 at 14:44