Adventures with Ruby

Selenium clicking a label

View Comments

Story: Selenium clicking a label

As a developer
I wanted to make acceptence tests
So I installed

  Scenario: I am making some acceptance tests for the LevenAls website, using plain text stories from David Chelimsky together with the Selenium runner from Kerry Buckley
    When I wanted to make the stories as clean as possible
    And I wanted to click a rails generated radiobutton
    Then the story became ugly
    And it had lines like 'the user clicks a customer_gender_m button'

  Scenario: I made a step for labels, getting the text
    When I wanted to get rid of it
    And I couldn't find an easy answer
    And I spent the better part of my evening googling it
    Then I made a post on the Selenium forum
    And asked for advice

  Scenario: I found a solution myself
    When I was sitting in the train
    And I was trying all kinds of solutions
    Then I stumbled upon the solution
    And I was overjoyed
    And it was: $selenium.click("//label[text()='#{label}']")

So here is the entire step:

When "the user clicks on a $element labelled $label" do |element, label|
  $selenium.click "//label[text()='#{label}']"
end

Written by Iain Hecker

December 18th, 2007 at 9:55 am

Posted in Uncategorized

  • http://ariekanarie.nl Arie

    As a developer
    I want to refer to labels in plain text user stories
    So I don’t end up with ugly stories

    Scenario: Using this snippet of code
    Given you’re using the rspec plain text story runner and Kerry Buckley’s selenium steps.
    When you want to use this code
    Then you have to put it in the selenium.rb in stories/steps

  • http://ariekanarie.nl Arie

    As a developer
    I want to refer to labels in plain text user stories
    So I don’t end up with ugly stories

    Scenario: Using this snippet of code
    Given you’re using the rspec plain text story runner and Kerry Buckley’s selenium steps.
    When you want to use this code
    Then you have to put it in the selenium.rb in stories/steps

blog comments powered by Disqus
Fork me on GitHub