Skip to content

Commit

Permalink
Run remote testing with firefox too
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Jun 26, 2018
1 parent 121c391 commit 7805423
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
18 changes: 16 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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

Expand All @@ -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"
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/selenium_spec_chrome_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module TestSessions

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
Expand Down
57 changes: 57 additions & 0 deletions spec/selenium_spec_firefox_remote.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7805423

Please sign in to comment.