我正在使用Rspec + Capybara和dockerized硒/standalone-chrome:3.4.0的Rails应用程序的Gitlab Runner为CI设置CI。测试在本地通过,但是一旦通过CI系统测试就会失败,并显示错误Selenium :: WebDriver :: Error :: NoSuchDriverError。
我尝试在本地运行测试,但使用相同的dockerized映像selenium / standalone-chrome:3.4.0,并且系统测试失败,并显示错误Selenium :: WebDriver :: Error :: UnknownCommandError。
RSpec.configure do |config|
config.before(:each, type: :system) do
if ENV['SELENIUM_URL'].present?
# Make the test app listen to outside requests, for the remote Selenium instance.
Capybara.server_host = '0.0.0.0'
# Specify the driver
driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: { url: ENV['SELENIUM_URL'] }
# Get the application container's IP
ip = Socket.ip_address_list.detect(&:ipv4_private?).ip_address
# Use the IP instead of localhost so Capybara knows where to direct Selenium
host! "http://#{ip}:#{Capybara.server_port}"
else
# Otherwise, use the local machine's chromedriver
driven_by :selenium, using: :headless_chrome
end
end
end
image: starefossen/ruby-node:latest
cache:
paths:
- node_modules
- vendor/ruby
services:
- postgres:9.4.20
- selenium/standalone-chrome:3.4.0
stages:
- test
- deploy
variables:
RAILS_ENV: test
DB_HOST: postgres
DB_PORT: 5432
SELENIUM_URL: 'http://selenium__standalone-chrome:4444/wd/hub'
1.1) Failure/Error: find('#map-spot-creation').click(x: 150, y: 500)
Selenium::WebDriver::Error::NoSuchDriverError:
no such session
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.15.0-45-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: '03fdb0cca17d', ip: '172.17.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-45-generic', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8), userDataDir=/tmp/.org.chromium.Chromium.VTiW5k}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=60.0.3112.113, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: bbdeebbc74c3f543af5572cbe50c7f7f
*** Element info: {Using=css selector, value=#map-spot-creation} (org.openqa.selenium.NoSuchSessionException)
# [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstructorAccessorImpl.java):-2:in `newInstance0'
# [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstructorAccessorImpl.java):62:in `newInstance'
# [remote server] sun.reflect.DelegatingConstructorAccessorImpl(DelegatingConstructorAccessorImpl.java):45:in `newInstance'
# [remote server] java.lang.reflect.Constructor(Constructor.java):423:in `newInstance'
# [remote server] org.openqa.selenium.remote.ErrorHandler(ErrorHandler.java):215:in `createThrowable'
# [remote server] org.openqa.selenium.remote.ErrorHandler(ErrorHandler.java):167:in `throwIfResponseFailed'
# [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):671:in `execute'
# [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):437:in `findElements'
# [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):505:in `findElementsByCssSelector'
# [remote server] org.openqa.selenium.By$ByCssSelector(By.java):441:in `findElements'
# [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):398:in `findElements'
# [remote server] sun.reflect.GeneratedMethodAccessor12():-1:in `invoke'
# [remote server] sun.reflect.DelegatingMethodAccessorImpl(DelegatingMethodAccessorImpl.java):43:in `invoke'
# [remote server] java.lang.reflect.Method(Method.java):498:in `invoke'
# [remote server] org.openqa.selenium.support.events.EventFiringWebDriver$2(EventFiringWebDriver.java):104:in `invoke'
# [remote server] com.sun.proxy.$Proxy4():-1:in `findElements'
# [remote server] org.openqa.selenium.support.events.EventFiringWebDriver(EventFiringWebDriver.java):177:in `findElements'
# [remote server] org.openqa.selenium.remote.server.handler.FindElements(FindElements.java):50:in `call'
# [remote server] org.openqa.selenium.remote.server.handler.FindElements(FindElements.java):35:in `call'
# [remote server] java.util.concurrent.FutureTask(FutureTask.java):266:in `run'
# [remote server] org.openqa.selenium.remote.server.DefaultSession$1(DefaultSession.java):176:in `run'
# [remote server] java.util.concurrent.ThreadPoolExecutor(ThreadPoolExecutor.java):1149:in `runWorker'
# [remote server] java.util.concurrent.ThreadPoolExecutor$Worker(ThreadPoolExecutor.java):624:in `run'
# [remote server] java.lang.Thread(Thread.java):748:in `run'
# ./spec/features/user_creates_a_spot_account_spec.rb:24:in `block (2 levels) in <top (required)>'