Automated Testing using Cucumber & Watir
As unroole has developed into a state of the art CMS, we have dedicated more and more time to testing the system in order to ensure the high standard of quality we are so proud of. In our continuous pursuit to improve efficiency, we have experimented with a series of tools in order to automate the repetitive and laborious process of testing. The ideal tools for our needs proved to be Cucumber+Watir(Web Application Testing In Ruby). Using the combination of these two tools, we were able to automate our black box testing by simulating user behaviour in the web application.
Automating your testing process will save you a lot of time. Once you write your testing scenarios/steps, you can run your scripts every time someone touches the codebase. Both tools use a human-like language that can be easily picked up by the QA team. The information they output brings your right to the core of the problem. And last but not least the scripts you write, are very easy to maintain: for any change in the systems, a few light touches in the scripts and you are ready to go.
If you are new to either of these tools, a feature worth noting is the tag feature. Using tags one can bundle test cases, creating testing scenarios which allow users focus his efforts on specific features. This not only helps you stay organized, but also saves time at runtime when testing large systems that include a large number of testing scenarios.
Watir is an very powerful system which we strongly recommend to everyone. However, as a new adopter of the system you may encounter some frustrations when trying to test javascript features. Here are some of the challenges we encountered and examples on how we overcame them:
-
Accessing an element inside an iframe, (in this case a textbox):
@browser.execute_script(" var myframe = document.getElementsByTagName('iframe')[0] myframe.contentDocument.getElementsByTagName('body')[0] myframe.contentDocument.getElementsByTagName('body')[0].innerHTML ='ABC'") -
Changing css properties for a particular element which is transparent and requires to be visible on the browser:
@browser.execute_script(" $('.widget_editor_ctr') .css('display', 'block') .css('opacity', 1);") -
Stoping JavaScript Pop Ups from showing when running your Watir tests, use this code before triggering the action that calls the window. This will stop the pop ups for the entire browser session:
@browser.execute_script("window.confirm = function confirm() { return true };") -
Setting the value for a file field:
@browser.file_field(:id, "the_file").set("C:\\image.png")
If you are looking for a way to improve your testing process, we strongly recommend checking out Cucumber and Watir. For more information try: