Created
August 12, 2011 19:29
-
-
Save trinary/1142794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 :test, :name, :home | |
def open(args) | |
puts "open on " + Capybara.current_url | |
Capybara.visit(args[:target]) | |
end | |
def type(args) | |
puts "type on " + Capybara.current_url | |
type,id = args[:target].split '=' | |
Capybara.fill_in(id, :with => args[:arg]) | |
end | |
def click(args) | |
clicker(args) | |
end | |
def clickAndWait(args) | |
clicker(args) | |
#Capybara.find(selector).click | |
end | |
def clicker(args) | |
type = args[:target].split '='.first | |
if (type == "css") | |
selector = args[:target].gsub('css=','') | |
Capybara.find(selector).click | |
elsif (type == "link") | |
selector = args[:target].gsub('link=','') | |
Capybara.click_link(selector) | |
end | |
end | |
def initialize(url) | |
@uri = URI.parse(url) | |
@test = Nokogiri::HTML.parse(Net::HTTP.get(URI.parse(url))) | |
@home = URI.parse(@test.xpath('/html/head/link[@rel="selenium.base"]/@href').first.value) | |
Capybara.default_driver = :webkit | |
Capybara.run_server = false | |
Capybara.app_host = @home.scheme + '://' + @home.host | |
Capybara.visit(@home.path) | |
@test.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} | |
puts "ran #{action} on #{target} with #{arg}" | |
end | |
end | |
end | |
walker = CapybaraWalker.new('http://localhost:8000/testcase2.html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment