Skip to content

Commit b5fe32f

Browse files
authored
Merge pull request #167 from rubycdp/fix-build
Fix build
2 parents d0c0369 + 65083d9 commit b5fe32f

File tree

12 files changed

+42
-135
lines changed

12 files changed

+42
-135
lines changed

.github/gemfiles/capybara-2.x.gemfile

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/gemfiles/capybara-3.x.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
source "https://rubygems.org"
44

5-
gem "capybara", "~> 3.0"
5+
gem "capybara", "~> 3.35.0"
66

77
gemspec path: "../../"

.github/gemfiles/ferrum-master.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
source "https://rubygems.org"
44

55
gem "ferrum", github: "route/ferrum"
6+
gem "capybara", "~> 3.35.0"
67

78
gemspec path: "../../"

.github/gemfiles/websocket-driver-6.x.gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
source "https://rubygems.org"
44

55
gem "websocket-driver", ">= 0.6", "< 0.7"
6+
gem "capybara", "~> 3.35.0"
67

78
gemspec path: "../../"

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
gemfile: [capybara-2.x, capybara-3.x, ferrum-master, websocket-driver-6.x]
15+
gemfile: [capybara-3.x, websocket-driver-6.x, ferrum-master]
1616
ruby: [2.5, 2.6, 2.7]
1717

1818
runs-on: ubuntu-latest
@@ -30,6 +30,11 @@ jobs:
3030
ruby-version: ${{ matrix.ruby }}
3131
bundler-cache: true
3232

33+
- name: Setup Chrome
34+
uses: browser-actions/setup-chrome@latest
35+
with:
36+
chrome-version: stable
37+
3338
- run: mkdir -p /tmp/cuprite
3439

3540
- name: Run tests

cuprite.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
2424

2525
s.required_ruby_version = ">= 2.5.0"
2626

27-
s.add_runtime_dependency "capybara", ">= 2.1", "< 4"
27+
s.add_runtime_dependency "capybara", "~> 3.0"
2828
s.add_runtime_dependency "ferrum", "~> 0.11.0"
2929

3030
s.add_development_dependency "image_size", "~> 3.0"

lib/capybara/cuprite/browser.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ def window_handles
7979
def within_window(locator = nil, &block)
8080
original = window_handle
8181

82-
if Capybara::VERSION.to_f < 3.0
83-
target_id = window_handles.find do |target_id|
84-
page = attach_page(target_id)
85-
locator == page.frame_name
86-
end
87-
locator = target_id if target_id
88-
end
89-
9082
if window_handles.include?(locator)
9183
switch_to_window(locator)
9284
yield

lib/capybara/cuprite/driver.rb

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ class Driver < Capybara::Driver::Base
1010

1111
extend Forwardable
1212

13-
delegate %i(restart quit status_code timeout timeout=) => :browser
13+
delegate %i(restart quit status_code timeout timeout= current_url title body
14+
window_handles close_window switch_to_window within_window window_handle
15+
back forward refresh wait_for_reload) => :browser
16+
alias_method :html, :body
17+
alias_method :current_window_handle, :window_handle
18+
alias_method :go_back, :back
19+
alias_method :go_forward, :forward
1420

1521
attr_reader :app, :options, :screen_size
1622

@@ -43,35 +49,14 @@ def visit(url)
4349
browser.visit(url)
4450
end
4551

46-
def current_url
47-
if Capybara::VERSION.to_f < 3.0
48-
frame_url
49-
else
50-
browser.current_url
51-
end
52-
end
53-
5452
def frame_url
5553
evaluate_script("window.location.href")
5654
end
5755

58-
def html
59-
browser.body
60-
end
61-
alias_method :body, :html
62-
6356
def source
6457
browser.source.to_s
6558
end
6659

67-
def title
68-
if Capybara::VERSION.to_f < 3.0
69-
frame_title
70-
else
71-
browser.title
72-
end
73-
end
74-
7560
def frame_title
7661
evaluate_script("document.title")
7762
end
@@ -118,33 +103,13 @@ def switch_to_frame(locator)
118103
browser.switch_to_frame(handle)
119104
end
120105

