mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Correct document scroll element
Previously was using "body" tag but that only works in quirks mode. This uses the "html" tag which is what works in standards mode. Updated the expectations to also not use the body tag but instead use `documentElement` which is the suggested accessor in JS to use as it will return the right element depending on the mode. This ensures the measurement is done correctly in standards mode also. ---- The previous commit indicated some failures with the frame specs also. I ran the entire test suite twice and both times saw those frame failures. But now when running just those frame tests I get no failures. Futhermore when I run the entire test suite with these scroll fixes in place I get no failures either. For now will wait to see what CI says but I think it might have been some random failure or state leftover from another test.
This commit is contained in:
parent
f20c8de93c
commit
b2e2a27777
2 changed files with 5 additions and 5 deletions
|
@ -41,7 +41,7 @@ module Capybara
|
|||
end
|
||||
|
||||
def scroll_to(*args, **options)
|
||||
find(:xpath, '//body').scroll_to(*args, **options)
|
||||
find(:xpath, '/html').scroll_to(*args, **options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|||
el = @session.find(:css, '#scroll')
|
||||
@session.scroll_to(el, align: :bottom)
|
||||
el_bottom = el.evaluate_script('this.getBoundingClientRect().bottom')
|
||||
viewport_bottom = el.evaluate_script('document.body.clientHeight')
|
||||
viewport_bottom = el.evaluate_script('document.documentElement.clientHeight')
|
||||
expect(el_bottom).to be_within(1).of(viewport_bottom)
|
||||
end
|
||||
|
||||
|
@ -23,7 +23,7 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|||
el = @session.find(:css, '#scroll')
|
||||
@session.scroll_to(el, align: :center)
|
||||
el_center = el.evaluate_script('(function(rect){return (rect.top + rect.bottom)/2})(this.getBoundingClientRect())')
|
||||
viewport_bottom = el.evaluate_script('document.body.clientHeight')
|
||||
viewport_bottom = el.evaluate_script('document.documentElement.clientHeight')
|
||||
expect(el_center).to be_within(2).of(viewport_bottom / 2)
|
||||
end
|
||||
|
||||
|
@ -35,13 +35,13 @@ Capybara::SpecHelper.spec '#scroll_to', requires: [:scroll] do
|
|||
|
||||
it 'can scroll the window to the vertical bottom' do
|
||||
@session.scroll_to :bottom
|
||||
max_scroll = @session.evaluate_script('document.body.scrollHeight - document.body.clientHeight')
|
||||
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.documentElement.clientHeight')
|
||||
expect(@session.evaluate_script('[window.scrollX || window.pageXOffset, window.scrollY || window.pageYOffset]')).to eq [0, max_scroll]
|
||||
end
|
||||
|
||||
it 'can scroll the window to the vertical center' do
|
||||
@session.scroll_to :center
|
||||
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.body.clientHeight')
|
||||
max_scroll = @session.evaluate_script('document.documentElement.scrollHeight - document.documentElement.clientHeight')
|
||||
expect(@session.evaluate_script('[window.scrollX || window.pageXOffset, window.scrollY || window.pageYOffset]')).to eq [0, max_scroll / 2]
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue