Replace webdriver with cuprite (#18476)

* Replace webdriver with cuprite

* Fix broken spec

* Fix broken spec

* Fix broken spec

* Fix broken spec
This commit is contained in:
Mac Siri 2022-09-22 08:23:42 -04:00 committed by GitHub
parent bebd1d459c
commit 41987116c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 39 additions and 41 deletions

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 <span> 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")

View file

@ -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

Binary file not shown.

BIN
vendor/cache/cliver-0.3.2.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/cuprite-0.13.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/ferrum-0.11.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.