Refactor "I scroll" web step to avoid using execute_script

The apparition driver does not support "scroll_by" without going through "execute_script", but we can better express the intention of this test and make the scrolling action a bit more general by replacing "scroll a bit" with "scroll to [some element]" — in this case, we need to scroll until the "Change" button is visible so that we can press it.

This change_settings.feature spec is the only place that used "I scroll a bit".
This commit is contained in:
Sage Ross 2021-12-30 13:02:36 -08:00 committed by Benjamin Neff
parent e5b65f6498
commit df4504979e
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
3 changed files with 7 additions and 6 deletions

View file

@ -19,12 +19,12 @@ Feature: Change settings
Scenario: Change my email preferences
When I uncheck "user_email_preferences_mentioned"
And I scroll a bit
And I scroll to "change_email_preferences"
And I press "change_email_preferences"
Then I should see "Email notifications changed"
And the "user_email_preferences_mentioned" checkbox should not be checked
When I uncheck "user_email_preferences_mentioned_in_comment"
And I scroll a bit
And I scroll to "change_email_preferences"
And I press "change_email_preferences"
Then I should see "Email notifications changed"
And the "user_email_preferences_mentioned_in_comment" checkbox should not be checked

View file

@ -167,10 +167,6 @@ Then /^I should see (\d+) contacts$/ do |n_posts|
has_css?("#people-stream .stream-element", count: n_posts.to_i).should be true
end
When /^I scroll a bit$/ do
page.execute_script("window.scrollBy(0,200)")
end
And /^I scroll down$/ do
page.execute_script("window.scrollBy(0,3000000)")
end

View file

@ -195,3 +195,8 @@ Then /^I wait until ajax requests finished$/ do
loop until page.evaluate_script("jQuery.active") == 0
end
end
When /^I scroll to "([^"]*)"$/ do |element_id|
element = find_by_id(element_id) # rubocop:disable Rails/DynamicFindBy
page.scroll_to(element, align: :bottom)
end