Skip to content

Instantly share code, notes, and snippets.

@sohara
Created February 2, 2011 18:48
Show Gist options
  • Save sohara/808159 to your computer and use it in GitHub Desktop.
Save sohara/808159 to your computer and use it in GitHub Desktop.
step definition to test the contents of specific table row given a column heading and the contents of one of the cells in the row
# Locates a table cell based on given row and column content.
When /^(.*) in the "([^\"]*)" column of the "([^\"]*)" row$/ do |action, column_title, row_title|
col_number = 0
all(:xpath, "//*[(th|td)/descendant-or-self::*[contains(text(), '#{column_title}')]]/th").each do |element|
col_number += 1
break if element.has_content?(column_title)
end
within :xpath, "//*[(th|td)/descendant-or-self::*[contains(text(), '#{row_title}')]]/td[#{col_number}]" do
When action
end
end
@justaj
Copy link

justaj commented Dec 11, 2014

This is exactly what I have been looking for but I'm a little confused about how to use it. I basically have a table and I know the column title that contains the value I want (to assign to a variable) along with a value within that row. (The row itself doesn't have a title) When I try to run it with cucumber I get an undefined error.

What would the cucumber look like?
When in the "A" column of the "B" row ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment