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

Setup travis to test selenium-webdriver HEAD with Chrome too

This commit is contained in:
Thomas Walpole 2016-09-01 15:46:56 -07:00
parent 908edbcd4e
commit 8567aa1990
7 changed files with 82 additions and 56 deletions

View file

@ -30,16 +30,23 @@ matrix:
- gemfile: gemfiles/Gemfile.beta-versions - gemfile: gemfiles/Gemfile.beta-versions
rvm: 2.4.0-preview1 rvm: 2.4.0-preview1
- gemfile: gemfiles/Gemfile.beta-marionette - gemfile: gemfiles/Gemfile.beta-marionette
env: env: GECKODRIVER=true
- GECKODRIVER=true
SELENIUM_BETA=true
rvm: 2.3.1 rvm: 2.3.1
addons: addons:
firefox: latest-beta firefox: latest-beta
apt: apt:
packages: packages:
- awesome - awesome
- gemfile: gemfiles/Gemfile.beta-marionette
env: CAPYBARA_CHROME=true
rvm: 2.3.1
addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
- awesome
allow_failures: allow_failures:
- gemfile: gemfiles/Gemfile.beta-versions - gemfile: gemfiles/Gemfile.beta-versions
- gemfile: gemfiles/Gemfile.beta-marionette - gemfile: gemfiles/Gemfile.beta-marionette
@ -56,20 +63,24 @@ addons:
- awesome - awesome
before_install: before_install:
- mkdir -p ~/drivers; export PATH=~/drivers:$PATH;
- if [ $CAPYBARA_CHROME ]; then - if [ $CAPYBARA_CHROME ]; then
CHROMEDRIVER_VERSION=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE); CHROMEDRIVER_VERSION=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE);
CHROMEDRIVER_URL="http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"; CHROMEDRIVER_URL="http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip";
FILE=`mktemp`; wget "$CHROMEDRIVER_URL" -qO $FILE && unzip $FILE chromedriver -d ~; rm $FILE; chmod 777 ~/chromedriver; FILE=`mktemp`; wget "$CHROMEDRIVER_URL" -qO $FILE && unzip $FILE chromedriver -d ~/drivers; rm $FILE; chmod 777 ~/drivers/chromedriver;
~/drivers/chromedriver --version;
fi fi
- if [ $GECKODRIVER ]; then - if [ $GECKODRIVER ]; then
GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/v0.10.0/geckodriver-v0.10.0-linux64.tar.gz"; GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/v0.10.0/geckodriver-v0.10.0-linux64.tar.gz";
FILE=`mktemp`; wget "$GECKODRIVER_URL" -qO $FILE && tar xz -C ~ -f $FILE geckodriver; rm $FILE; chmod 777 ~/geckodriver; FILE=`mktemp`; wget "$GECKODRIVER_URL" -qO $FILE && tar xz -C ~/drivers -f $FILE geckodriver; rm $FILE; chmod 777 ~/drivers/geckodriver;
~/drivers/geckodriver --version;
fi fi
- if [ $SELENIUM_BETA ]; then - if [[ $BUNDLE_GEMFILE =~ Gemfile.beta-marionette$ ]]; then
cd ..; git clone --depth 1 https://github.com/SeleniumHQ/selenium.git; pushd ..;
git clone --depth 1 https://github.com/SeleniumHQ/selenium.git;
cd selenium; ./go //rb:gem:build; cd selenium; ./go //rb:gem:build;
cd ../capybara; popd;
bundle config local.selenium-webdriver $HOME/selenium/build/rb; bundle config local.selenium-webdriver ../selenium/build/rb;
fi fi
before_script: before_script:
- export DISPLAY=:99.0 - export DISPLAY=:99.0

View file

@ -6,9 +6,11 @@ require 'yard'
desc "Run all examples" desc "Run all examples"
RSpec::Core::RakeTask.new(:spec) do |t| RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = %w[--color] t.rspec_opts = %w[--color]
# When we drop RSpec 2.x support we can rename spec_chrome.rb and implement this properly
# t.exclude_pattern = './spec/*{_chrome_spec.rb}'
end end
RSpec::Core::RakeTask.new(:spec_with_chrome) do |t| RSpec::Core::RakeTask.new(:all) do |t|
t.rspec_opts = %w[--color] t.rspec_opts = %w[--color]
# jruby buffers the progress formatter so travis doesn't see output often enough # jruby buffers the progress formatter so travis doesn't see output often enough
t.rspec_opts << '--format documentation' if RUBY_PLATFORM=='java' t.rspec_opts << '--format documentation' if RUBY_PLATFORM=='java'

View file

@ -3,7 +3,7 @@ require 'spec_helper'
RSpec.describe Capybara::Selenium::Driver do RSpec.describe Capybara::Selenium::Driver do
it "should exit with a non-zero exit status" do it "should exit with a non-zero exit status" do
browser = Capybara::Selenium::Driver.new(TestApp).browser browser = Capybara::Selenium::Driver.new(TestApp, browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym).browser
expect(true).to eq(false) expect(true).to eq(false)
end end
end end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
RSpec.describe Capybara::Selenium::Driver do RSpec.describe Capybara::Selenium::Driver do
it "should exit with a zero exit status" do it "should exit with a zero exit status" do
browser = Capybara::Selenium::Driver.new(TestApp).browser browser = Capybara::Selenium::Driver.new(TestApp, browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym).browser
expect(true).to eq(true) expect(true).to eq(true)
end end
end end

View file

@ -0,0 +1,44 @@
# frozen_string_literal: true
require 'spec_helper'
require "selenium-webdriver"
require 'shared_selenium_session'
Capybara.register_driver :selenium_focus do |app|
# profile = Selenium::WebDriver::Firefox::Profile.new
# profile["focusmanager.testmode"] = true
# Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
Capybara::Selenium::Driver.new(app, browser: :firefox)
end
module TestSessions
Selenium = Capybara::Session.new(:selenium_focus, TestApp)
end
skipped_tests = [
:response_headers,
:status_code,
:trigger
]
skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => skipped_tests
RSpec.describe "Capybara::Session with firefox" do
include_examples "Capybara::Session", TestSessions::Selenium, :selenium_focus
end
RSpec.describe Capybara::Selenium::Driver do
before do
@driver = Capybara::Selenium::Driver.new(TestApp, browser: :firefox)
end
describe '#quit' do
it "should reset browser when quit" do
expect(@driver.browser).to be
@driver.quit
#access instance variable directly so we don't create a new browser instance
expect(@driver.instance_variable_get(:@browser)).to be_nil
end
end
end

View file

@ -1,8 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
require 'selenium-webdriver' require 'selenium-webdriver'
require 'shared_selenium_session'
Selenium::WebDriver::Chrome.driver_path = '/home/travis/chromedriver' if ENV['TRAVIS']
Capybara.register_driver :selenium_chrome do |app| Capybara.register_driver :selenium_chrome do |app|
args = ENV['TRAVIS'] ? ['no-sandbox' ] : [] args = ENV['TRAVIS'] ? ['no-sandbox' ] : []
@ -18,3 +17,7 @@ Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", :capybar
:status_code, :status_code,
:trigger :trigger
] unless ENV['TRAVIS'] && (RUBY_PLATFORM == 'java') ] unless ENV['TRAVIS'] && (RUBY_PLATFORM == 'java')
RSpec.describe "Capybara::Session with chrome" do
include_examples "Capybara::Session", TestSessions::Chrome, :selenium_chrome
end

View file

@ -2,32 +2,12 @@
require 'spec_helper' require 'spec_helper'
require "selenium-webdriver" require "selenium-webdriver"
Selenium::WebDriver::Firefox.driver_path = '/home/travis/geckodriver' if ENV['TRAVIS'] && ENV['GECKODRIVER'] RSpec.shared_examples "Capybara::Session" do |session, mode|
let(:session) {session}
Capybara.register_driver :selenium_focus do |app|
# profile = Selenium::WebDriver::Firefox::Profile.new
# profile["focusmanager.testmode"] = true
# Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
Capybara::Selenium::Driver.new(app, browser: :firefox)
end
module TestSessions
Selenium = Capybara::Session.new(:selenium_focus, TestApp)
end
skipped_tests = [
:response_headers,
:status_code,
:trigger
]
skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => skipped_tests
RSpec.describe Capybara::Session do
context 'with selenium driver' do context 'with selenium driver' do
before do before do
@session = TestSessions::Selenium @session = session
end end
describe '#driver' do describe '#driver' do
@ -38,7 +18,7 @@ RSpec.describe Capybara::Session do
describe '#mode' do describe '#mode' do
it "should remember the mode" do it "should remember the mode" do
expect(@session.mode).to eq(:selenium_focus) expect(@session.mode).to eq(mode)
end end
end end
@ -61,11 +41,13 @@ RSpec.describe Capybara::Session do
end end
it "should have return code 1 when running selenium_driver_rspec_failure.rb" do it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
ENV['SELENIUM_BROWSER'] = @session.driver.options[:browser].to_s
`rspec spec/fixtures/selenium_driver_rspec_failure.rb` `rspec spec/fixtures/selenium_driver_rspec_failure.rb`
expect($?.exitstatus).to eq(1) expect($?.exitstatus).to eq(1)
end end
it "should have return code 0 when running selenium_driver_rspec_success.rb" do it "should have return code 0 when running selenium_driver_rspec_success.rb" do
ENV['SELENIUM_BROWSER'] = @session.driver.options[:browser].to_s
`rspec spec/fixtures/selenium_driver_rspec_success.rb` `rspec spec/fixtures/selenium_driver_rspec_success.rb`
expect($?.exitstatus).to eq(0) expect($?.exitstatus).to eq(0)
end end
@ -76,7 +58,7 @@ RSpec.describe Capybara::Session do
@session.visit('/with_js') @session.visit('/with_js')
@session.click_link('Open alert') @session.click_link('Open alert')
@session.accept_alert @session.accept_alert
expect{@session.driver.browser.switch_to.alert}.to raise_error("No alert is present") expect{@session.driver.browser.switch_to.alert}.to raise_error(Selenium::WebDriver::Error::NoAlertPresentError)
end end
end end
@ -136,19 +118,3 @@ RSpec.describe Capybara::Session do
end end
end end
end end
RSpec.describe Capybara::Selenium::Driver do
before do
@driver = Capybara::Selenium::Driver.new(TestApp, browser: :firefox)
end
describe '#quit' do
it "should reset browser when quit" do
expect(@driver.browser).to be
@driver.quit
#access instance variable directly so we don't create a new browser instance
expect(@driver.instance_variable_get(:@browser)).to be_nil
end
end
end