mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Stub for SafariWatir (not working 100%)
This commit is contained in:
parent
5d8f14e573
commit
73bc7de10d
4 changed files with 80 additions and 4 deletions
|
@ -18,5 +18,6 @@ module Webcat
|
|||
module Driver
|
||||
autoload :RackTest, 'webcat/rack_test_driver'
|
||||
autoload :Culerity, 'webcat/culerity_driver'
|
||||
autoload :SafariWatir, 'webcat/safariwatir_driver'
|
||||
end
|
||||
end
|
65
lib/webcat/safariwatir_driver.rb
Normal file
65
lib/webcat/safariwatir_driver.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
require 'safariwatir'
|
||||
|
||||
class Webcat::Driver::SafariWatir
|
||||
class Node < Struct.new(:node)
|
||||
def text
|
||||
node.text
|
||||
end
|
||||
|
||||
def attribute(name)
|
||||
value = if name.to_sym == :class
|
||||
node.class_name
|
||||
else
|
||||
node.send(name.to_sym)
|
||||
end
|
||||
return value if value and not value.empty?
|
||||
end
|
||||
|
||||
def click
|
||||
node.click
|
||||
end
|
||||
|
||||
def tag_name
|
||||
# FIXME: this might be the dumbest way ever of getting the tag name
|
||||
# there has to be something better...
|
||||
node.to_xml[/^\s*<([a-z0-9\-\:]+)/, 1]
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :app, :rack_server
|
||||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@rack_server = Webcat::Server.new(@app)
|
||||
@rack_server.boot
|
||||
end
|
||||
|
||||
def visit(path)
|
||||
browser.goto(url(path))
|
||||
end
|
||||
|
||||
def body
|
||||
browser.html
|
||||
end
|
||||
|
||||
def find(selector)
|
||||
browser.send(:scripter).by_xpath(selector).map { |node| Node.new(node) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def url(path)
|
||||
rack_server.url(path)
|
||||
end
|
||||
|
||||
def browser
|
||||
unless @_browser
|
||||
@_browser = Watir::Safari.new
|
||||
at_exit do
|
||||
@_browser.exit
|
||||
end
|
||||
end
|
||||
@_browser
|
||||
end
|
||||
|
||||
end
|
|
@ -5,21 +5,21 @@ shared_examples_for 'driver' do
|
|||
describe '#visit' do
|
||||
it "should move to another page" do
|
||||
@driver.visit('/')
|
||||
@driver.body.should == 'Hello world!'
|
||||
@driver.body.should include('Hello world!')
|
||||
@driver.visit('/foo')
|
||||
@driver.body.should == 'Another World'
|
||||
@driver.body.should include('Another World')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#body' do
|
||||
it "should return text reponses" do
|
||||
@driver.visit('/')
|
||||
@driver.body.should == 'Hello world!'
|
||||
@driver.body.should include('Hello world!')
|
||||
end
|
||||
|
||||
it "should return the full response html" do
|
||||
@driver.visit('/with_simple_html')
|
||||
@driver.body.should == '<h1>Bar</h1>'
|
||||
@driver.body.should include('<h1>Bar</h1>')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
10
spec/safariwarit_driver_spec.rb
Normal file
10
spec/safariwarit_driver_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
||||
|
||||
describe Webcat::Driver::SafariWatir do
|
||||
before do
|
||||
@driver = Webcat::Driver::SafariWatir.new(TestApp)
|
||||
end
|
||||
|
||||
# it_should_behave_like "driver"
|
||||
# it_should_behave_like "driver with javascript support"
|
||||
end
|
Loading…
Add table
Reference in a new issue