views:

106

answers:

2

I am using Htmlunit (browser automation/testing tool) to go through a series of links or perform a set of actions on a page. At some point after this I want to see the resulting page in a browser (internet explorer or firefox etc.) How can I do this. ? Thank you Friends...

A: 

I hope I got you correctly.

This is my solution:

WebClient wc = new WebClient();

HtmlPage page = wc.getPage("http://stackoverflow.com/");

//Get page as Html
String htmlBody = page.getWebResponse().getContentAsString();

//Save the response in a file
String filePath = "c:/temp/out.html";
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(filePath)));
bw.write(htmlBody);
bw.close();

//Open the page with a browser
Runtime.getRuntime().exec("C:/Program Files/Internet Explorer/iexplore.exe " + filePath);

Hope that helps.

Avi Y
A: 

You can also use htmlPage.save(File) (which automatically saves images) before executing real browser

Ahmed Ashour