2018-04-24 18:47:53 -04:00
# frozen_string_literal: true
require 'spec_helper'
require 'selenium-webdriver'
require 'shared_selenium_session'
require 'rspec/shared_spec_matchers'
def selenium_host
ENV . fetch ( 'SELENIUM_HOST' , '0.0.0.0' )
end
def selenium_port
ENV . fetch ( 'SELENIUM_PORT' , 4444 )
end
def ensure_selenium_running!
TCPSocket . open ( selenium_host , selenium_port )
rescue
raise 'Selenium is not running. ' \
" You can run a selenium server easily with: \n " \
2018-06-25 19:31:31 -04:00
' $ docker-compose up -d selenium_chrome'
2018-04-24 18:47:53 -04:00
end
Capybara . register_driver :selenium_chrome_remote do | app |
ensure_selenium_running!
url = " http:// #{ selenium_host } : #{ selenium_port } /wd/hub "
caps = Selenium :: WebDriver :: Remote :: Capabilities . chrome
Capybara :: Selenium :: Driver . new app ,
browser : :remote ,
desired_capabilities : caps ,
url : url
end
CHROME_REMOTE_DRIVER = :selenium_chrome_remote
module TestSessions
Chrome = Capybara :: Session . new ( CHROME_REMOTE_DRIVER , TestApp )
end
2018-06-25 18:28:30 -04:00
TestSessions :: Chrome . driver . browser . file_detector = lambda do | args |
# args => ["/path/to/file"]
str = args . first . to_s
str if File . exist? ( str )
end
2018-06-17 16:35:29 -04:00
skipped_tests = % i [ response_headers status_code trigger download ]
2018-04-24 18:47:53 -04:00
# skip window tests when headless for now - closing a window not supported by chromedriver/chrome
skipped_tests << :windows if ENV [ 'TRAVIS' ] && ( ENV [ 'SKIP_WINDOW' ] || ENV [ 'HEADLESS' ] )
2018-06-25 20:27:36 -04:00
RSpec . configure do | config |
config . define_derived_metadata do | metadata |
case metadata [ :full_description ]
when / ^Capybara::Session selenium_chrome_remote # attach_file with multipart form should not break when using HTML5 multiple file input uploading multiple files$ /
metadata [ :pending ] = " Selenium with Remote Chrome doesn't support multiple file upload "
end
end
end
2018-04-24 18:47:53 -04:00
Capybara :: SpecHelper . run_specs TestSessions :: Chrome , CHROME_REMOTE_DRIVER . to_s , capybara_skip : skipped_tests
2018-06-25 14:21:20 -04:00
RSpec . describe " Capybara::Session with remote Chrome " do
2018-04-24 18:47:53 -04:00
include Capybara :: SpecHelper
include_examples " Capybara::Session " , TestSessions :: Chrome , CHROME_REMOTE_DRIVER
include_examples Capybara :: RSpecMatchers , TestSessions :: Chrome , CHROME_REMOTE_DRIVER
2018-06-12 16:06:25 -04:00
it 'is considered to be chrome' do
2018-06-08 17:59:03 -04:00
expect ( session . driver . send ( :chrome? ) ) . to be_truthy
2018-04-24 18:47:53 -04:00
end
end