public
Created

Simple script to post answer for http://stackoverflow.com/q/14527556/841064

  • Download Gist
test.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<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>
test.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.