canoo or jwebUnit for automated headless web client? - java

I'm writing an application in groovy with grails that needs to do some automated usage of a couple of websites. So I need something that will perform a similar task to functional web application testing, without a browser being needed. I would also like it to be as lightweight as possible and of course completely headless.
There are two options that I am aware of so far. Canoo which has a nice grails plugin and conveniently also a firefox recorder plugin and EasyB/JWebUnit which can be recorded with Selenium.
Canoo seems very heavy and I don't know what I'd have to do to get it to run in a grails service neatly.
Perhaps I'm thinking about this wrongly though. Has anyone here done this kind of thing in Java or Groovy? Am I better off just dropping out to curl on the command line perhaps?

Have you though about just sending your web requests? Maybe you don't need a full blown headless browser and a line like
def html = new Url("http://example.com").text
is enough for your app?
A testing tool or framework is great when you have to click virtual buttons. But if you only have to remote control a website, sending a request could be enough.
Update: if you need to send POST requests and handle cookies, then the Url-Class isn't enough. But you can use the http builder instead. Here are two URLs which will get you started:
http://blog.swwomm.com/2011/01/groovy-httpbuilder-cookies.html
http://groovy.codehaus.org/modules/http-builder/doc/post.html

Related

Chrome Browser and Java Message Passing

I have developed a Chrome extension and it captures some data in a webpage.
My ultimate goal is to pass this final result to my Java Application.
I have following few options in my mind, but I was not able to find any resources for them yet.
Access the localStorage externally.
Run Chrome browser through the Java app, So I guess we have the control of its data.
If no API found, write the result to a file and access it from the
Java App.
Is there any API to achieve any of the first 2 options? Or any other interface other than the file system?
I checked with berkelium and The Chromium Embedded Framework. But they are just chrome wrappers, and we cannot run a chrome instance from it.
Edit
For the 2nd option I tried with Selenium Webdriver, but I think it hasn't any method to access the localStorage.
It sounds like you are looking for Native Messaging, which allows communication between a Chrome Extension and a native application (e.g. a Java Desktop Application).
There are plenty of question here on SO regarding the implementation of Native Messaging and there is, also, the "official" example.
I suggest the above solution, but if your application will heavily interact with the extension (and you feel like reverse engineering) there is the open-source **[NetBeans Connector Chrome Extension][3]**, which uses a different approach (Sockets or WebSockets - I am not sure).
Take a look at **[this answer][4]** for info on how to get at the sources.
Is there a limitation preventing you from exposing a REST API with your java application?

Which option is suitable to replace Java Applet?

I would like to replace Java Applet which currently needs to use client's resources, i.e. external readers, and to communicate with a server via socket.
Reason:
1. I have thousands of client machines using this Java Applet program, and most of them are running out-dated JRE. When the Java Applet program is updated / added new features, all client machines will need updating the latest JRE.
Expected Solution:
The Java Applet program would be expected to be replaced by a web-based application, which allows to compile and run source code at client's side such that the new web-based application could still use client's resources and communicate with server via socket.
Can I use JavaScript to achieve it?
I would very appreciate your help/suggestion for this problem. Thank you!
JavaScript is a scripting language that gets evaluated in the browser.
I would not describe it as compiling and running but yes, it does mean you can run code in the client and is commonly used to create applications that run in the browser.
There's a staggering amount of frameworks that you can use to write your application. Take a look at the TodoMVC site to see the same TODO app created using several different frameworks.
If you come from Java applets, GWT may be interesting to look at.
If you wish to let the JavaScript client listen for messages from the server, take a look at websockets.
The smart card reader is going to be a problem, though!
See Architectures to access Smart Card from a generic browser? Or: How to bridge the gap from browser to PC/SC stack?
By the way:
The real issue with outdated JREs is not that your code will not run on old JREs, you can create perfectly fine applets using java 1.4 or java 5. Any libraries you may need you can deploy alongside your applet. The pain is a security problem. Anything but the latest version Java plugin is getting actively exploited and puts the user at risk. Occasionally, even the latest version is not safe.
try socket.io
I think this is the latest technology you can use to communicate with client browsers. it support the latest browsers and mobile browsers too.
hope this will help you.
Javascript has become very powerful with HTML 5.0. Here is a list of new elements that you can use to access all kinds of resources, including local files, audio, video, GPU rendering (canvas + WebGL) and GPU compute (WebCL). Here are even more things you can do, including database connections and networking. You can even create offline Javascript applications.
jQuery and jQuery layout make robust GUI development a lot easier. Rich tool suites, such as Google Closure offer optimization and a compiler for improving performance and detecting obvious mistakes early in the development process.
W3 offers useful stats for making an informed decision on how many users on average have access to which features. Note that the most annoying guy in that list arguably is IE8 due to it's lack of proper HTML 5.0 support.
In case you want to stick with Java, then one alternative would be to use my http://bck2brwsr.apidesign.org project. It's goal is to create small Java that can run in 100% of modern browsers without any plugin installed.
There are Java bindings to HTML (via knockout - one of the four most popular frameworks for HTML5) and that is why one can code whole business logic in Java and just render it via HTML. Should be enough to replace most of the applet UI.
In addition to that there is an experimental API to render on HTML canvas. People use it to write Java games that run in a pure browser.
There is a simple way to communicate with server via JSON REST API or via WebSockets. A live example is here.

