Skip to content

Instantly share code, notes, and snippets.

@abotalov
Created January 25, 2013 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abotalov/4637735 to your computer and use it in GitHub Desktop.
Save abotalov/4637735 to your computer and use it in GitHub Desktop.
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