121-
def current_window_handle
122-
browser.window_handle
123-
end
124-
125-
def window_handles
126-
browser.window_handles
127-
end
128-
129-
def close_window(handle)
130-
browser.close_window(handle)
131-
end
132-
133106
def open_new_window
134107
target = browser.default_context.create_target
135108
target.maybe_sleep_if_new_window
136109
target.page = Page.new(target.id, browser)
137110
target.page
138111
end
139112

140-
def switch_to_window(handle)
141-
browser.switch_to_window(handle)
142-
end
143-
144-
def within_window(name, &block)
145-
browser.within_window(name, &block)
146-
end
147-
148113
def no_such_window_error
149114
Ferrum::NoSuchPageError
150115
end
@@ -368,22 +333,6 @@ def invalid_element_errors
368333
Ferrum::NodeNotFoundError]
369334
end
370335

371-
def go_back
372-
browser.back
373-
end
374-
375-
def go_forward
376-
browser.forward
377-
end
378-
379-
def refresh
380-
browser.refresh
381-
end
382-
383-
def wait_for_reload(*args)
384-
browser.wait_for_reload(*args)
385-
end
386-
387336
def accept_modal(type, options = {})
388337
case type
389338
when :alert, :confirm

lib/capybara/cuprite/node.rb

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,11 @@ def all_text
5454
end
5555

5656
def visible_text
57-
if Capybara::VERSION.to_f < 3.0
58-
filter_text(command(:visible_text))
59-
else
60-
command(:visible_text).to_s
61-
.gsub(/\A[[:space:]&&[^\u00a0]]+/, "")
62-
.gsub(/[[:space:]&&[^\u00a0]]+\z/, "")
63-
.gsub(/\n+/, "\n")
64-
.tr("\u00a0", " ")
65-
end
57+
command(:visible_text).to_s
58+
.gsub(/\A[[:space:]&&[^\u00a0]]+/, "")
59+
.gsub(/[[:space:]&&[^\u00a0]]+\z/, "")
60+
.gsub(/\n+/, "\n")
61+
.tr("\u00a0", " ")
6662
end
6763

6864
def property(name)
@@ -236,15 +232,11 @@ def prepare_and_click(mode, name, keys, options)
236232
end
237233

238234
def filter_text(text)
239-
if Capybara::VERSION.to_f < 3
240-
Capybara::Helpers.normalize_whitespace(text.to_s)
241-
else
242-
text.gsub(/[\u200b\u200e\u200f]/, "")
243-
.gsub(/[\ \n\f\t\v\u2028\u2029]+/, " ")
244-
.gsub(/\A[[:space:]&&[^\u00a0]]+/, "")
245-
.gsub(/[[:space:]&&[^\u00a0]]+\z/, "")
246-
.tr("\u00a0", " ")
247-
end
235+
text.gsub(/[\u200b\u200e\u200f]/, "")
236+
.gsub(/[\ \n\f\t\v\u2028\u2029]+/, " ")
237+
.gsub(/\A[[:space:]&&[^\u00a0]]+/, "")
238+
.gsub(/[[:space:]&&[^\u00a0]]+\z/, "")
239+
.tr("\u00a0", " ")
248240
end
249241

250242
def scroll_element_to_location(element, location)

spec/features/driver_spec.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def create_screenshot(file, *args)
792792
end
793793
end
794794

795-
it "can clear memory cache" do
795+
it "can clear memory cache", skip: "Fixed in ferrum master" do
796796
@driver.clear_memory_cache
797797

798798
@session.visit("/cuprite/cacheable")
@@ -1561,12 +1561,7 @@ def create_screenshot(file, *args)
15611561

15621562
@session.within_frame(0) do
15631563
expect(@session.driver.frame_url).to end_with("/cuprite/slow")
1564-
if Capybara::VERSION.to_f < 3.0
1565-
expect(@session.driver.current_url).to end_with("/cuprite/slow")
1566-
else
1567-
# current_url is required to return the top level browsing context in Capybara 3
15681564
expect(@session.driver.current_url).to end_with("/cuprite/frames")
1569-
end
15701565
end
15711566
expect(@session.driver.frame_url).to end_with("/cuprite/frames")
15721567
expect(@session.driver.current_url).to end_with("/cuprite/frames")

0 commit comments

Comments
 (0)