2

I want to simulate opening a web page in java, I know I can do this to actually open the page in my browser on my computer,

String htmlFilePath = "path/to/html/file.html"; // path to your new file
File htmlFile = new File(htmlFilePath);

// open the default web browser for the HTML page
Desktop.getDesktop().browse(htmlFile.toURI());

// if a web browser is the default HTML handler, this might work too
Desktop.getDesktop().open(htmlFile);

But is there a way to simulate it so I don't actually see it open on my computer, but it still evaluates like someone did open the web page.

Or if that is not possible what would be the easiest way to physically open it on my computer and then have a way of getting a callback so that I know when the page has been loaded?

Thanks

spen123
  • 3,464
  • 11
  • 39
  • 52

2 Answers2

2

There are several ways to emulate an HTTP client (such as a web browser):

  1. Jersey (Java) - https://jersey.java.net/documentation/latest/client.html
  2. Apache HTTPClient (Java) - https://hc.apache.org/
  3. JMeter (Java) - Use JMeter to record an HTTP request and replay it as a test - https://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf
  4. Selenium (browser plugin) - http://www.seleniumhq.org/
  5. CURL (command line tool) - http://curl.haxx.se/

I do recommend Jersey in your case. It is a tool especially designed for REST. So it may even help server-side development.

I know you specifically asked for a Java solution, but the last two options are really popular.

Akira
  • 4,001
  • 1
  • 16
  • 24
0

I have a sample program here that uses the Selenium library.

Launch Firefox and Wait until it is Closed

The program has a code that launches a browser and opens a website. It can detect if the browser has done loading the website. It can also detect if the browser was closed.

Community
  • 1
  • 1
d_air
  • 631
  • 1
  • 4
  • 12