4

We have a JavaScript file that our customers are installing on their site to capture certain behaviors and emit events when certain actions are taken. We'd like to have a utility on our backend to periodically load the page and trigger a test run of the script to make sure it's still able to emit the events we need.

Our back-end is written in Java, and ideally I'd like a solution that can be done entirely from within Java. What I'm looking for is a headless browser that can load a page, add a listener for the event our script emits, trigger a test of the event, verify the result against an expected value, and then report back to our application if everything's still behaving as expected.

Right now the closest I've come to this is running a PhantomJS file, writing the output to standard output, then calling that from Java and reading the standard output buffer. That's a doable fallback, but I'd prefer something that can be entirely run in Java.

I've looked at Selenium briefly, and am going back to take a closer look, but my first impression was that it would be overkill for what I'm trying to do. Are there any better options out there?

3

If you install a headless browser such phantomjs or slimerjs on the machine you can use a CasperJS interface to control it.

There's a jUnit-CasperJS project on Github that can be convenient for this kind of setup.

Depending on the script you have to test you may find limiting to use a headless browser, then go for Selenium (or Selenium + Geb).
By the way Selenium has a driver also for PhantomJS: while Selenium can be painful to setup can be a better choice in the longer run I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.