diff --git a/Gemfile b/Gemfile index 3c3dfaf31..109d94597 100644 --- a/Gemfile +++ b/Gemfile @@ -154,6 +154,7 @@ group :development, :test do end group :test do + gem "cuprite", "~> 0.13" # Capybara driver for Chrome gem "exifr", ">= 1.3.6" # EXIF Reader is a module to read EXIF from JPEG and TIFF images gem "factory_bot_rails", "~> 6.2" # factory_bot is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies gem "fakeredis", "~> 0.8.0" # Fake (In-memory) driver for redis-rb. Useful for testing environment and machines without Redis. @@ -168,7 +169,6 @@ group :test do gem "test-prof", "~> 1.0" # Ruby Tests Profiling Toolbox gem "timecop", "~> 0.9" # A gem providing "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code gem "vcr", "~> 6.1" # Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests - gem "webdrivers", "~> 5.0" # Run Selenium tests more easily with install and updates for all supported webdrivers gem "webmock", "~> 3.17", require: false # WebMock allows stubbing HTTP requests and setting expectations on HTTP requests gem "with_model", "~> 2.1.6" # Dynamically build a model within an RSpec context gem "zonebie", "~> 0.6.1" # Runs your tests in a random timezone diff --git a/Gemfile.lock b/Gemfile.lock index 620d7b579..d6db77813 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -158,7 +158,7 @@ GEM carrierwave fastimage chartkick (4.2.1) - childprocess (4.1.0) + cliver (0.3.2) cloudinary (1.23.0) aws_cf_signer rest-client (>= 2.0.0) @@ -178,6 +178,9 @@ GEM crack (0.4.5) rexml crass (1.0.6) + cuprite (0.13) + capybara (>= 2.1, < 4) + ferrum (~> 0.11.0) cypress-rails (0.5.4) puma (>= 3.8.0) railties (>= 5.2.0) @@ -279,6 +282,11 @@ GEM feedjira (3.2.1) loofah (>= 2.3.1) sax-machine (>= 1.0) + ferrum (0.11) + addressable (~> 2.5) + cliver (~> 0.3) + concurrent-ruby (~> 1.1) + websocket-driver (>= 0.6, < 0.8) ffi (1.15.5) ffi-compiler (1.0.1) ffi (>= 1.0.0) @@ -796,11 +804,6 @@ GEM addressable (>= 2.3.5) faraday (>= 0.17.3, < 3) sax-machine (1.3.2) - selenium-webdriver (4.4.0) - childprocess (>= 0.5, < 5.0) - rexml (~> 3.2, >= 3.2.5) - rubyzip (>= 1.2.2, < 3.0) - websocket (~> 1.0) semantic_range (3.0.0) sexp_processor (4.16.1) shellany (0.0.1) @@ -909,10 +912,6 @@ GEM activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webdrivers (5.0.0) - nokogiri (~> 1.6) - rubyzip (>= 1.3.0) - selenium-webdriver (~> 4.0) webmock (3.18.1) addressable (>= 2.8.0) crack (>= 0.3.2) @@ -926,7 +925,6 @@ GEM hkdf (~> 0.2) jwt (~> 2.0) webrick (1.7.0) - websocket (1.2.9) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -971,6 +969,7 @@ DEPENDENCIES carrierwave-bombshelter (~> 0.2) cloudinary (~> 1.23) counter_culture (~> 3.2) + cuprite (~> 0.13) cypress-rails (~> 0.5) ddtrace (~> 1.3.0) debug (>= 1.0.0) @@ -1098,7 +1097,6 @@ DEPENDENCIES warning (~> 1.3) wcag_color_contrast (~> 0.1) web-console (~> 4.2) - webdrivers (~> 5.0) webmock (~> 3.17) webpacker (~> 5.4.3) with_model (~> 2.1.6) diff --git a/spec/support/initializers/capybara.rb b/spec/support/initializers/capybara.rb index 09ec2b3af..a2806319c 100644 --- a/spec/support/initializers/capybara.rb +++ b/spec/support/initializers/capybara.rb @@ -1,10 +1,25 @@ require "capybara/rails" require "capybara/rspec" -require "webdrivers/chromedriver" +require "capybara/cuprite" -Webdrivers.cache_time = 86_400 - -Capybara.default_max_wait_time = 10 +Capybara.default_max_wait_time = 2 +Capybara.register_driver(:better_cuprite) do |app| + Capybara::Cuprite::Driver.new( + app, + **{ + window_size: [1200, 800], + # See additional options for Dockerized environment in the respective section of this article + browser_options: {}, + # Increase Chrome startup wait time (required for stable CI builds) + process_timeout: 10, + # Enable debugging capabilities + inspector: true, + # Allow running Chrome in a headful mode by setting HEADLESS env + # var to a falsey value + headless: !ENV["HEADLESS"].in?(%w[n 0 no false]) + }, + ) +end RSpec.configure do |config| config.before(:each, type: :system) do @@ -12,18 +27,7 @@ RSpec.configure do |config| end config.before(:each, type: :system, js: true) do - if ENV["SELENIUM_URL"].present? - # Support use of remote chrome testing. - Capybara.server_host = ENV.fetch("CAPYBARA_SERVER_HOST") { "0.0.0.0" } - ip = Socket.ip_address_list.detect(&:ipv4_private?).ip_address - host! URI::HTTP.build(host: ip, port: Capybara.server_port).to_s - - driven_by :selenium, using: :chrome, screen_size: [1400, 2000], options: { url: ENV["SELENIUM_URL"] } - else - # options from https://github.com/teamcapybara/capybara#selenium - chrome = ENV["HEADLESS"] == "false" ? :selenium_chrome : :selenium_chrome_headless - driven_by chrome - end + driven_by :better_cuprite end end diff --git a/spec/system/articles/user_visits_articles_by_tag_spec.rb b/spec/system/articles/user_visits_articles_by_tag_spec.rb index e7401856e..a21c5bdaa 100644 --- a/spec/system/articles/user_visits_articles_by_tag_spec.rb +++ b/spec/system/articles/user_visits_articles_by_tag_spec.rb @@ -21,7 +21,7 @@ RSpec.describe "User visits articles by tag", type: :system do end it "shows the header", js: true do - within("h1") { expect(page).to have_text("javascript") } + within("h1.crayons-title") { expect(page).to have_text("javascript") } end it "shows the follow button", js: true do diff --git a/spec/system/authentication/user_logs_in_with_email_spec.rb b/spec/system/authentication/user_logs_in_with_email_spec.rb index 7def11bc9..d4d2cac1f 100644 --- a/spec/system/authentication/user_logs_in_with_email_spec.rb +++ b/spec/system/authentication/user_logs_in_with_email_spec.rb @@ -138,7 +138,7 @@ RSpec.describe "Authenticating with Email" do end def fill_in_user(user) - attach_file("user_profile_image", "spec/fixtures/files/podcast.png") + attach_file(File.expand_path("./spec/fixtures/files/podcast.png")) fill_in("user_name", with: user.name) fill_in("user_username", with: user.username) fill_in("user_email", with: user.email) diff --git a/spec/system/organization/user_updates_org_settings_spec.rb b/spec/system/organization/user_updates_org_settings_spec.rb index 76cdf7f52..c940ed8fc 100644 --- a/spec/system/organization/user_updates_org_settings_spec.rb +++ b/spec/system/organization/user_updates_org_settings_spec.rb @@ -46,7 +46,6 @@ RSpec.describe "Organization setting page(/settings/organization)", type: :syste visit "settings/organization" click_button("Make admin") - page.driver.browser.switch_to.alert.accept expect(page).to have_text("#{user2.name} is now an admin.") end @@ -57,7 +56,6 @@ RSpec.describe "Organization setting page(/settings/organization)", type: :syste visit "settings/organization" click_button("Revoke admin status") - page.driver.browser.switch_to.alert.accept expect(page).to have_text("#{user2.name} is no longer an admin.") end @@ -67,7 +65,6 @@ RSpec.describe "Organization setting page(/settings/organization)", type: :syste visit "settings/organization" click_button("Remove from org") - page.driver.browser.switch_to.alert.accept expect(page).to have_text("#{user2.name} is no longer part of your organization.") end diff --git a/spec/system/podcasts/user_visits_podcast_episode_spec.rb b/spec/system/podcasts/user_visits_podcast_episode_spec.rb index 17d29b12d..d60521f51 100644 --- a/spec/system/podcasts/user_visits_podcast_episode_spec.rb +++ b/spec/system/podcasts/user_visits_podcast_episode_spec.rb @@ -8,9 +8,9 @@ RSpec.describe "User visits podcast show page", type: :system, js: true do it "doesn't detect native capabilities from a non-mobile web browser" do visit podcast_episode.path.to_s - result = execute_script("return window.Forem.Runtime.isNativeIOS('podcast')") + result = evaluate_script("window.Forem.Runtime.isNativeIOS('podcast')") expect(result).to be false - result = execute_script("return window.Forem.Runtime.isNativeAndroid('podcast')") + result = evaluate_script("window.Forem.Runtime.isNativeAndroid('podcast')") expect(result).to be false end diff --git a/spec/system/user/view_user_index_spec.rb b/spec/system/user/view_user_index_spec.rb index 4833d85c1..4562e3918 100644 --- a/spec/system/user/view_user_index_spec.rb +++ b/spec/system/user/view_user_index_spec.rb @@ -78,7 +78,6 @@ RSpec.describe "User index", type: :system do end it "shows organizations", js: true do - Capybara.current_session.driver.browser.manage.window.resize_to(1920, 1080) expect(page).to have_css(".spec-org-titles", text: "Organizations") end end diff --git a/spec/system/user_uses_the_editor_spec.rb b/spec/system/user_uses_the_editor_spec.rb index ab7c5a671..116f93f27 100644 --- a/spec/system/user_uses_the_editor_spec.rb +++ b/spec/system/user_uses_the_editor_spec.rb @@ -100,10 +100,10 @@ RSpec.describe "Using the editor", type: :system do visit "/new" within "form#article-form" do fill_in "article-form-title", with: "This is a test" - fill_in "tag-input", with: "What, Yo" + find("#tag-input").native.send_keys("what", :return) fill_in "article_body_markdown", with: "Hello" end - find("button", text: /\APublish\z/).click + click_button "Publish" expect(page).to have_xpath("//div[@class='crayons-article__header__meta']//h1") expect(page).to have_text("Hello") expect(page).to have_link("what", href: "/t/what") diff --git a/spec/system/user_visits_a_comments_page_spec.rb b/spec/system/user_visits_a_comments_page_spec.rb index 6688e9952..6263e58e0 100644 --- a/spec/system/user_visits_a_comments_page_spec.rb +++ b/spec/system/user_visits_a_comments_page_spec.rb @@ -22,14 +22,14 @@ RSpec.describe "Views an article", type: :system, js: true do create(:comment, user: co_author, commentable: article) visit "#{article.path}/comments" - expect(page).to have_selector(".spec-op-author", visible: :visible, text: "Author", count: 2) + expect(page).to have_selector(".spec-op-author[data-tooltip='Author']", visible: :visible, count: 2) end it "shows special op marker on ama articles" do create(:comment, user: user, commentable: ama_article) visit "#{ama_article.path}/comments" - expect(page).to have_selector(".spec-op-author", visible: :visible, text: "Ask Me Anything") + expect(page).to have_selector(".spec-op-author[data-tooltip='Ask Me Anything']", visible: :visible) end it "shows a thread" do diff --git a/vendor/cache/childprocess-4.1.0.gem b/vendor/cache/childprocess-4.1.0.gem deleted file mode 100644 index 73cbd239a..000000000 Binary files a/vendor/cache/childprocess-4.1.0.gem and /dev/null differ diff --git a/vendor/cache/cliver-0.3.2.gem b/vendor/cache/cliver-0.3.2.gem new file mode 100644 index 000000000..3635c7e0d Binary files /dev/null and b/vendor/cache/cliver-0.3.2.gem differ diff --git a/vendor/cache/cuprite-0.13.gem b/vendor/cache/cuprite-0.13.gem new file mode 100644 index 000000000..5cf0bfbba Binary files /dev/null and b/vendor/cache/cuprite-0.13.gem differ diff --git a/vendor/cache/ferrum-0.11.gem b/vendor/cache/ferrum-0.11.gem new file mode 100644 index 000000000..5b757a2e9 Binary files /dev/null and b/vendor/cache/ferrum-0.11.gem differ diff --git a/vendor/cache/selenium-webdriver-4.4.0.gem b/vendor/cache/selenium-webdriver-4.4.0.gem deleted file mode 100644 index 4881b6212..000000000 Binary files a/vendor/cache/selenium-webdriver-4.4.0.gem and /dev/null differ diff --git a/vendor/cache/webdrivers-5.0.0.gem b/vendor/cache/webdrivers-5.0.0.gem deleted file mode 100644 index f6d14aaa6..000000000 Binary files a/vendor/cache/webdrivers-5.0.0.gem and /dev/null differ diff --git a/vendor/cache/websocket-1.2.9.gem b/vendor/cache/websocket-1.2.9.gem deleted file mode 100644 index 2578fac82..000000000 Binary files a/vendor/cache/websocket-1.2.9.gem and /dev/null differ