2018-06-25 18:21:20 +00: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', 4445)
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_selenium_running!
|
2018-06-28 17:18:50 +00:00
|
|
|
timer = Capybara::Helpers.timer(expire_in: 20)
|
|
|
|
begin
|
|
|
|
TCPSocket.open(selenium_host, selenium_port)
|
2018-07-10 21:18:39 +00:00
|
|
|
rescue StandardError
|
2018-06-28 17:18:50 +00:00
|
|
|
if timer.expired?
|
|
|
|
raise 'Selenium is not running. ' \
|
|
|
|
"You can run a selenium server easily with: \n" \
|
|
|
|
' $ docker-compose up -d selenium_firefox'
|
|
|
|
else
|
2018-07-10 21:18:39 +00:00
|
|
|
puts 'Waiting for Selenium docker instance...'
|
2018-06-28 17:18:50 +00:00
|
|
|
sleep 1
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
end
|
2018-06-25 18:21:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Capybara.register_driver :selenium_firefox_remote do |app|
|
|
|
|
ensure_selenium_running!
|
|
|
|
|
|
|
|
url = "http://#{selenium_host}:#{selenium_port}/wd/hub"
|
|
|
|
caps = Selenium::WebDriver::Remote::Capabilities.firefox
|
|
|
|
|
|
|
|
Capybara::Selenium::Driver.new app,
|
|
|
|
browser: :remote,
|
|
|
|
desired_capabilities: caps,
|
|
|
|
url: url
|
|
|
|
end
|
|
|
|
|
|
|
|
FIREFOX_REMOTE_DRIVER = :selenium_firefox_remote
|
|
|
|
|
|
|
|
module TestSessions
|
2018-07-05 18:50:43 +00:00
|
|
|
RemoteFirefox = Capybara::Session.new(FIREFOX_REMOTE_DRIVER, TestApp)
|
2018-06-25 18:21:20 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 18:50:43 +00:00
|
|
|
TestSessions::RemoteFirefox.driver.browser.file_detector = lambda do |args|
|
2018-06-25 22:28:30 +00:00
|
|
|
# args => ["/path/to/file"]
|
|
|
|
str = args.first.to_s
|
|
|
|
str if File.exist?(str)
|
|
|
|
end
|
|
|
|
|
2018-06-25 18:21:20 +00:00
|
|
|
skipped_tests = %i[response_headers status_code trigger download]
|
|
|
|
# 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-07-05 18:50:43 +00:00
|
|
|
Capybara::SpecHelper.run_specs TestSessions::RemoteFirefox, FIREFOX_REMOTE_DRIVER.to_s, capybara_skip: skipped_tests do |example|
|
|
|
|
case example.metadata[:full_description]
|
|
|
|
when 'Capybara::Session selenium_firefox_remote node #click should allow multiple modifiers'
|
|
|
|
pending "Firefox doesn't generate an event for shift+control+click" if marionette_gte?(62, @session)
|
|
|
|
when /^Capybara::Session selenium node #double_click/
|
|
|
|
pending "selenium-webdriver/geckodriver doesn't generate double click event" if marionette_lt?(59, @session)
|
|
|
|
when 'Capybara::Session selenium_firefox_remote #accept_prompt should accept the prompt with a blank response when there is a default'
|
|
|
|
pending "Geckodriver doesn't set a blank response currently"
|
2018-07-24 21:13:03 +00:00
|
|
|
when 'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once for each set of files uploaded',
|
|
|
|
'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once when uploading multiple files from empty'
|
|
|
|
pending 'Due to having to work around selenium remote lack of multiple file upload support the change event count is off'
|
2018-07-05 18:50:43 +00:00
|
|
|
end
|
|
|
|
end
|
2018-06-25 18:21:20 +00:00
|
|
|
|
2018-07-10 21:18:39 +00:00
|
|
|
RSpec.describe 'Capybara::Session with remote firefox' do
|
2018-06-25 18:21:20 +00:00
|
|
|
include Capybara::SpecHelper
|
2018-07-10 21:18:39 +00:00
|
|
|
include_examples 'Capybara::Session', TestSessions::RemoteFirefox, FIREFOX_REMOTE_DRIVER
|
2018-07-05 18:50:43 +00:00
|
|
|
include_examples Capybara::RSpecMatchers, TestSessions::RemoteFirefox, FIREFOX_REMOTE_DRIVER
|
2018-06-25 18:21:20 +00:00
|
|
|
|
|
|
|
it 'is considered to be firefox' do
|
2018-08-24 18:32:55 +00:00
|
|
|
expect(session.driver.browser.browser).to eq :firefox
|
2018-06-25 18:21:20 +00:00
|
|
|
end
|
|
|
|
end
|