mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge branch 'master' of https://github.com/sobrinho/capybara into sobrinho-master
This commit is contained in:
commit
1c22bbd33a
14 changed files with 1 additions and 422 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,3 +11,4 @@ capybara-*.html
|
|||
.yardoc
|
||||
doc
|
||||
.bundle
|
||||
Gemfile.lock
|
||||
|
|
105
Gemfile.lock
105
Gemfile.lock
|
@ -1,105 +0,0 @@
|
|||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
capybara (0.4.1.1)
|
||||
celerity (>= 0.7.9)
|
||||
culerity (>= 0.2.4)
|
||||
mime-types (>= 1.16)
|
||||
nokogiri (>= 1.3.3)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (>= 0.5.4)
|
||||
selenium-webdriver (>= 0.0.27)
|
||||
xpath (~> 0.1.3)
|
||||
|
||||
PATH
|
||||
remote: xpath
|
||||
specs:
|
||||
xpath (0.1.3)
|
||||
nokogiri (~> 1.3)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
builder (3.0.0)
|
||||
celerity (0.8.7)
|
||||
childprocess (0.1.6)
|
||||
ffi (~> 0.6.3)
|
||||
configuration (1.2.0)
|
||||
cucumber (0.10.0)
|
||||
builder (>= 2.1.2)
|
||||
diff-lcs (~> 1.1.2)
|
||||
gherkin (~> 2.3.2)
|
||||
json (~> 1.4.6)
|
||||
term-ansicolor (~> 1.0.5)
|
||||
culerity (0.2.15)
|
||||
diff-lcs (1.1.2)
|
||||
ffi (0.6.3)
|
||||
rake (>= 0.8.7)
|
||||
ffi (0.6.3-java)
|
||||
fuubar (0.0.3)
|
||||
rspec (~> 2.0)
|
||||
rspec-instafail (~> 0.1.4)
|
||||
ruby-progressbar (~> 0.0.9)
|
||||
gherkin (2.3.3)
|
||||
json (~> 1.4.6)
|
||||
gherkin (2.3.3-java)
|
||||
json (~> 1.4.6)
|
||||
json (1.4.6)
|
||||
json (1.4.6-java)
|
||||
json_pure (1.4.6)
|
||||
launchy (0.3.7)
|
||||
configuration (>= 0.0.5)
|
||||
rake (>= 0.8.1)
|
||||
mime-types (1.16)
|
||||
nokogiri (1.4.4)
|
||||
nokogiri (1.4.4-java)
|
||||
weakling (>= 0.0.3)
|
||||
rack (1.2.1)
|
||||
rack-test (0.5.7)
|
||||
rack (>= 1.0)
|
||||
rake (0.8.7)
|
||||
rspec (2.4.0)
|
||||
rspec-core (~> 2.4.0)
|
||||
rspec-expectations (~> 2.4.0)
|
||||
rspec-mocks (~> 2.4.0)
|
||||
rspec-core (2.4.0)
|
||||
rspec-expectations (2.4.0)
|
||||
diff-lcs (~> 1.1.2)
|
||||
rspec-instafail (0.1.5)
|
||||
rspec-mocks (2.4.0)
|
||||
ruby-progressbar (0.0.9)
|
||||
rubyzip (0.9.4)
|
||||
selenium-webdriver (0.1.2)
|
||||
childprocess (~> 0.1.5)
|
||||
ffi (~> 0.6.3)
|
||||
json_pure
|
||||
rubyzip
|
||||
sinatra (1.1.2)
|
||||
rack (~> 1.1)
|
||||
tilt (~> 1.2)
|
||||
term-ansicolor (1.0.5)
|
||||
tilt (1.2.2)
|
||||
weakling (0.0.4-java)
|
||||
yard (0.6.4)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
bundler (~> 1.0)
|
||||
capybara!
|
||||
celerity (>= 0.7.9)
|
||||
cucumber (>= 0.10)
|
||||
culerity (>= 0.2.4)
|
||||
fuubar (>= 0.0.1)
|
||||
launchy (>= 0.3.5)
|
||||
mime-types (>= 1.16)
|
||||
nokogiri (>= 1.3.3)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (>= 0.5.4)
|
||||
rspec (>= 2.0.0)
|
||||
selenium-webdriver (>= 0.0.27)
|
||||
sinatra (>= 0.9.4)
|
||||
xpath!
|
||||
yard (>= 0.5.8)
|
|
@ -24,8 +24,6 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.add_runtime_dependency("nokogiri", [">= 1.3.3"])
|
||||
s.add_runtime_dependency("mime-types", [">= 1.16"])
|
||||
s.add_runtime_dependency("culerity", [">= 0.2.4"])
|
||||
s.add_runtime_dependency("celerity", [">= 0.7.9"])
|
||||
s.add_runtime_dependency("selenium-webdriver", [">= 0.0.27"])
|
||||
s.add_runtime_dependency("rack", [">= 1.0.0"])
|
||||
s.add_runtime_dependency("rack-test", [">= 0.5.4"])
|
||||
|
|
|
@ -200,8 +200,6 @@ module Capybara
|
|||
autoload :Base, 'capybara/driver/base'
|
||||
autoload :Node, 'capybara/driver/node'
|
||||
autoload :RackTest, 'capybara/driver/rack_test_driver'
|
||||
autoload :Celerity, 'capybara/driver/celerity_driver'
|
||||
autoload :Culerity, 'capybara/driver/culerity_driver'
|
||||
autoload :Selenium, 'capybara/driver/selenium_driver'
|
||||
end
|
||||
end
|
||||
|
@ -220,14 +218,6 @@ Capybara.register_driver :rack_test do |app|
|
|||
Capybara::Driver::RackTest.new(app)
|
||||
end
|
||||
|
||||
Capybara.register_driver :celerity do |app|
|
||||
Capybara::Driver::Celerity.new(app)
|
||||
end
|
||||
|
||||
Capybara.register_driver :culerity do |app|
|
||||
Capybara::Driver::Culerity.new(app)
|
||||
end
|
||||
|
||||
Capybara.register_driver :selenium do |app|
|
||||
Capybara::Driver::Selenium.new(app)
|
||||
end
|
||||
|
|
|
@ -1,164 +0,0 @@
|
|||
class Capybara::Driver::Celerity < Capybara::Driver::Base
|
||||
class Node < Capybara::Driver::Node
|
||||
def text
|
||||
native.text
|
||||
end
|
||||
|
||||
def [](name)
|
||||
value = native.attribute_value(name.to_sym)
|
||||
return value if value and not value.to_s.empty?
|
||||
end
|
||||
|
||||
def value
|
||||
if tag_name == "select" and native.multiple?
|
||||
find(".//option[@selected]").map { |n| if n.has_value? then n.value else n.text end }
|
||||
else
|
||||
native.value
|
||||
end
|
||||
end
|
||||
|
||||
def set(value)
|
||||
native.set(value)
|
||||
end
|
||||
|
||||
def select_option
|
||||
native.click
|
||||
end
|
||||
|
||||
def unselect_option
|
||||
unless select_node.native.multiple?
|
||||
raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
|
||||
end
|
||||
|
||||
# FIXME: couldn't find a clean way to unselect, so clear and reselect
|
||||
selected_nodes = select_node.find('.//option[@selected]')
|
||||
select_node.native.clear
|
||||
selected_nodes.each { |n| n.click unless n.path == path }
|
||||
end
|
||||
|
||||
def click
|
||||
native.click
|
||||
end
|
||||
|
||||
def drag_to(element)
|
||||
native.fire_event('mousedown')
|
||||
element.native.fire_event('mousemove')
|
||||
element.native.fire_event('mouseup')
|
||||
end
|
||||
|
||||
def tag_name
|
||||
# FIXME: this might be the dumbest way ever of getting the tag name
|
||||
# there has to be something better...
|
||||
native.to_xml[/^\s*<([a-z0-9\-\:]+)/, 1]
|
||||
end
|
||||
|
||||
def visible?
|
||||
native.visible?
|
||||
end
|
||||
|
||||
def checked?
|
||||
native.checked?
|
||||
rescue # https://github.com/langalex/culerity/issues/issue/33
|
||||
false
|
||||
end
|
||||
|
||||
def selected?
|
||||
native.selected?
|
||||
rescue # https://github.com/langalex/culerity/issues/issue/33
|
||||
false
|
||||
end
|
||||
|
||||
def path
|
||||
native.xpath
|
||||
end
|
||||
|
||||
def trigger(event)
|
||||
native.fire_event(event.to_s)
|
||||
end
|
||||
|
||||
def find(locator)
|
||||
noko_node = Nokogiri::HTML(driver.body).xpath(native.xpath).first
|
||||
all_nodes = noko_node.xpath(locator).map { |n| n.path }.join(' | ')
|
||||
if all_nodes.empty? then [] else driver.find(all_nodes) end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# a reference to the select node if this is an option node
|
||||
def select_node
|
||||
find('./ancestor::select').first
|
||||
end
|
||||
|
||||
def has_value?
|
||||
native.object.hasAttribute('value')
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :app, :rack_server, :options
|
||||
|
||||
def initialize(app, options={})
|
||||
@app = app
|
||||
@options = options
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
@rack_server.boot if Capybara.run_server
|
||||
end
|
||||
|
||||
def visit(path)
|
||||
browser.goto(url(path))
|
||||
end
|
||||
|
||||
def current_url
|
||||
browser.url
|
||||
end
|
||||
|
||||
def source
|
||||
browser.html
|
||||
end
|
||||
|
||||
def body
|
||||
browser.document.as_xml
|
||||
end
|
||||
|
||||
def response_headers
|
||||
browser.response_headers
|
||||
end
|
||||
|
||||
def status_code
|
||||
browser.status_code
|
||||
end
|
||||
|
||||
def find(selector)
|
||||
browser.elements_by_xpath(selector).map { |node| Node.new(self, node) }
|
||||
end
|
||||
|
||||
def wait?; true; end
|
||||
|
||||
def execute_script(script)
|
||||
browser.execute_script script
|
||||
nil
|
||||
end
|
||||
|
||||
def evaluate_script(script)
|
||||
browser.execute_script "#{script}"
|
||||
end
|
||||
|
||||
def browser
|
||||
unless @_browser
|
||||
require 'celerity'
|
||||
@_browser = ::Celerity::Browser.new(options)
|
||||
end
|
||||
|
||||
@_browser
|
||||
end
|
||||
|
||||
def reset!
|
||||
browser.clear_cookies
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def url(path)
|
||||
rack_server.url(path)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
require 'culerity'
|
||||
|
||||
class Capybara::Driver::Culerity < Capybara::Driver::Celerity
|
||||
|
||||
def self.server
|
||||
unless @_server
|
||||
@_server = ::Culerity::run_server
|
||||
at_exit do
|
||||
@_server.close
|
||||
end
|
||||
end
|
||||
@_server
|
||||
end
|
||||
|
||||
def browser
|
||||
unless @_browser
|
||||
@_browser = ::Culerity::RemoteBrowserProxy.new self.class.server, options
|
||||
at_exit do
|
||||
@_browser.close
|
||||
@_browser.exit
|
||||
end
|
||||
end
|
||||
@_browser
|
||||
end
|
||||
|
||||
end
|
|
@ -119,7 +119,6 @@ shared_examples_for "driver with javascript support" do
|
|||
|
||||
describe '#drag_to' do
|
||||
it "should drag and drop an object" do
|
||||
pending "drag/drop is currently broken under celerity/culerity" if @driver.is_a?(Capybara::Driver::Celerity)
|
||||
draggable = @driver.find('//div[@id="drag"]').first
|
||||
droppable = @driver.find('//div[@id="drop"]').first
|
||||
draggable.drag_to(droppable)
|
||||
|
|
|
@ -10,7 +10,6 @@ shared_examples_for "session with javascript support" do
|
|||
|
||||
describe 'Node#drag_to' do
|
||||
it "should drag and drop an object" do
|
||||
pending "drag/drop is currently broken under celerity/culerity" if @session.driver.is_a?(Capybara::Driver::Celerity)
|
||||
@session.visit('/with_js')
|
||||
element = @session.find('//div[@id="drag"]')
|
||||
target = @session.find('//div[@id="drop"]')
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Capybara::Driver::Celerity, :jruby => :platform do
|
||||
before(:all) do
|
||||
@driver = TestSessions::Celerity.driver
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
it_should_behave_like "driver with javascript support"
|
||||
it_should_behave_like "driver with header support"
|
||||
it_should_behave_like "driver with status code support"
|
||||
it_should_behave_like "driver with cookies support"
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Capybara::Driver::Culerity, :jruby => :installed do
|
||||
|
||||
before(:all) do
|
||||
@driver = TestSessions::Culerity.driver
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
it_should_behave_like "driver with javascript support"
|
||||
it_should_behave_like "driver with header support"
|
||||
it_should_behave_like "driver with status code support"
|
||||
it_should_behave_like "driver with cookies support"
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Capybara::Driver::Culerity, :jruby => :installed do
|
||||
before(:all) do
|
||||
Capybara.app_host = "http://capybara-testapp.heroku.com"
|
||||
@driver = TestSessions::Culerity.driver
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
Capybara.app_host = nil
|
||||
end
|
||||
|
||||
it "should navigate to a fully qualified remote page" do
|
||||
@driver.visit('http://capybara-testapp.heroku.com/foo')
|
||||
@driver.body.should include('Another World')
|
||||
end
|
||||
|
||||
it_should_behave_like "driver"
|
||||
it_should_behave_like "driver with javascript support"
|
||||
it_should_behave_like "driver with header support"
|
||||
it_should_behave_like "driver with status code support"
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Capybara::Driver::Celerity, :jruby => :platform do
|
||||
before(:all) do
|
||||
@session = TestSessions::Celerity
|
||||
end
|
||||
|
||||
describe '#driver' do
|
||||
it "should be a celerity driver" do
|
||||
@session.driver.should be_an_instance_of(Capybara::Driver::Celerity)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mode' do
|
||||
it "should remember the mode" do
|
||||
@session.mode.should == :celerity
|
||||
end
|
||||
end
|
||||
|
||||
it_should_behave_like "session"
|
||||
it_should_behave_like "session with javascript support"
|
||||
it_should_behave_like "session with headers support"
|
||||
it_should_behave_like "session with status code support"
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Capybara::Session, :jruby => :installed do
|
||||
context 'with culerity driver' do
|
||||
before(:all) do
|
||||
@session = TestSessions::Culerity
|
||||
end
|
||||
|
||||
describe '#driver' do
|
||||
it "should be a culerity driver" do
|
||||
@session.driver.should be_an_instance_of(Capybara::Driver::Culerity)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mode' do
|
||||
it "should remember the mode" do
|
||||
@session.mode.should == :culerity
|
||||
end
|
||||
end
|
||||
|
||||
it_should_behave_like "session"
|
||||
it_should_behave_like "session with javascript support"
|
||||
it_should_behave_like "session with headers support"
|
||||
it_should_behave_like "session with status code support"
|
||||
end
|
||||
end
|
|
@ -15,23 +15,9 @@ Capybara.default_wait_time = 0 # less timeout so tests run faster
|
|||
module TestSessions
|
||||
RackTest = Capybara::Session.new(:rack_test, TestApp)
|
||||
Selenium = Capybara::Session.new(:selenium, TestApp)
|
||||
Culerity = Capybara::Session.new(:culerity, TestApp)
|
||||
Celerity = Capybara::Session.new(:celerity, TestApp)
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
||||
running_with_jruby = RUBY_PLATFORM =~ /java/
|
||||
jruby_installed = `which jruby` && $?.success?
|
||||
|
||||
warn "** Skipping Celerity specs because platform is not Java" unless running_with_jruby
|
||||
warn "** Skipping Culerity specs because JRuby is not installed" unless jruby_installed
|
||||
|
||||
config.filter_run_excluding(:jruby => lambda { |value|
|
||||
return true if value == :platform && !running_with_jruby
|
||||
return true if value == :installed && !jruby_installed
|
||||
})
|
||||
|
||||
config.before do
|
||||
Capybara.configure do |config|
|
||||
config.default_selector = :xpath
|
||||
|
|
Loading…
Reference in a new issue