Remove resynchronization for Selenium
This commit is contained in:
parent
b100d1c298
commit
a1b1cc7132
|
@ -2,11 +2,9 @@ require 'selenium-webdriver'
|
|||
|
||||
class Capybara::Selenium::Driver < Capybara::Driver::Base
|
||||
DEFAULT_OPTIONS = {
|
||||
:resynchronize => false,
|
||||
:resynchronization_timeout => 10,
|
||||
:browser => :firefox
|
||||
}
|
||||
SPECIAL_OPTIONS = [:browser, :resynchronize, :resynchronization_timeout]
|
||||
SPECIAL_OPTIONS = [:browser]
|
||||
|
||||
attr_reader :app, :rack_server, :options
|
||||
|
||||
|
@ -56,18 +54,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
|
||||
def wait?; true; end
|
||||
|
||||
def resynchronize
|
||||
if options[:resynchronize]
|
||||
load_wait_for_ajax_support
|
||||
yield
|
||||
Capybara.timeout(options[:resynchronization_timeout], self, "failed to resynchronize, ajax request timed out") do
|
||||
evaluate_script("!window.capybaraRequestsOutstanding")
|
||||
end
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def execute_script(script)
|
||||
browser.execute_script script
|
||||
end
|
||||
|
@ -79,8 +65,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
def reset!
|
||||
# Use instance variable directly so we avoid starting the browser just to reset the session
|
||||
if @browser
|
||||
begin
|
||||
@browser.manage.delete_all_cookies
|
||||
begin @browser.manage.delete_all_cookies
|
||||
rescue Selenium::WebDriver::Error::UnhandledError
|
||||
# delete_all_cookies fails when we've previously gone
|
||||
# to about:blank, so we rescue this error and do nothing
|
||||
|
@ -129,35 +114,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
|||
|
||||
private
|
||||
|
||||
def load_wait_for_ajax_support
|
||||
browser.execute_script <<-JS
|
||||
window.capybaraRequestsOutstanding = 0;
|
||||
(function() { // Overriding XMLHttpRequest
|
||||
var oldXHR = window.XMLHttpRequest;
|
||||
|
||||
function newXHR() {
|
||||
var realXHR = new oldXHR();
|
||||
|
||||
window.capybaraRequestsOutstanding++;
|
||||
realXHR.addEventListener("readystatechange", function() {
|
||||
if( realXHR.readyState == 4 ) {
|
||||
setTimeout( function() {
|
||||
window.capybaraRequestsOutstanding--;
|
||||
if(window.capybaraRequestsOutstanding < 0) {
|
||||
window.capybaraRequestsOutstanding = 0;
|
||||
}
|
||||
}, 500 );
|
||||
}
|
||||
}, false);
|
||||
|
||||
return realXHR;
|
||||
}
|
||||
|
||||
window.XMLHttpRequest = newXHR;
|
||||
})();
|
||||
JS
|
||||
end
|
||||
|
||||
def url(path)
|
||||
rack_server.url(path)
|
||||
end
|
||||
|
|
|
@ -23,34 +23,30 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
elsif tag_name == 'input' and type == 'checkbox'
|
||||
click if value ^ native.attribute('checked').to_s.eql?("true")
|
||||
elsif tag_name == 'input' and type == 'file'
|
||||
resynchronize do
|
||||
native.send_keys(value.to_s)
|
||||
end
|
||||
native.send_keys(value.to_s)
|
||||
elsif tag_name == 'textarea' or tag_name == 'input'
|
||||
resynchronize do
|
||||
native.clear
|
||||
native.send_keys(value.to_s)
|
||||
end
|
||||
native.clear
|
||||
native.send_keys(value.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
def select_option
|
||||
resynchronize { native.click } unless selected?
|
||||
native.click unless selected?
|
||||
end
|
||||
|
||||
def unselect_option
|
||||
if select_node['multiple'] != 'multiple' and select_node['multiple'] != 'true'
|
||||
raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
|
||||
end
|
||||
resynchronize { native.click } if selected?
|
||||
native.click if selected?
|
||||
end
|
||||
|
||||
def click
|
||||
resynchronize { native.click }
|
||||
native.click
|
||||
end
|
||||
|
||||
def drag_to(element)
|
||||
resynchronize { driver.browser.action.drag_and_drop(native, element.native).perform }
|
||||
driver.browser.action.drag_and_drop(native, element.native).perform
|
||||
end
|
||||
|
||||
def tag_name
|
||||
|
@ -75,10 +71,6 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
|
|||
|
||||
private
|
||||
|
||||
def resynchronize
|
||||
driver.resynchronize { yield }
|
||||
end
|
||||
|
||||
# a reference to the select node if this is an option node
|
||||
def select_node
|
||||
find('./ancestor::select').first
|
||||
|
|
|
@ -134,41 +134,6 @@ shared_examples_for "driver with javascript support" do
|
|||
|
||||
end
|
||||
|
||||
shared_examples_for "driver with resynchronization support" do
|
||||
before { @driver.visit('/with_js') }
|
||||
describe "#find" do
|
||||
context "with synchronization turned on" do
|
||||
before { @driver.options[:resynchronize] = true }
|
||||
it "should wait for all ajax requests to finish" do
|
||||
@driver.find('//input[@id="fire_ajax_request"]').first.click
|
||||
@driver.find('//p[@id="ajax_request_done"]').should_not be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "with resynchronization turned off" do
|
||||
before { @driver.options[:resynchronize] = false }
|
||||
it "should not wait for ajax requests to finish" do
|
||||
@driver.find('//input[@id="fire_ajax_request"]').first.click
|
||||
@driver.find('//p[@id="ajax_request_done"]').should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context "with short synchronization timeout" do
|
||||
before { @driver.options[:resynchronize] = true }
|
||||
before { @driver.options[:resynchronization_timeout] = 0.1 }
|
||||
|
||||
it "should raise an error" do
|
||||
expect do
|
||||
@driver.find('//input[@id="fire_ajax_request"]').first.click
|
||||
end.to raise_error(Capybara::TimeoutError, "failed to resynchronize, ajax request timed out")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
after { @driver.options[:resynchronize] = false }
|
||||
after { @driver.options[:resynchronization_timeout] = 10 }
|
||||
end
|
||||
|
||||
shared_examples_for "driver with header support" do
|
||||
it "should make headers available through response_headers" do
|
||||
@driver.visit('/with_simple_html')
|
||||
|
|
|
@ -8,7 +8,6 @@ describe Capybara::Selenium::Driver do
|
|||
|
||||
it_should_behave_like "driver"
|
||||
it_should_behave_like "driver with javascript support"
|
||||
it_should_behave_like "driver with resynchronization support"
|
||||
it_should_behave_like "driver with frame support"
|
||||
it_should_behave_like "driver with support for window switching"
|
||||
it_should_behave_like "driver without status code support"
|
||||
|
|
Loading…
Reference in New Issue