Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
[rubycdp/ferrum#689]

### Fixed
- `scroll_to` with an element or a location waits for the scroll like `scroll_to(x, y)` and `scroll_by` already do,
instead of making Ferrum warn that the script returns a promise [#362]

### Removed
- Methods deprecated in 0.20, see its Deprecated section for replacements
Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/cuprite/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,15 @@ def scroll_element_to_location(element, location)
else
raise ArgumentError, "Invalid scroll_to location: #{location}"
end
element.node.evaluate("this.scrollIntoView(#{scroll_opts})")
element.node.evaluate("await this.scrollIntoView(#{scroll_opts})")
end

def scroll_to_location(location)
height = { top: "0",
bottom: "this.scrollHeight",
center: "(this.scrollHeight - this.clientHeight) / 2" }

node.evaluate("this.scrollTo(0, #{height[location]})")
node.evaluate("await this.scrollTo(0, #{height[location]})")
end

def scroll_to_coords(x, y)
Expand Down
27 changes: 27 additions & 0 deletions spec/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1201,5 +1201,32 @@
@driver.evaluate_script("[window.scrollX, window.scrollY]")
).to eq([200, 500])
end

context "when Ferrum raises on deprecations" do
around do |example|
previous = ENV.fetch("FERRUM_DEPRECATION_WARNINGS", nil)
ENV["FERRUM_DEPRECATION_WARNINGS"] = "raise"
example.run
ensure
ENV["FERRUM_DEPRECATION_WARNINGS"] = previous
end

it "scrolls an element to the bottom of the window" do
@session.visit("/cuprite/scroll_long_page")
element = @session.find(:css, "#middleish")
@session.scroll_to(element, align: :bottom)

bottom = element.evaluate_script("this.getBoundingClientRect().bottom")
expect(bottom).to be_within(1).of(@driver.evaluate_script("window.innerHeight"))
end

it "scrolls the window to the bottom" do
@session.visit("/cuprite/scroll_long_page")
@session.scroll_to(:bottom)

max_scroll = @driver.evaluate_script("document.documentElement.scrollHeight - window.innerHeight")
expect(@driver.evaluate_script("window.scrollY")).to be_within(0.5).of(max_scroll)
end
end
end
end
Loading