After adding quite a few Cucumber tests to my current automation framework, I wanted to get it a bit more clean.  There’s a lot of code, some of which could be reused.

First I looked at this as a Ruby problem and tried to create classes within the Cucumber Step Definition files and do some inheritance.

However, I found that Cucumber has it’s own way of handling this.  You can call a step from within a step.  Similar to a method call from a different class, you can do something like this:

Given /^a user who is at the Profile Edit screen$/ do
    step “user logs in”

That code:
step “user logs in”
will grab the code driving that step. In my case it could be a login.rb file that has
Given /^user logs in$/ do
    @browser = browser_type
    @browser.goto “http://www……”

Doing this helps dry up tests and keep the code clean.

Leave a Reply

Your email address will not be published. Required fields are marked *