capybara 2.15.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/History.md +137 -2
- data/README.md +36 -25
- data/lib/capybara/config.rb +11 -57
- data/lib/capybara/cucumber.rb +2 -3
- data/lib/capybara/driver/base.rb +19 -16
- data/lib/capybara/driver/node.rb +5 -4
- data/lib/capybara/dsl.rb +1 -0
- data/lib/capybara/helpers.rb +19 -29
- data/lib/capybara/minitest/spec.rb +16 -13
- data/lib/capybara/minitest.rb +140 -137
- data/lib/capybara/node/actions.rb +68 -89
- data/lib/capybara/node/base.rb +11 -18
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +8 -8
- data/lib/capybara/node/element.rb +32 -42
- data/lib/capybara/node/finders.rb +64 -71
- data/lib/capybara/node/matchers.rb +50 -71
- data/lib/capybara/node/simple.rb +11 -17
- data/lib/capybara/queries/ancestor_query.rb +12 -8
- data/lib/capybara/queries/base_query.rb +22 -18
- data/lib/capybara/queries/current_path_query.rb +12 -25
- data/lib/capybara/queries/match_query.rb +3 -7
- data/lib/capybara/queries/selector_query.rb +100 -96
- data/lib/capybara/queries/sibling_query.rb +5 -5
- data/lib/capybara/queries/text_query.rb +35 -35
- data/lib/capybara/queries/title_query.rb +8 -11
- data/lib/capybara/rack_test/browser.rb +15 -18
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +6 -10
- data/lib/capybara/rack_test/form.rb +52 -39
- data/lib/capybara/rack_test/node.rb +93 -63
- data/lib/capybara/rails.rb +2 -6
- data/lib/capybara/result.rb +22 -22
- data/lib/capybara/rspec/compound.rb +5 -10
- data/lib/capybara/rspec/features.rb +17 -48
- data/lib/capybara/rspec/matcher_proxies.rb +31 -15
- data/lib/capybara/rspec/matchers.rb +116 -58
- data/lib/capybara/rspec.rb +5 -10
- data/lib/capybara/selector/css.rb +6 -11
- data/lib/capybara/selector/filter.rb +1 -17
- data/lib/capybara/selector/filter_set.rb +18 -15
- data/lib/capybara/selector/filters/base.rb +7 -6
- data/lib/capybara/selector/filters/expression_filter.rb +6 -23
- data/lib/capybara/selector/filters/node_filter.rb +2 -12
- data/lib/capybara/selector/selector.rb +28 -34
- data/lib/capybara/selector.rb +129 -117
- data/lib/capybara/selenium/driver.rb +172 -163
- data/lib/capybara/selenium/node.rb +218 -104
- data/lib/capybara/server.rb +3 -2
- data/lib/capybara/session/config.rb +47 -59
- data/lib/capybara/session/matchers.rb +23 -14
- data/lib/capybara/session.rb +175 -229
- data/lib/capybara/spec/fixtures/no_extension +1 -0
- data/lib/capybara/spec/public/test.js +38 -6
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
- data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
- data/lib/capybara/spec/session/accept_prompt_spec.rb +30 -1
- data/lib/capybara/spec/session/all_spec.rb +31 -18
- data/lib/capybara/spec/session/ancestor_spec.rb +6 -8
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
- data/lib/capybara/spec/session/assert_current_path.rb +12 -11
- data/lib/capybara/spec/session/assert_selector.rb +1 -0
- data/lib/capybara/spec/session/assert_text.rb +31 -23
- data/lib/capybara/spec/session/assert_title.rb +13 -3
- data/lib/capybara/spec/session/attach_file_spec.rb +57 -29
- data/lib/capybara/spec/session/body_spec.rb +1 -0
- data/lib/capybara/spec/session/check_spec.rb +7 -6
- data/lib/capybara/spec/session/choose_spec.rb +5 -4
- data/lib/capybara/spec/session/click_button_spec.rb +24 -32
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
- data/lib/capybara/spec/session/click_link_spec.rb +8 -7
- data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
- data/lib/capybara/spec/session/current_url_spec.rb +19 -8
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
- data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +5 -4
- data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
- data/lib/capybara/spec/session/fill_in_spec.rb +30 -5
- data/lib/capybara/spec/session/find_button_spec.rb +4 -3
- data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
- data/lib/capybara/spec/session/find_field_spec.rb +9 -15
- data/lib/capybara/spec/session/find_link_spec.rb +6 -5
- data/lib/capybara/spec/session/find_spec.rb +37 -31
- data/lib/capybara/spec/session/first_spec.rb +60 -33
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
- data/lib/capybara/spec/session/go_back_spec.rb +1 -0
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
- data/lib/capybara/spec/session/has_button_spec.rb +2 -1
- data/lib/capybara/spec/session/has_css_spec.rb +3 -2
- data/lib/capybara/spec/session/has_current_path_spec.rb +49 -22
- data/lib/capybara/spec/session/has_field_spec.rb +4 -3
- data/lib/capybara/spec/session/has_link_spec.rb +5 -4
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +76 -0
- data/lib/capybara/spec/session/has_select_spec.rb +32 -31
- data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
- data/lib/capybara/spec/session/has_table_spec.rb +2 -1
- data/lib/capybara/spec/session/has_text_spec.rb +9 -13
- data/lib/capybara/spec/session/has_title_spec.rb +1 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
- data/lib/capybara/spec/session/headers.rb +2 -1
- data/lib/capybara/spec/session/html_spec.rb +1 -0
- data/lib/capybara/spec/session/node_spec.rb +107 -58
- data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
- data/lib/capybara/spec/session/refresh_spec.rb +6 -2
- data/lib/capybara/spec/session/reset_session_spec.rb +19 -0
- data/lib/capybara/spec/session/response_code.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
- data/lib/capybara/spec/session/save_page_spec.rb +1 -17
- data/lib/capybara/spec/session/save_screenshot_spec.rb +3 -3
- data/lib/capybara/spec/session/select_spec.rb +21 -20
- data/lib/capybara/spec/session/selectors_spec.rb +2 -2
- data/lib/capybara/spec/session/sibling_spec.rb +1 -1
- data/lib/capybara/spec/session/text_spec.rb +17 -3
- data/lib/capybara/spec/session/title_spec.rb +11 -1
- data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
- data/lib/capybara/spec/session/unselect_spec.rb +7 -6
- data/lib/capybara/spec/session/visit_spec.rb +64 -3
- data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_spec.rb +12 -12
- data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
- data/lib/capybara/spec/session/window/within_window_spec.rb +15 -71
- data/lib/capybara/spec/session/within_spec.rb +1 -0
- data/lib/capybara/spec/spec_helper.rb +36 -18
- data/lib/capybara/spec/test_app.rb +17 -9
- data/lib/capybara/spec/views/form.erb +7 -0
- data/lib/capybara/spec/views/initial_alert.erb +10 -0
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
- data/lib/capybara/spec/views/with_hover.erb +5 -0
- data/lib/capybara/spec/views/with_html.erb +27 -1
- data/lib/capybara/spec/views/with_js.erb +11 -0
- data/lib/capybara/spec/views/within_frames.erb +4 -1
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +6 -10
- data/lib/capybara.rb +29 -26
- data/spec/basic_node_spec.rb +1 -0
- data/spec/capybara_spec.rb +16 -69
- data/spec/dsl_spec.rb +5 -13
- data/spec/filter_set_spec.rb +5 -4
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
- data/spec/minitest_spec.rb +13 -4
- data/spec/minitest_spec_spec.rb +12 -3
- data/spec/per_session_config_spec.rb +9 -8
- data/spec/rack_test_spec.rb +21 -20
- data/spec/result_spec.rb +17 -16
- data/spec/rspec/features_spec.rb +17 -14
- data/spec/rspec/scenarios_spec.rb +5 -7
- data/spec/rspec/shared_spec_matchers.rb +96 -99
- data/spec/rspec/views_spec.rb +2 -1
- data/spec/rspec_matchers_spec.rb +18 -2
- data/spec/rspec_spec.rb +11 -15
- data/spec/selector_spec.rb +5 -6
- data/spec/selenium_spec_chrome.rb +20 -11
- data/spec/selenium_spec_edge.rb +27 -0
- data/spec/selenium_spec_ie.rb +31 -0
- data/spec/selenium_spec_marionette.rb +38 -12
- data/spec/server_spec.rb +33 -33
- data/spec/session_spec.rb +2 -1
- data/spec/shared_selenium_session.rb +82 -22
- data/spec/spec_helper.rb +3 -6
- metadata +76 -81
- data/lib/capybara/query.rb +0 -7
- data/spec/selenium_spec_firefox.rb +0 -68
data/spec/rspec_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
|
-
RSpec.describe 'capybara/rspec', :
|
5
|
+
RSpec.describe 'capybara/rspec', type: :feature do
|
5
6
|
it "should include Capybara in rspec" do
|
6
7
|
visit('/foo')
|
7
8
|
expect(page.body).to include('Another World')
|
@@ -37,21 +38,20 @@ RSpec.describe 'capybara/rspec', :type => :feature do
|
|
37
38
|
expect(Capybara.current_driver).to eq(Capybara.javascript_driver)
|
38
39
|
end
|
39
40
|
|
40
|
-
it "switches to the given driver when giving it as metadata", :
|
41
|
+
it "switches to the given driver when giving it as metadata", driver: :culerity do
|
41
42
|
expect(Capybara.current_driver).to eq(:culerity)
|
42
43
|
end
|
43
44
|
|
44
45
|
context "#all" do
|
45
46
|
it "allows access to the Capybara finder" do
|
46
47
|
visit('/with_html')
|
47
|
-
|
48
|
+
found = all(:css, 'h2') { |element| element[:class] == 'head' }
|
49
|
+
expect(found.size).to eq(5)
|
48
50
|
end
|
49
51
|
|
50
52
|
it "allows access to the RSpec matcher" do
|
51
|
-
skip "RSpec < 3 doesn't have an `all` matcher" if rspec2?
|
52
|
-
|
53
53
|
visit('/with_html')
|
54
|
-
expect([
|
54
|
+
expect(%w[test1 test2]).to all(be_a(String))
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -64,7 +64,6 @@ RSpec.describe 'capybara/rspec', :type => :feature do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "allows access to the RSpec matcher" do
|
67
|
-
skip "RSpec version doesn't have a 'within' matcher" unless ::RSpec::Matchers.instance_methods.include?(:within)
|
68
67
|
visit('/with_html')
|
69
68
|
# This reads terribly, but must call #within
|
70
69
|
expect(find(:css, 'span.number').text.to_i).to within(1).of(41)
|
@@ -72,15 +71,15 @@ RSpec.describe 'capybara/rspec', :type => :feature do
|
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
75
|
-
RSpec.describe 'capybara/rspec', :
|
74
|
+
RSpec.describe 'capybara/rspec', type: :other do
|
76
75
|
context "when RSpec::Matchers is included after Capybara::DSL" do
|
77
76
|
before do
|
78
|
-
class
|
77
|
+
class DSLMatchersTest
|
79
78
|
include Capybara::DSL
|
80
79
|
include RSpec::Matchers
|
81
80
|
end
|
82
81
|
|
83
|
-
@test_class_instance =
|
82
|
+
@test_class_instance = DSLMatchersTest.new
|
84
83
|
end
|
85
84
|
|
86
85
|
context "#all" do
|
@@ -90,10 +89,8 @@ RSpec.describe 'capybara/rspec', :type => :other do
|
|
90
89
|
end
|
91
90
|
|
92
91
|
it "allows access to the RSpec matcher" do
|
93
|
-
skip "RSpec < 3 doesn't have an `all` matcher" if rspec2?
|
94
|
-
|
95
92
|
@test_class_instance.visit('/with_html')
|
96
|
-
expect([
|
93
|
+
expect(%w[test1 test2]).to @test_class_instance.all(be_a(String))
|
97
94
|
end
|
98
95
|
end
|
99
96
|
|
@@ -106,7 +103,6 @@ RSpec.describe 'capybara/rspec', :type => :other do
|
|
106
103
|
end
|
107
104
|
|
108
105
|
it "allows access to the RSpec matcher" do
|
109
|
-
skip "RSpec version doesn't have a 'within' matcher" unless ::RSpec::Matchers.instance_methods.include?(:within)
|
110
106
|
@test_class_instance.visit('/with_html')
|
111
107
|
# This reads terribly, but must call #within
|
112
108
|
expect(@test_class_instance.find(:css, 'span.number').text.to_i).to @test_class_instance.within(1).of(41)
|
@@ -115,7 +111,7 @@ RSpec.describe 'capybara/rspec', :type => :other do
|
|
115
111
|
end
|
116
112
|
end
|
117
113
|
|
118
|
-
RSpec.describe 'capybara/rspec', :
|
114
|
+
RSpec.describe 'capybara/rspec', type: :other do
|
119
115
|
it "should not include Capybara" do
|
120
116
|
expect { visit('/') }.to raise_error(NoMethodError)
|
121
117
|
end
|
data/spec/selector_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe Capybara do
|
@@ -56,7 +57,7 @@ RSpec.describe Capybara do
|
|
56
57
|
it "can set default visiblity" do
|
57
58
|
Capybara.add_selector :hidden_field do
|
58
59
|
visible :hidden
|
59
|
-
css { |
|
60
|
+
css { |_sel| 'input[type="hidden"]' }
|
60
61
|
end
|
61
62
|
|
62
63
|
expect(string).to have_no_css('input[type="hidden"]')
|
@@ -77,7 +78,7 @@ RSpec.describe Capybara do
|
|
77
78
|
|
78
79
|
it "doesn't change existing filters" do
|
79
80
|
Capybara.modify_selector :custom_selector do
|
80
|
-
css { |css_class| "p.#{css_class}"}
|
81
|
+
css { |css_class| "p.#{css_class}" }
|
81
82
|
end
|
82
83
|
expect(string).to have_selector(:custom_selector, 'b', count: 1)
|
83
84
|
expect(string).to have_selector(:custom_selector, 'b', not_empty: false, count: 1)
|
@@ -92,7 +93,7 @@ RSpec.describe Capybara do
|
|
92
93
|
field: ".//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]",
|
93
94
|
fieldset: ".//fieldset",
|
94
95
|
link: ".//a[./@href]",
|
95
|
-
link_or_button: ".//a[./@href] | .//input[./@type = 'submit' or ./@type = 'reset' or ./@type = 'image' or ./@type = 'button'] | .//button"
|
96
|
+
link_or_button: ".//a[./@href] | .//input[./@type = 'submit' or ./@type = 'reset' or ./@type = 'image' or ./@type = 'button'] | .//button",
|
96
97
|
fillable_field: ".//*[self::input | self::textarea][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'radio' or ./@type = 'checkbox' or ./@type = 'hidden' or ./@type = 'file')]",
|
97
98
|
radio_button: ".//input[./@type = 'radio']",
|
98
99
|
checkbox: ".//input[./@type = 'checkbox']",
|
@@ -102,7 +103,7 @@ RSpec.describe Capybara do
|
|
102
103
|
table: ".//table"
|
103
104
|
}
|
104
105
|
selectors.each do |selector, xpath|
|
105
|
-
results = string.all(selector,nil).to_a.map(&:native)
|
106
|
+
results = string.all(selector, nil).to_a.map(&:native)
|
106
107
|
expect(results.size).to be > 0
|
107
108
|
expect(results).to eq string.all(:xpath, xpath).to_a.map(&:native)
|
108
109
|
end
|
@@ -116,7 +117,6 @@ RSpec.describe Capybara do
|
|
116
117
|
end
|
117
118
|
|
118
119
|
it "works with 'special' characters" do
|
119
|
-
skip "We support old Nokogiris but they have their limits" if Gem::Version.new(Nokogiri::VERSION) < Gem::Version.new('1.6.8')
|
120
120
|
expect(string.find(:custom_css_selector, "div", id: "#special")[:id]).to eq '#special'
|
121
121
|
expect(string.find(:custom_css_selector, "input", id: "2checkbox")[:id]).to eq '2checkbox'
|
122
122
|
end
|
@@ -129,7 +129,6 @@ RSpec.describe Capybara do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it "works with 'special' characters" do
|
132
|
-
skip "We support old Nokogiris but they have their limits" if Gem::Version.new(Nokogiri::VERSION) < Gem::Version.new('1.6.8')
|
133
132
|
expect(string.find(:custom_css_selector, "input", class: ".special")[:id]).to eq 'file'
|
134
133
|
expect(string.find(:custom_css_selector, "input", class: "2checkbox")[:id]).to eq '2checkbox'
|
135
134
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'selenium-webdriver'
|
4
5
|
require 'shared_selenium_session'
|
6
|
+
require 'rspec/shared_spec_matchers'
|
5
7
|
|
6
|
-
CHROME_DRIVER =
|
8
|
+
CHROME_DRIVER = ENV['HEADLESS'] ? :selenium_chrome_headless : :selenium_chrome
|
7
9
|
|
8
|
-
if ENV['HEADLESS'] && ENV['TRAVIS']
|
9
|
-
|
10
|
-
end
|
10
|
+
# if ENV['HEADLESS'] && ENV['TRAVIS']
|
11
|
+
# Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta'
|
12
|
+
# end
|
11
13
|
|
12
14
|
Capybara.register_driver :selenium_chrome_clear_storage do |app|
|
13
15
|
chrome_options = {
|
14
16
|
browser: :chrome,
|
15
|
-
options: ::Selenium::WebDriver::Chrome::Options.new
|
17
|
+
options: ::Selenium::WebDriver::Chrome::Options.new
|
16
18
|
}
|
17
19
|
chrome_options[:options].args << 'headless' if ENV['HEADLESS']
|
18
20
|
Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: true, clear_session_storage: true))
|
@@ -22,15 +24,18 @@ module TestSessions
|
|
22
24
|
Chrome = Capybara::Session.new(CHROME_DRIVER, TestApp)
|
23
25
|
end
|
24
26
|
|
25
|
-
skipped_tests = [
|
27
|
+
skipped_tests = %i[response_headers status_code trigger]
|
26
28
|
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome
|
27
|
-
skipped_tests << :windows if ENV['TRAVIS']
|
29
|
+
skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])
|
30
|
+
|
31
|
+
$stdout.puts `#{Selenium::WebDriver::Chrome.driver_path} --version` if ENV['CI']
|
28
32
|
|
29
33
|
Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, capybara_skip: skipped_tests
|
30
34
|
|
31
35
|
RSpec.describe "Capybara::Session with chrome" do
|
32
36
|
include Capybara::SpecHelper
|
33
37
|
include_examples "Capybara::Session", TestSessions::Chrome, CHROME_DRIVER
|
38
|
+
include_examples Capybara::RSpecMatchers, TestSessions::Chrome, CHROME_DRIVER
|
34
39
|
|
35
40
|
context "storage" do
|
36
41
|
describe "#reset!" do
|
@@ -40,8 +45,10 @@ RSpec.describe "Capybara::Session with chrome" do
|
|
40
45
|
@session.find(:css, '#set-storage').click
|
41
46
|
@session.reset!
|
42
47
|
@session.visit('/with_js')
|
43
|
-
expect(@session.driver.browser.local_storage.keys).not_to be_empty
|
44
|
-
expect(@session.driver.browser.session_storage.keys).not_to be_empty
|
48
|
+
# expect(@session.driver.browser.local_storage.keys).not_to be_empty
|
49
|
+
# expect(@session.driver.browser.session_storage.keys).not_to be_empty
|
50
|
+
expect(@session.evaluate_script('Object.keys(localStorage)')).not_to be_empty
|
51
|
+
expect(@session.evaluate_script('Object.keys(sessionStorage)')).not_to be_empty
|
45
52
|
end
|
46
53
|
|
47
54
|
it "clears storage when set" do
|
@@ -50,8 +57,10 @@ RSpec.describe "Capybara::Session with chrome" do
|
|
50
57
|
@session.find(:css, '#set-storage').click
|
51
58
|
@session.reset!
|
52
59
|
@session.visit('/with_js')
|
53
|
-
expect(@session.driver.browser.local_storage.keys).to be_empty
|
54
|
-
expect(@session.driver.browser.session_storage.keys).to be_empty
|
60
|
+
# expect(@session.driver.browser.local_storage.keys).to be_empty
|
61
|
+
# expect(@session.driver.browser.session_storage.keys).to be_empty
|
62
|
+
expect(@session.evaluate_script('Object.keys(localStorage)')).to be_empty
|
63
|
+
expect(@session.evaluate_script('Object.keys(sessionStorage)')).to be_empty
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "selenium-webdriver"
|
5
|
+
require 'shared_selenium_session'
|
6
|
+
require 'rspec/shared_spec_matchers'
|
7
|
+
|
8
|
+
Capybara.register_driver :selenium_edge do |app|
|
9
|
+
# ::Selenium::WebDriver.logger.level = "debug"
|
10
|
+
Capybara::Selenium::Driver.new(app, browser: :edge)
|
11
|
+
end
|
12
|
+
|
13
|
+
module TestSessions
|
14
|
+
SeleniumEdge = Capybara::Session.new(:selenium_edge, TestApp)
|
15
|
+
end
|
16
|
+
|
17
|
+
skipped_tests = %i[response_headers status_code trigger modals]
|
18
|
+
|
19
|
+
$stdout.puts `#{Selenium::WebDriver::Edge.driver_path} --version` if ENV['CI']
|
20
|
+
|
21
|
+
Capybara::SpecHelper.run_specs TestSessions::SeleniumEdge, "selenium", capybara_skip: skipped_tests
|
22
|
+
|
23
|
+
RSpec.describe "Capybara::Session with Edge", capybara_skip: skipped_tests do
|
24
|
+
include Capybara::SpecHelper
|
25
|
+
include_examples "Capybara::Session", TestSessions::SeleniumEdge, :selenium_edge
|
26
|
+
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumEdge, :selenium_edge
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "selenium-webdriver"
|
5
|
+
require 'shared_selenium_session'
|
6
|
+
require 'rspec/shared_spec_matchers'
|
7
|
+
|
8
|
+
Capybara.register_driver :selenium_ie do |app|
|
9
|
+
# ::Selenium::WebDriver.logger.level = "debug"
|
10
|
+
Capybara::Selenium::Driver.new(
|
11
|
+
app,
|
12
|
+
browser: :ie,
|
13
|
+
desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.ie('requireWindowFocus': true)
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
module TestSessions
|
18
|
+
SeleniumIE = Capybara::Session.new(:selenium_ie, TestApp)
|
19
|
+
end
|
20
|
+
|
21
|
+
skipped_tests = %i[response_headers status_code trigger modals hover form_attribute windows]
|
22
|
+
|
23
|
+
$stdout.puts `#{Selenium::WebDriver::IE.driver_path} --version` if ENV['CI']
|
24
|
+
|
25
|
+
Capybara::SpecHelper.run_specs TestSessions::SeleniumIE, "selenium", capybara_skip: skipped_tests
|
26
|
+
|
27
|
+
RSpec.describe "Capybara::Session with Internet Explorer", capybara_skip: skipped_tests do
|
28
|
+
include Capybara::SpecHelper
|
29
|
+
include_examples "Capybara::Session", TestSessions::SeleniumIE, :selenium_ie
|
30
|
+
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumIE, :selenium_ie
|
31
|
+
end
|
@@ -1,16 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require "selenium-webdriver"
|
4
5
|
require 'shared_selenium_session'
|
5
6
|
require 'rspec/shared_spec_matchers'
|
6
7
|
|
7
|
-
|
8
|
+
browser_options = ::Selenium::WebDriver::Firefox::Options.new
|
9
|
+
browser_options.args << '--headless' if ENV['HEADLESS']
|
10
|
+
browser_options.add_preference 'dom.file.createInChild', true
|
11
|
+
# browser_options.add_option("log", {"level": "trace"})
|
8
12
|
|
9
13
|
Capybara.register_driver :selenium_marionette do |app|
|
14
|
+
# ::Selenium::WebDriver.logger.level = "debug"
|
10
15
|
Capybara::Selenium::Driver.new(
|
11
16
|
app,
|
12
17
|
browser: :firefox,
|
13
|
-
desired_capabilities: {marionette: true}
|
18
|
+
desired_capabilities: { marionette: true, 'moz:webdriverClick': true },
|
19
|
+
options: browser_options
|
20
|
+
# Get a trace level log from geckodriver
|
21
|
+
# :driver_opts => { args: ['-vv'] }
|
14
22
|
)
|
15
23
|
end
|
16
24
|
|
@@ -18,9 +26,10 @@ Capybara.register_driver :selenium_marionette_clear_storage do |app|
|
|
18
26
|
Capybara::Selenium::Driver.new(
|
19
27
|
app,
|
20
28
|
browser: :firefox,
|
21
|
-
desired_capabilities: {marionette: true},
|
29
|
+
desired_capabilities: { marionette: true },
|
22
30
|
clear_local_storage: true,
|
23
|
-
clear_session_storage: true
|
31
|
+
clear_session_storage: true,
|
32
|
+
options: browser_options
|
24
33
|
)
|
25
34
|
end
|
26
35
|
|
@@ -28,13 +37,11 @@ module TestSessions
|
|
28
37
|
SeleniumMarionette = Capybara::Session.new(:selenium_marionette, TestApp)
|
29
38
|
end
|
30
39
|
|
31
|
-
skipped_tests = [
|
32
|
-
:response_headers,
|
33
|
-
:status_code,
|
34
|
-
:trigger
|
35
|
-
]
|
40
|
+
skipped_tests = %i[response_headers status_code trigger]
|
36
41
|
skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
|
37
42
|
|
43
|
+
$stdout.puts `#{Selenium::WebDriver::Firefox.driver_path} --version` if ENV['CI']
|
44
|
+
|
38
45
|
Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, "selenium", capybara_skip: skipped_tests
|
39
46
|
|
40
47
|
RSpec.describe "Capybara::Session with firefox" do
|
@@ -45,14 +52,14 @@ end
|
|
45
52
|
|
46
53
|
RSpec.describe Capybara::Selenium::Driver do
|
47
54
|
before do
|
48
|
-
@driver = Capybara::Selenium::Driver.new(TestApp, browser: :firefox)
|
55
|
+
@driver = Capybara::Selenium::Driver.new(TestApp, browser: :firefox, options: browser_options)
|
49
56
|
end
|
50
57
|
|
51
58
|
describe '#quit' do
|
52
59
|
it "should reset browser when quit" do
|
53
60
|
expect(@driver.browser).to be
|
54
61
|
@driver.quit
|
55
|
-
#access instance variable directly so we don't create a new browser instance
|
62
|
+
# access instance variable directly so we don't create a new browser instance
|
56
63
|
expect(@driver.instance_variable_get(:@browser)).to be_nil
|
57
64
|
end
|
58
65
|
|
@@ -113,5 +120,24 @@ RSpec.describe Capybara::Selenium::Driver do
|
|
113
120
|
end
|
114
121
|
end
|
115
122
|
end
|
116
|
-
end
|
117
123
|
|
124
|
+
context "#refresh" do
|
125
|
+
def extract_results(session)
|
126
|
+
expect(session).to have_xpath("//pre[@id='results']")
|
127
|
+
YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
|
128
|
+
end
|
129
|
+
|
130
|
+
it "can repost by accepting confirm" do
|
131
|
+
@session = TestSessions::SeleniumMarionette
|
132
|
+
@session.visit('/form')
|
133
|
+
@session.select('Sweden', from: 'form_region')
|
134
|
+
@session.click_button('awesome')
|
135
|
+
expect do
|
136
|
+
@session.accept_confirm(wait: 0.1) do
|
137
|
+
@session.refresh
|
138
|
+
sleep 2
|
139
|
+
end
|
140
|
+
end.to change { extract_results(@session)['post_count'] }.by(1)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/spec/server_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe Capybara::Server do
|
5
|
-
|
6
6
|
it "should spool up a rack server" do
|
7
|
-
@app = proc { |
|
7
|
+
@app = proc { |_env| [200, {}, ["Hello Server!"]] }
|
8
8
|
@server = Capybara::Server.new(@app).boot
|
9
9
|
|
10
10
|
@res = Net::HTTP.start(@server.host, @server.port) { |http| http.get('/') }
|
@@ -19,8 +19,9 @@ RSpec.describe Capybara::Server do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should bind to the specified host" do
|
22
|
+
# TODO: travis with jruby in container mode has an issue with this test
|
22
23
|
begin
|
23
|
-
app = proc { |
|
24
|
+
app = proc { |_env| [200, {}, ['Hello Server!']] }
|
24
25
|
|
25
26
|
Capybara.server_host = '127.0.0.1'
|
26
27
|
server = Capybara::Server.new(app).boot
|
@@ -34,12 +35,12 @@ RSpec.describe Capybara::Server do
|
|
34
35
|
ensure
|
35
36
|
Capybara.server_host = nil
|
36
37
|
end
|
37
|
-
end unless ENV['TRAVIS']
|
38
|
+
end unless ENV['TRAVIS'] && (RUBY_ENGINE == 'jruby') or Gem.win_platform?
|
38
39
|
|
39
40
|
it "should use specified port" do
|
40
41
|
Capybara.server_port = 22789
|
41
42
|
|
42
|
-
@app = proc { |
|
43
|
+
@app = proc { |_env| [200, {}, ["Hello Server!"]] }
|
43
44
|
@server = Capybara::Server.new(@app).boot
|
44
45
|
|
45
46
|
@res = Net::HTTP.start(@server.host, 22789) { |http| http.get('/') }
|
@@ -49,7 +50,7 @@ RSpec.describe Capybara::Server do
|
|
49
50
|
end
|
50
51
|
|
51
52
|
it "should use given port" do
|
52
|
-
@app = proc { |
|
53
|
+
@app = proc { |_env| [200, {}, ["Hello Server!"]] }
|
53
54
|
@server = Capybara::Server.new(@app, 22790).boot
|
54
55
|
|
55
56
|
@res = Net::HTTP.start(@server.host, 22790) { |http| http.get('/') }
|
@@ -59,8 +60,8 @@ RSpec.describe Capybara::Server do
|
|
59
60
|
end
|
60
61
|
|
61
62
|
it "should find an available port" do
|
62
|
-
@app1 = proc { |
|
63
|
-
@app2 = proc { |
|
63
|
+
@app1 = proc { |_env| [200, {}, ["Hello Server!"]] }
|
64
|
+
@app2 = proc { |_env| [200, {}, ["Hello Second Server!"]] }
|
64
65
|
|
65
66
|
@server1 = Capybara::Server.new(@app1).boot
|
66
67
|
@server2 = Capybara::Server.new(@app2).boot
|
@@ -83,7 +84,7 @@ RSpec.describe Capybara::Server do
|
|
83
84
|
end
|
84
85
|
|
85
86
|
it "should use the existing server if it already running" do
|
86
|
-
@app = proc { |
|
87
|
+
@app = proc { |_env| [200, {}, ["Hello Server!"]] }
|
87
88
|
|
88
89
|
@server1 = Capybara::Server.new(@app).boot
|
89
90
|
@server2 = Capybara::Server.new(@app).boot
|
@@ -98,27 +99,25 @@ RSpec.describe Capybara::Server do
|
|
98
99
|
end
|
99
100
|
|
100
101
|
it "detects and waits for all reused server sessions pending requests" do
|
101
|
-
done =
|
102
|
+
done = 0
|
102
103
|
|
103
104
|
app = proc do |env|
|
104
105
|
request = Rack::Request.new(env)
|
105
106
|
sleep request.params['wait_time'].to_f
|
106
|
-
done
|
107
|
+
done += 1
|
107
108
|
[200, {}, ["Hello Server!"]]
|
108
109
|
end
|
109
110
|
|
110
111
|
server1 = Capybara::Server.new(app).boot
|
111
112
|
server2 = Capybara::Server.new(app).boot
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
expect {
|
114
|
+
expect do
|
115
|
+
start_request(server1, 1.0)
|
116
|
+
start_request(server2, 3.0)
|
117
117
|
server1.wait_for_pending_requests
|
118
|
-
|
118
|
+
end.to change { done }.from(0).to(2)
|
119
119
|
expect(server2.send(:pending_requests?)).to eq(false)
|
120
120
|
end
|
121
|
-
|
122
121
|
end
|
123
122
|
|
124
123
|
context "When Capybara.reuse_server is false" do
|
@@ -132,7 +131,7 @@ RSpec.describe Capybara::Server do
|
|
132
131
|
end
|
133
132
|
|
134
133
|
it "should not reuse an already running server" do
|
135
|
-
@app = proc { |
|
134
|
+
@app = proc { |_env| [200, {}, ["Hello Server!"]] }
|
136
135
|
|
137
136
|
@server1 = Capybara::Server.new(@app).boot
|
138
137
|
@server2 = Capybara::Server.new(@app).boot
|
@@ -147,48 +146,48 @@ RSpec.describe Capybara::Server do
|
|
147
146
|
end
|
148
147
|
|
149
148
|
it "detects and waits for only one sessions pending requests" do
|
150
|
-
done =
|
149
|
+
done = 0
|
151
150
|
|
152
151
|
app = proc do |env|
|
153
152
|
request = Rack::Request.new(env)
|
154
153
|
sleep request.params['wait_time'].to_f
|
155
|
-
done
|
154
|
+
done += 1
|
156
155
|
[200, {}, ["Hello Server!"]]
|
157
156
|
end
|
158
157
|
|
159
158
|
server1 = Capybara::Server.new(app).boot
|
160
159
|
server2 = Capybara::Server.new(app).boot
|
161
160
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
expect {
|
161
|
+
expect do
|
162
|
+
start_request(server1, 1.0)
|
163
|
+
start_request(server2, 3.0)
|
166
164
|
server1.wait_for_pending_requests
|
167
|
-
|
165
|
+
end.to change { done }.from(0).to(1)
|
168
166
|
expect(server2.send(:pending_requests?)).to eq(true)
|
167
|
+
expect do
|
168
|
+
server2.wait_for_pending_requests
|
169
|
+
end.to change { done }.from(1).to(2)
|
169
170
|
end
|
170
|
-
|
171
171
|
end
|
172
172
|
|
173
173
|
it "should raise server errors when the server errors before the timeout" do
|
174
174
|
begin
|
175
|
-
Capybara.
|
175
|
+
Capybara.register_server :kaboom do
|
176
176
|
sleep 0.1
|
177
177
|
raise 'kaboom'
|
178
178
|
end
|
179
|
+
Capybara.server = :kaboom
|
179
180
|
|
180
181
|
expect do
|
181
|
-
Capybara::Server.new(proc {|e|}).boot
|
182
|
+
Capybara::Server.new(proc { |e| }).boot
|
182
183
|
end.to raise_error(RuntimeError, 'kaboom')
|
183
184
|
ensure
|
184
|
-
|
185
|
-
# a one-time call in capybara.rb
|
186
|
-
Capybara.server {|app, port| Capybara.run_default_server(app, port)}
|
185
|
+
Capybara.server = :default
|
187
186
|
end
|
188
187
|
end
|
189
188
|
|
190
189
|
it "is not #responsive? when Net::HTTP raises a SystemCallError" do
|
191
|
-
app =
|
190
|
+
app = -> { [200, {}, ['Hello, world']] }
|
192
191
|
server = Capybara::Server.new(app)
|
193
192
|
expect(Net::HTTP).to receive(:start).and_raise(SystemCallError.allocate)
|
194
193
|
expect(server.responsive?).to eq false
|
@@ -197,7 +196,8 @@ RSpec.describe Capybara::Server do
|
|
197
196
|
def start_request(server, wait_time)
|
198
197
|
# Start request, but don't wait for it to finish
|
199
198
|
socket = TCPSocket.new(server.host, server.port)
|
200
|
-
socket.write "GET /?wait_time=#{wait_time
|
199
|
+
socket.write "GET /?wait_time=#{wait_time} HTTP/1.0\r\n\r\n"
|
200
|
+
sleep 0.1
|
201
201
|
socket.close
|
202
202
|
sleep 0.1
|
203
203
|
end
|
data/spec/session_spec.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe Capybara::Session do
|
5
6
|
it "verifies a passed app is a rack app" do
|
6
7
|
expect do
|
7
|
-
Capybara::Session.new(:unknown,
|
8
|
+
Capybara::Session.new(:unknown, random: "hash")
|
8
9
|
end.to raise_error TypeError, "The second parameter to Session::new should be a rack app if passed."
|
9
10
|
end
|
10
11
|
|