Create a gist now

Instantly share code, notes, and snippets.

Simple script to post answer for http://stackoverflow.com/q/14527556/841064
<table>
<tr>
<td>Sara</td>
<td>2.3</td>
<td>4.3</td>
</tr>
<tr>
<td>Mike</td>
<td>4.5</td>
<td>1.1</td>
</tr>
<tr>
<td>Alex</td>
<td>1</td>
<td>8</td>
</tr>
</table>
require 'capybara'
require 'capybara/dsl'
require 'rspec/expectations'
Capybara.app_host = "file:///path/to/folder/with/file"
Capybara.run_server = false
Capybara.current_driver = :selenium
include Capybara::DSL # It's a bad practice in general but good enough for simple script
include RSpec::Matchers
visit '/test.html'
def cell_text(n)
find(:xpath, "./td[#{n}]").text
end
h = {2 => 4.5, 3 => 1.1}
within 'table' do
all('tr').each do |row|
within row do
if cell_text(1) == 'Mike'
h.each { |i, value| cell_text(i).should == value.to_s }
else
h.each { |i, value| cell_text(i).should_not == value.to_s }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment