1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Run remote testing with firefox too

This commit is contained in:
Thomas Walpole 2018-06-25 11:21:20 -07:00
parent 121c391492
commit 7805423ce2
5 changed files with 86 additions and 5 deletions

View file

@ -35,6 +35,9 @@ matrix:
- gemfile: Gemfile
rvm: 2.5.1
env: CAPYBARA_CHROME_REMOTE=true
- gemfile: Gemfile
rvm: 2.5.1
env: CAPYBARA_FIREFOX_REMOTE=true
- gemfile: gemfiles/Gemfile.rspec-34
rvm: 2.3.6
env: CAPYBARA_FF=true
@ -71,6 +74,7 @@ matrix:
- gemfile: gemfiles/Gemfile.beta-versions
- gemfile: gemfiles/Gemfile.edge-marionette
- env: CAPYBARA_CHROME_REMOTE=true
- env: CAPYBARA_FIREFOX_REMOTE=true
before_install:
- gem update --system
- gem install bundler
@ -82,7 +86,7 @@ before_install:
bundle config local.selenium-webdriver ../selenium/build/rb;
fi
before_script:
- if [[ -z $HEADLESS && -z $CAPYBARA_CHROME_REMOTE ]]; then
- if [[ -z $HEADLESS && -z $CAPYBARA_CHROME_REMOTE && -z $CAPYBARA_FIREFOX_REMOTE ]]; then
export DISPLAY=:99.0;
sh -e /etc/init.d/xvfb start;
sleep 1;
@ -91,7 +95,7 @@ before_script:
awesome &
fi
- if [[ $CAPYBARA_CHROME_REMOTE = true ]]; then
docker-compose up -d selenium
docker-compose up -d selenium_chrome
TIMEOUT=10
@ -100,5 +104,15 @@ before_script:
sleep 1;
done
fi
- if [[ $CAPYBARA_FIREFOX_REMOTE = true ]]; then
docker-compose up -d selenium_firefox
TIMEOUT=10
until wget --spider http://localhost:4445 > /dev/null 2>&1 || [ $TIMEOUT -eq 0 ]; do
echo "Waiting for selenium server, $((TIMEOUT--)) remaining attempts...";
sleep 1;
done
fi
script: "bundle exec rake travis"

View file

@ -14,7 +14,7 @@ RSpec::Core::RakeTask.new(:spec_marionette) do |t|
t.pattern = './spec{,/*/**}/*{_spec.rb,_spec_marionette.rb}'
end
%w[chrome ie edge chrome_remote].each do |driver|
%w[chrome ie edge chrome_remote firefox_remote].each do |driver|
RSpec::Core::RakeTask.new(:"spec_#{driver}") do |t|
t.rspec_opts = rspec_opts
t.pattern = "./spec/*{_spec_#{driver}.rb}"
@ -46,6 +46,8 @@ task :travis do
Rake::Task[:spec_edge].invoke
elsif ENV['CAPYBARA_CHROME_REMOTE']
Rake::Task[:spec_chrome_remote].invoke
elsif ENV['CAPYBARA_FIREFOX_REMOTE']
Rake::Task[:spec_firefox_remote].invoke
else
Rake::Task[:spec_chrome].invoke
end

View file

@ -2,9 +2,17 @@
version: "2.1"
services:
selenium:
selenium_chrome:
network_mode: "host"
image: "selenium/${SELENIUM_IMAGE:-standalone-chrome-debug}"
volumes:
- "/dev/shm:/dev/shm"
- "${PWD}:${PWD}" # For making attach_file specs work
selenium_firefox:
network_mode: "host"
image: "selenium/${SELENIUM_IMAGE:-standalone-firefox-debug}"
volumes:
- "/dev/shm:/dev/shm"
- "${PWD}:${PWD}" # For making attach_file specs work
environment:
- SE_OPTS=-port 4445

View file

@ -45,7 +45,7 @@ skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLE
Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_REMOTE_DRIVER.to_s, capybara_skip: skipped_tests
RSpec.describe "Capybara::Session with chrome" do
RSpec.describe "Capybara::Session with remote Chrome" do
include Capybara::SpecHelper
include_examples "Capybara::Session", TestSessions::Chrome, CHROME_REMOTE_DRIVER
include_examples Capybara::RSpecMatchers, TestSessions::Chrome, CHROME_REMOTE_DRIVER

View file

@ -0,0 +1,57 @@
# 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!
TCPSocket.open(selenium_host, selenium_port)
rescue
raise 'Selenium is not running. ' \
"You can run a selenium server easily with: \n" \
' $ docker-compose up -d selenium'
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
Firefox = Capybara::Session.new(FIREFOX_REMOTE_DRIVER, TestApp)
end
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'])
Capybara::SpecHelper.run_specs TestSessions::Firefox, FIREFOX_REMOTE_DRIVER.to_s, capybara_skip: skipped_tests
RSpec.describe "Capybara::Session with remote firefox" do
include Capybara::SpecHelper
include_examples "Capybara::Session", TestSessions::Firefox, FIREFOX_REMOTE_DRIVER
include_examples Capybara::RSpecMatchers, TestSessions::Firefox, FIREFOX_REMOTE_DRIVER
it 'is considered to be firefox' do
expect(session.driver.send(:firefox?)).to be_truthy
expect(session.driver.send(:marionette?)).to be_truthy
end
end