From df4504979e29b44e681b2c6a672fcd15603914e6 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 13:02:36 -0800 Subject: Refactor "I scroll" web step to avoid using execute_script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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". --- features/desktop/change_settings.feature | 4 ++-- features/step_definitions/custom_web_steps.rb | 4 ---- features/step_definitions/web_steps.rb | 5 +++++ 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'features') diff --git a/features/desktop/change_settings.feature b/features/desktop/change_settings.feature index 4655b2a9d..02b199ccf 100644 --- a/features/desktop/change_settings.feature +++ b/features/desktop/change_settings.feature @@ -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 diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index ac5302e6f..040106fae 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -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 diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 4067ad5f4..952bcbee0 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -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 -- cgit v1.2.3 From 245bc1a05fb281ee046785a2e6ea763ac2693536 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 13:09:31 -0800 Subject: Remove unused custom web step It looks like this web step is no longer used anywhere. It was implemented for the "Feature: inifinite scroll" test, but that no longer exists. --- features/step_definitions/custom_web_steps.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'features') diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 040106fae..465d3dd48 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -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 -And /^I scroll down$/ do - page.execute_script("window.scrollBy(0,3000000)") -end - Then /^I should have scrolled down$/ do expect(page.evaluate_script("window.pageYOffset")).to be > 0 end -- cgit v1.2.3 From 688245c0de784efbb60c61f83a037728a06c5f03 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 13:27:48 -0800 Subject: Remove unnecessary `execute_script` call in feature spec This call to `execute_script` would directly call jQuery's `sortable` function on an element to make it sortable. However, this isn't necessary; the test can still drag the "Cat People" aspect to the desired position without it. --- features/step_definitions/aspects_steps.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'features') diff --git a/features/step_definitions/aspects_steps.rb b/features/step_definitions/aspects_steps.rb index 4a5c9e577..5be963ddb 100644 --- a/features/step_definitions/aspects_steps.rb +++ b/features/step_definitions/aspects_steps.rb @@ -119,8 +119,6 @@ When /^(.*) in the aspect creation modal$/ do |action| end When /^I drag "([^"]*)" (up|down)$/ do |aspect_name, direction| - expect(page).to have_js_defined("$('body').sortable") - page.execute_script("$('#aspect_nav .list-group').sortable('option', 'tolerance', 'pointer');") aspect_id = @me.aspects.where(name: aspect_name).first.id aspect = find(:xpath, "//div[@id='aspect_nav']/ul/a[@data-aspect-id='#{aspect_id}']") target = direction == "up" ? aspect.all(:xpath, "./preceding-sibling::a").last : -- cgit v1.2.3 From ef7a5f8d6ecd861bac4f58fee9e00edb6c903541 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 13:50:06 -0800 Subject: Replace "execute_script" for triggering hovercards In addition to getting rid of an "execute_script" instance, this approach is slightly higher fidelity, as it renders the hovercard at the correct place on the page and doesn't reach into jQuery to trigger the hovercard. --- features/step_definitions/hovercard_steps.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'features') diff --git a/features/step_definitions/hovercard_steps.rb b/features/step_definitions/hovercard_steps.rb index 832dcc307..3235d43e8 100644 --- a/features/step_definitions/hovercard_steps.rb +++ b/features/step_definitions/hovercard_steps.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true When(/^I activate the first hovercard$/) do - page.execute_script("$('.hovercardable').first().trigger('mouseenter');") + first(".hovercardable").hover end Then(/^I should see a hovercard$/) do @@ -14,7 +14,7 @@ Then(/^I should see "([^"]*)" hashtag in the hovercard$/) do |tag| end When(/^I deactivate the first hovercard$/) do - page.execute_script("$('.hovercardable').first().trigger('mouseleave');") + find("input#q").click # Click something else instead — e.g., search — to deactive it end Then(/^I should not see a hovercard$/) do -- cgit v1.2.3 From b67cf8e983ae6a98cee32473c3fe81e71114516f Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 14:00:31 -0800 Subject: Replace "execute_script" for filling in Close Account modal Using "fill_in" seems to work fine with the apparition driver, and will hopefully also work on CI now. --- features/step_definitions/modal_steps.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'features') diff --git a/features/step_definitions/modal_steps.rb b/features/step_definitions/modal_steps.rb index ceea1f667..a166a5ec9 100644 --- a/features/step_definitions/modal_steps.rb +++ b/features/step_definitions/modal_steps.rb @@ -9,9 +9,7 @@ Then /^I should see the mention modal$/ do end When /^I put in my password in the close account modal$/ do - # Capybara helpers fill_in, set and send_keys currently don't work - # inside of Bootstrap modals on Travis CI - execute_script("$(\"#closeAccountModal input#close_account_password\").val(\"#{@me.password}\")") + fill_in("#close_account_password", with: @me.password) expect(find("#closeAccountModal input#close_account_password").value).to eq(@me.password) end -- cgit v1.2.3 From 454838008047a85185d61301e8c8fd6db0604a14 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 14:09:19 -0800 Subject: Replace "execute_script" in spec scrolling down on notifications --- features/step_definitions/notifications_steps.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'features') diff --git a/features/step_definitions/notifications_steps.rb b/features/step_definitions/notifications_steps.rb index 9088dacc2..9c521a908 100644 --- a/features/step_definitions/notifications_steps.rb +++ b/features/step_definitions/notifications_steps.rb @@ -24,7 +24,7 @@ And "I wait for notifications to load" do end And "I scroll down on the notifications dropdown" do - page.execute_script("$('.notifications').scrollTop(350)") + find(".notifications").scroll_to(0, 350) end Then "the notification dropdown should be visible" do -- cgit v1.2.3 From 637dad208a0dd53bc8b4c8d46c6e5c705d670583 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 14:39:33 -0800 Subject: Replace "execute_script" in publisher_steps definitions --- features/step_definitions/publisher_steps.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'features') diff --git a/features/step_definitions/publisher_steps.rb b/features/step_definitions/publisher_steps.rb index 5afa5f5fe..56c7917a5 100644 --- a/features/step_definitions/publisher_steps.rb +++ b/features/step_definitions/publisher_steps.rb @@ -13,9 +13,11 @@ Then /^the publisher should be expanded$/ do end When /^I click to delete the first uploaded photo$/ do - page.execute_script("$('#photodropzone .x').css('display', 'block');") image_count = all(".publisher_photo img", wait: false).count - find("#photodropzone .x", match: :first).trigger "click" + within "ul#photodropzone" do + first("img").hover + find(".x", match: :first).trigger "click" + end page.assert_selector(".publisher_photo img", count: image_count - 1) end @@ -68,12 +70,6 @@ When /^I post an extremely long status message$/ do end When /^I select "([^"]*)" on the aspect dropdown$/ do |text| - page.execute_script( - "$('#publisher .dropdown .dropdown_list, #publisher .aspect-dropdown .dropdown-menu') - .find('li').each(function(i,el){ - var elem = $(el); - if ('" + text + "' == $.trim(elem.text()) ) { - elem.click(); - }});" - ) + find("button.dropdown-toggle").click + find(".dropdown-menu li", text: text).click end -- cgit v1.2.3 From d14036b63093c60fa32d11b3597cc75404b1c584 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 14:55:24 -0800 Subject: Replace "evaluate_script" for toggling a Bootstrap switch in spec --- features/step_definitions/web_steps.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'features') diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 952bcbee0..2c2ca4400 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -170,8 +170,8 @@ Then /^the "([^"]*)" bootstrap-switch should be (on|off)$/ do |label, state| end end -Then /^I toggle the "([^"]*)" bootstrap-switch$/ do |label| - page.execute_script("return $('#{label}').bootstrapSwitch('toggleState')") +Then /^I toggle the "#([^"]*)" bootstrap-switch$/ do |id| + find(".bootstrap-switch-id-#{id}").click end Then /^(?:|I )should be on (.+)$/ do |page_name| -- cgit v1.2.3 From 4588ce11c93ca955934d32179a918850a4412e3a Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 15:10:36 -0800 Subject: Replace "execute_script" for uploading images in specs --- features/support/publishing_cuke_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'features') diff --git a/features/support/publishing_cuke_helpers.rb b/features/support/publishing_cuke_helpers.rb index 57997ccc4..73dc02e27 100644 --- a/features/support/publishing_cuke_helpers.rb +++ b/features/support/publishing_cuke_helpers.rb @@ -27,9 +27,9 @@ module PublishingCukeHelpers end def upload_file_with_publisher(path) - page.execute_script(%q{$("input[name='qqfile']").css("opacity", '1');}) with_scope("#publisher-textarea-wrapper") do - attach_file("qqfile", Rails.root.join(path).to_s) + find('input[name="qqfile"]', visible: false) + .attach_file(Rails.root.join(path).to_s, make_visible: true) # wait for the image to be ready page.assert_selector(".publisher_photo.loading", count: 0) end -- cgit v1.2.3 From 4fe52a72f15c20691f52e3aa1d6ea7f953a3d0e5 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 30 Dec 2021 18:22:07 -0800 Subject: Fix comment style violation --- features/step_definitions/hovercard_steps.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'features') diff --git a/features/step_definitions/hovercard_steps.rb b/features/step_definitions/hovercard_steps.rb index 3235d43e8..2fa367b3f 100644 --- a/features/step_definitions/hovercard_steps.rb +++ b/features/step_definitions/hovercard_steps.rb @@ -14,7 +14,7 @@ Then(/^I should see "([^"]*)" hashtag in the hovercard$/) do |tag| end When(/^I deactivate the first hovercard$/) do - find("input#q").click # Click something else instead — e.g., search — to deactive it + find("input#q").click # Click something else instead to deactive it end Then(/^I should not see a hovercard$/) do -- cgit v1.2.3 From ae5333d67dc32e388393fb6e6382336c7ea8a53c Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Thu, 6 Jan 2022 06:06:27 -0800 Subject: Revert "Replace "execute_script" for triggering hovercards" This reverts commit e7dc4eca9ecdb025c01b02890e8e075ebc1af9cc. --- features/step_definitions/hovercard_steps.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'features') diff --git a/features/step_definitions/hovercard_steps.rb b/features/step_definitions/hovercard_steps.rb index 2fa367b3f..832dcc307 100644 --- a/features/step_definitions/hovercard_steps.rb +++ b/features/step_definitions/hovercard_steps.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true When(/^I activate the first hovercard$/) do - first(".hovercardable").hover + page.execute_script("$('.hovercardable').first().trigger('mouseenter');") end Then(/^I should see a hovercard$/) do @@ -14,7 +14,7 @@ Then(/^I should see "([^"]*)" hashtag in the hovercard$/) do |tag| end When(/^I deactivate the first hovercard$/) do - find("input#q").click # Click something else instead to deactive it + page.execute_script("$('.hovercardable').first().trigger('mouseleave');") end Then(/^I should not see a hovercard$/) do -- cgit v1.2.3 From 107f118db422af09058ecda3217ae936f7dd2a36 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Sat, 15 Jan 2022 20:13:56 -0800 Subject: Undo change to aspects_steps.rb that breaks the build When I removed this and tested it locally, the feature spec still passed, but it is failing on CI, so it looks like we still need this `execute_script` use until we find a better Capybara strategy. --- features/step_definitions/aspects_steps.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'features') diff --git a/features/step_definitions/aspects_steps.rb b/features/step_definitions/aspects_steps.rb index 5be963ddb..4a5c9e577 100644 --- a/features/step_definitions/aspects_steps.rb +++ b/features/step_definitions/aspects_steps.rb @@ -119,6 +119,8 @@ When /^(.*) in the aspect creation modal$/ do |action| end When /^I drag "([^"]*)" (up|down)$/ do |aspect_name, direction| + expect(page).to have_js_defined("$('body').sortable") + page.execute_script("$('#aspect_nav .list-group').sortable('option', 'tolerance', 'pointer');") aspect_id = @me.aspects.where(name: aspect_name).first.id aspect = find(:xpath, "//div[@id='aspect_nav']/ul/a[@data-aspect-id='#{aspect_id}']") target = direction == "up" ? aspect.all(:xpath, "./preceding-sibling::a").last : -- cgit v1.2.3 From 6fadfb30fed1461d1c66b1a692d594c3ba08abe4 Mon Sep 17 00:00:00 2001 From: Sage Ross Date: Sat, 15 Jan 2022 20:39:10 -0800 Subject: Undo another Capybara refactor that causes CI to break Alas. Closed #8331 --- features/step_definitions/modal_steps.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'features') diff --git a/features/step_definitions/modal_steps.rb b/features/step_definitions/modal_steps.rb index a166a5ec9..ceea1f667 100644 --- a/features/step_definitions/modal_steps.rb +++ b/features/step_definitions/modal_steps.rb @@ -9,7 +9,9 @@ Then /^I should see the mention modal$/ do end When /^I put in my password in the close account modal$/ do - fill_in("#close_account_password", with: @me.password) + # Capybara helpers fill_in, set and send_keys currently don't work + # inside of Bootstrap modals on Travis CI + execute_script("$(\"#closeAccountModal input#close_account_password\").val(\"#{@me.password}\")") expect(find("#closeAccountModal input#close_account_password").value).to eq(@me.password) end -- cgit v1.2.3