Skip to content

Instantly share code, notes, and snippets.

@trinary
Created August 11, 2011 18:34
Show Gist options
  • Save trinary/1140382 to your computer and use it in GitHub Desktop.
Save trinary/1140382 to your computer and use it in GitHub Desktop.
#!/bin/env ruby
#
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'capybara-webkit'
require 'nokogiri'
require 'uri'
require 'net/https'
class CapybaraWalker
include Capybara
attr_accessor :doc, :name, :home
def open(args)
Capybara.visit(args[:target])
end
def type(args)
Capybara.fill_in(args[:target], :with => args[:arg])
end
def clickAndWait(args)
Capybara.click_on(args[:target])
end
def initialize(url)
@uri = URI.parse(url)
@doc = Nokogiri::HTML.parse(Net::HTTP.get(URI.parse(url)))
@home = URI.parse(@doc.xpath('/html/head/link[@rel="selenium.base"]/@href').first.value)
Capybara.default_driver = :webkit
Capybara.run_server = false
Capybara.app_host = 'http://code.google.com/'
Capybara.visit(@home)
@doc.xpath('/html/body/table/tbody/tr').each do |e|
action = e.xpath('td[1]').first.text
target = e.xpath('td[2]').first.text
arg = e.xpath('td[3]').first.text
self.send action,{:target => target, :arg => arg}
end
end
end
walker = CapybaraWalker.new('http://localhost:8000/testcase.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment