I get several different errors when trying to use selenium with the Gitlab CI, I have to retry several times to get my tests to pass. These are the errors I get:
Selenium::WebDriver::Error::WebDriverError: invalid session id
Errno::ECONNREFUSED: Failed to open TCP connection to 127.0.0.1:9515
I’m using the webdrivers gem to manage my drivers and this is the config I have for my tests:
Webdrivers.cache_time = 86_400
if ENV["CI"]
Webdrivers::Chromedriver.required_version = "74.0.3729.6"
else
Webdrivers::Chromedriver.update
end
Capybara.register_driver :headless_chrome do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("window-size=2560x2560")
options.add_argument("disable-dev-shm-usage") if ENV['CI']
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.javascript_driver = :headless_chrome
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include Devise::Test::IntegrationHelpers
driven_by :headless_chrome, screen_size: [1280, 2400], options: {}
def click_role(role)
find(:css, "[role$='#{role}']").click
end
def shopping_cart_with_items
@ticket_type_vip_front = ticket_types(:vip_front)
@shopping_cart = shopping_carts(:default)
price = Money.new(@ticket_type_vip_front.price_cents, @ticket_type_vip_front.price_cents_currency)
@shopping_cart.add @ticket_type_vip_front, price
end
end