diff --git a/features/step_definitions/cms/page_template_steps.rb b/features/step_definitions/cms/page_template_steps.rb index c361db56ad..c93bdd940e 100644 --- a/features/step_definitions/cms/page_template_steps.rb +++ b/features/step_definitions/cms/page_template_steps.rb @@ -9,7 +9,7 @@ end def fill_draft(text) - raise 'Please mark this scenario with @javascript if you want to work with codemirror.' unless @javascript + ensure_javascript find('#cms_template_draft', visible: :all) execute_script("$('#cms_template_draft').data('codemirror').setValue(#{text.inspect});") diff --git a/features/step_definitions/pagination_steps.rb b/features/step_definitions/pagination_steps.rb index fa2e163bd2..f5f7a9cf75 100644 --- a/features/step_definitions/pagination_steps.rb +++ b/features/step_definitions/pagination_steps.rb @@ -22,7 +22,8 @@ click_link page end else - input = find('input[aria-label="Current page"]') + # Pagination controls are rendered twice: at the top and at the bottom of the data table + input = find('input[aria-label="Current page"]', match: :first) input.set(page) input.native.send_keys(:return) end diff --git a/features/step_definitions/provider_steps.rb b/features/step_definitions/provider_steps.rb index 212b29fae3..a410100081 100644 --- a/features/step_definitions/provider_steps.rb +++ b/features/step_definitions/provider_steps.rb @@ -3,7 +3,7 @@ def import_simple_layout(provider) simple_layout = SimpleLayout.new(provider) simple_layout.import_pages! - simple_layout.import_js_and_css! if @javascript + simple_layout.import_js_and_css! if javascript_test? end Given "a provider signed up to {plan}" do |plan| diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 5aa38cc956..723aa016c9 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -143,14 +143,11 @@ def with_scope(locator) Then /^(.+) and confirm the dialog(?: "(.*)")?$/ do |original, text| ActiveSupport::Deprecation.warn "🥒 Replace with step 'And confirm the dialog'" - if rack_test? + ensure_javascript + accept_confirm(text) do step original - else - accept_confirm(text) do - step original - end - wait_for_requests end + wait_for_requests end Then "(they )should see the following details(:)" do |table| diff --git a/features/support/0001_world.rb b/features/support/0001_world.rb index e0d7c2e540..1cb0b6f855 100644 --- a/features/support/0001_world.rb +++ b/features/support/0001_world.rb @@ -4,7 +4,6 @@ World(PlanHelpers) World(DummyAttachments) -World(JsHelpers) World(MessagesHelpers) World(BackendHelpers) World(SiteAccount) diff --git a/features/support/capybara.rb b/features/support/capybara.rb index 69592a80a2..ca5025986a 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -1,117 +1,59 @@ # frozen_string_literal: true require 'selenium/webdriver' -require 'capybara/minitest' -include Capybara::Minitest::Assertions -# in case firefox is needed! -#Capybara.register_driver :selenium do |app| -# Capybara::Selenium::Driver.new(app, :browser => :firefox) -#end +# When width < 1200px, vertical navigation overlaps the page's main content, +# and that will make some cucumbers fail +WINDOW_SIZE_ARG = '--window-size=1280,2048' -DEFAULT_JS_DRIVER = :headless_chrome -# in case firefox is needed! -# DEFAULT_JS_DRIVER = :headless_firefox - -Capybara.default_driver = :rack_test -Capybara.javascript_driver = DEFAULT_JS_DRIVER -Capybara.default_selector = :css -Capybara.disable_animation = true - -# Capybara 3 changes the default server to Puma. It can be reverted to the previous default of WEBRick by specifying: -Capybara.server = :webrick - -# see http://www.elabs.se/blog/60-introducing-capybara-2-1 Capybara.configure do |config| - config.default_driver = :rack_test - config.javascript_driver = DEFAULT_JS_DRIVER - config.raise_server_errors = true config.match = :prefer_exact + config.javascript_driver = :headless_chrome config.always_include_port = true config.default_max_wait_time = 10 -end - -# Needed because cucumber-rails requires capybara/cucumber -# https://github.com/cucumber/cucumber-rails/blob/7b47bf1dda3368247bf2d45bcb17a224e80ec6fd/lib/cucumber/rails/capybara.rb#L3 -# https://github.com/teamcapybara/capybara/blob/2.18.0/lib/capybara/cucumber.rb#L17-L19 -Before '@javascript' do - Capybara.current_driver = DEFAULT_JS_DRIVER -end - -Before '@chrome' do - Capybara.current_driver = :chrome -end - -Before '@firefox' do - Capybara.current_driver = :firefox -end - -Around '@security' do |scenario, block| - with_forgery_protection(&block) -end - -# monkeypatch to fix -# not opened for reading (IOError) -# /cucumber-1.3.20/lib/cucumber/formatter/interceptor.rb:33:in `each' -# /cucumber-1.3.20/lib/cucumber/formatter/interceptor.rb:33:in `collect' -# /cucumber-1.3.20/lib/cucumber/formatter/interceptor.rb:33:in `method_missing' -require 'cucumber/formatter/interceptor' -class Cucumber::Formatter::Interceptor::Pipe - def is_a?(klass) - super || klass == IO - end -end - -Capybara.register_driver :firefox do |app| - Capybara::Selenium::Driver.new(app, browser: :firefox) -end - -Capybara.register_driver :headless_firefox do |app| - options = Selenium::WebDriver::Firefox::Options.new - - options.add_argument('-headless') - options.add_argument('--window-size=1280,2048') - - driver = Capybara::Selenium::Driver.new(app, browser: :firefox, options: options) - - driver -end - -Capybara.register_driver :firefox do |app| - options = Selenium::WebDriver::Firefox::Options.new - - options.add_argument('--window-size=1280,2048') - - driver = Capybara::Selenium::Driver.new(app, browser: :firefox, options: options) - - driver + config.server = :webrick # default is `:default` (which uses puma) end Capybara.register_driver :chrome do |app| - options = Selenium::WebDriver::Chrome::Options.new - options.add_argument('--window-size=1280,2048') + options = Selenium::WebDriver::Options.chrome + options.add_argument(WINDOW_SIZE_ARG) options.add_argument('--disable-search-engine-choice-screen') Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end Capybara.register_driver :headless_chrome do |app| - options = Selenium::WebDriver::Options.chrome( - logging_prefs: { performance: 'ALL', browser: 'ALL' }, - perf_logging_prefs: { enableNetwork: true } - ) - + options = Selenium::WebDriver::Options.chrome + options.add_argument(WINDOW_SIZE_ARG) + options.add_argument('--disable-search-engine-choice-screen') options.add_argument('--headless=new') options.add_argument('--no-sandbox') options.add_argument('--disable-popup-blocking') - options.add_argument('--window-size=1280,2048') options.add_argument('--host-resolver-rules=MAP * ~NOTFOUND , EXCLUDE *localhost*') - options.add_argument('--disable-search-engine-choice-screen') options.add_argument('--disable-gpu') + options.logging_prefs = { performance: 'ALL', browser: 'ALL' } + options.add_option(:perf_logging_prefs, enableNetwork: true) + options.add_preference(:browser, set_download_behavior: { behavior: 'allow' }) - timeout = 120 # default 60 - client = Selenium::WebDriver::Remote::Http::Default.new(open_timeout: timeout, read_timeout: timeout) + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options, timeout: 120) +end + +# NOTE: depending on the scenario you will need to add both +# @firefox/@headless_firefox AND @javascript tags +Before '@firefox', '@headless_firefox' do + Capybara.javascript_driver = :headless_firefox +end + +Capybara.register_driver :firefox do |app| + options = Selenium::WebDriver::Options.firefox + options.add_argument(WINDOW_SIZE_ARG) + Capybara::Selenium::Driver.new(app, browser: :firefox, options: options) +end - Capybara::Selenium::Driver.new(app, browser: :chrome, options: options, http_client: client) +Capybara.register_driver :headless_firefox do |app| + options = Selenium::WebDriver::Options.firefox + options.add_argument(WINDOW_SIZE_ARG) + options.add_argument('-headless') + Capybara::Selenium::Driver.new(app, browser: :firefox, options: options) end diff --git a/features/support/helpers/capybara_helpers.rb b/features/support/helpers/capybara_helpers.rb index 97a299d543..c9e35f4ab0 100644 --- a/features/support/helpers/capybara_helpers.rb +++ b/features/support/helpers/capybara_helpers.rb @@ -1,14 +1,26 @@ # frozen_string_literal: true +require 'capybara/minitest' + module CapybaraHelpers + include Capybara::Minitest::Assertions + FLASH_SELECTOR = [ '#flash-messages', '#flashWrapper span', '#flashWrapper p' ].join(', ').freeze - def rack_test? - %I[webkit selenium webkit_debug headless_chrome chrome headless_firefox firefox].exclude? Capybara.current_driver + def javascript_test? + Capybara.current_driver == Capybara.javascript_driver + end + + def ensure_javascript + raise 'Please mark this scenario with @javascript.' unless javascript_test? + end + + def local_storage(key) + Capybara.current_session.driver.browser.local_storage.[](key) end def assert_flash(message) diff --git a/features/support/helpers/js_helpers.rb b/features/support/helpers/js_helpers.rb deleted file mode 100644 index 9a588f8b98..0000000000 --- a/features/support/helpers/js_helpers.rb +++ /dev/null @@ -1,16 +0,0 @@ -module JsHelpers - def bypass_confirm_dialog - # bypassing the confirm dialog - # http://groups.google.com/group/ruby-capybara/browse_thread/thread/89760b6fcab7fd19 - # http://stackoverflow.com/questions/2458632/how-to-test-a-confirm-dialog-with-cucumber - page.evaluate_script('window.confirm = function() { return true; }') - end - - def ensure_javascript - raise 'This step requires JS enabled' unless @javascript - end - - def local_storage(key) - Capybara.current_session.driver.browser.local_storage.[](key) - end -end diff --git a/features/support/helpers/requests_helper.rb b/features/support/helpers/requests_helper.rb index 740bb45725..a83d03a208 100644 --- a/features/support/helpers/requests_helper.rb +++ b/features/support/helpers/requests_helper.rb @@ -103,10 +103,6 @@ def finished_all_ajax_requests? Capybara.page.evaluate_script('jQuery.active').zero? end - - def javascript_test? - Capybara.current_driver == Capybara.javascript_driver - end end diff --git a/features/support/hooks.rb b/features/support/hooks.rb index c7a352b72d..f613a1a893 100644 --- a/features/support/hooks.rb +++ b/features/support/hooks.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +Around '@security' do |scenario, block| + with_forgery_protection(&block) +end + Before '@onpremises' do ThreeScale.config.stubs(onpremises: true) ThreeScale.config.stubs(saas?: false) @@ -28,7 +32,6 @@ Before '@javascript' do stub_core_reset! - @javascript = true end AfterStep('@javascript') do