2

I'm interested in applying another layer of abstraction on my cucumber webrat BDD suite that knows about the DOM I am working with.

Currently I am writing step definitions something like this example:

response_body.should have_selector("div", :id => 'left-side-bar') do |div|
  div.should have_selector("h1", :content => 'Hello')
  ... other stuff
end

I know I can do this with xpath and various other ways but I want to use my own DSL like this:

left_sidebar.should have_heading("Hello")

Basically, I want to represent the project specific entities my client requires such menu items, blocks or widgety things, columns, header footer and such in the DSL.

How would I do this? Is this practical? My application isn't a rail application (if that matters)

Rimian
  • 36,864
  • 16
  • 117
  • 117

1 Answers1

4

This sounds a lot like the page object pattern:

http://code.google.com/p/selenium/wiki/PageObjects

It's certainly practical, and makes no difference that your project isn't a rails app.

Basically you need to define a bunch of objects that model the pages\components of the site under test, and provide methods to access the page content on those objects. One advantage is that all of the knowledge about page markup is kept in these objects, so if the markup of the page changes you only need to update in once place.

I tend to include useful helper methods that, for example, locate an HTML table on a page and convert it into an array of hashes for easy comparison in cucumber steps.

AlistairH
  • 3,139
  • 2
  • 21
  • 19