Archive for JavaScript
Using Cucumber, Webrat and Selenium to test ajax form field validations
September 4th, 2009 • 2 comments Cucumber, Internet, JavaScript, Merb, Ruby, Webrat, programming
I have an app that fires an ajax request on a form field to validate its contents when I take focus off the field.
I am also using Cucumber, Webrat and Selenium for my integration tests.
I needed my integration tests to test the Ajax responses and the tests weren’t receiving a response from the Ajax requests.
The Problem
I found that by simply completing the web form, the ajax request was not being fired and my test was therefore failing when i checked for the existance of the Ajax response. It soon became clear that selenium doesn’t really interact with the form in the sense of selecting fields and entering values; It simply enters values. As such, the Ajax request was not firing and my test was failing.
The Solution
The solution is Selenium’s fireEvent method, which you can pass a form field id and the blur method:
selenium_session.fireEvent(”field”, “blur”);
In Webrat, this is ever simpler:
fire_event(”field”,”blur”)
On using this in a Cucumber step, the ajax is fired as the blur command tells the browser to take focus off the field.
Lovely!
Sproutcore – 1st impressions
October 14th, 2008 • 1 comment Apple, JavaScript, Ruby, software development
Tags: linkedin
Today i had a short play with Sproutcore (the “Cocoa for the Web” JS framework used by and optimized by Apple for me.com) for the first time. I was a little surprised with what i found.
The Great
- The development tools are in Ruby using the merb framework
- The development tools adopt a Rails like MVC architectural pattern, with commands like
sc-gen model example/contact
sc-gen controller example/detail
sc-gen view example/card
- The development tools include build tools that prepare all JS, HTML and CSS ready to be distributed.
sc-build - The development tools have a bunch of ruby (rails-style) helpers
<%= button_view :my_button, :label => 'Here is a functioning button!' %>
- It doesn’t work with the latest version of Merb (0.9.9 RC1) and doesn’t appear happy even having it around (even if 0.9.4 is installed, if seems to force a removal of 0.9.9 in order to work) – Patch submitted, but only recently.