Trying to understand selenium and its various components

For integration testing I want to use selenium, also for my TDD/BDD workflow but also for my remote build server to run through the tests etc.
What components do I need for this?
I know there is a browser add-in, but that is for helping to bootstrap the code (you can export the code, then tweak as necessary).
I find it slow to run the tests locally as it fires up the browser, is there a way to do this w/o the browser opening?
How does this work on the build server, is there a headless mode?
Can someone outline the various selenium tools and how they fit together and where they are used in the development cycle.
e.g. I see selenium drivers, selenium rc, browser add-on etc.
I want to use this for both rails and java.
I never tried Selenium with Java, only with Ruby, but your interaction should be similar. I don't think Selenium has a headless mode, you would have to use a different driver for that. For ruby, there is capybara-webkit, for example, which runs a headless webkit based browser.
I can tell you from my own experience, we had a lot of problems on CI (build server) with the headless browser so we ended up switching back to Selenium and Google Chrome running on top of Xvfb, which is kind of a virtual screen manager for unix that lets you run graphical apps in a headless environment. Most of the problems are related to inconsistent behavior between the webkit headless browser and an actual real driver. However, depending on how your app looks like and how you're going to drive it, it might work for you, you should give it a try.
So the only components you need are the Selenium server (that driver the browser) and the client, that sends the command to the server. They have java and ruby clients, so you can choose whichever language you prefer.
It is indeed a slow process and very flaky as well, as your tests might fail for no reason sometimes due to timeouts, 3rd party APIs that are down, etc. There are tons of things that can go wrong and cause your integration tests to fail.
Anyways it is still an invaluable tool and you should definitely use it. Just be aware that you should not rely entirely only on these kinds of tests to assure the quality of your app, however, these should only test a smaller surface of your system. Unit and component tests should make up the majority of your test suite.
Hope this helps clarify your questions.
I have evaluated Selenium somewhat myself and as I understand it you should use the Firefox add-on to record your tests. Then export to whatever code you want. Then, when the time comes and you want to test your system, boot the Selenium RC which acts as a server that you can then use to run your tests. The Selenium WebDrivers are part of this and allow the server to open and "drive" the browsers using your recorded tests.
Note that recording tests in browsers other to Firefox is more difficult as there is no handy add-on for use. Instead you have to build your own tests from scratch, which is time consuming.
app.test from Fabasoft (http://www.apptest.com/en/) is another free alternative that does the same job but in a different way, maybe take a look at that before you get too involved with Selenium.

Chrome extension interaction with Java application

I am learning to build Chrome extension and I have an idea to build something which requires complex computation (using many java libraries) which seems hard to be implemented by JavaScript.
A general architecture I have in mind is:
Chrome Extension (GE) extracts HTML elements and feeds HTML elements to Java application as input. Java application does the complex computation, and then feedback the results to GE. GE finally renders the results into the browser.
Does anyone know is this feasible? Does this have to involve a server architecture? Could you also refer me to some further information?
Note: It is a Java application, hopefully you can give me some Java specific answers.
Thanks in advance.
You would need to create java web application running on server (which can be accessed via URL) which you will be communicating with through ajax requests. Chrome extension (or any other js app) doesn't care what's running on server - java, php, or something else. It just sends HTTP POST/GET request to provided url and receives response back.
If you are asking if you can pack some java into your extension then the answer is no. You can pack some C++ though.

How to conduct blackbox testing on an AJAX application?

What's the best, crossplatform way to perform blackbox tests on AJAX web applications?
Ideally, the solution should have the following attributes:
Able to integrate into a continuous integration build loop
Cross platform so I you can run it on Windows laptops and Linux continuous integration servers
Easy way to script the interactions
Free-as-in-freedom so you can adapt it into your tool chain if necessary
I've looked into HttpUnit but I'm not conviced it can handle AJAX-heavy websites.
Selenium might be what you're looking for: http://selenium.openqa.org/
It allows you to script actions and evaluate the results. It's open-source (Apache 2.0), cross platform, and has nice tools.
I have used Selenium for exactly this task, but found it to be brittle.
Check out this talk by two Googlers: Does my button look big in this? Building testable AJAX applications
They isolate the testable javascript (non DOM-interaction) and test that using the Rhino javascript engine.

Categories