Skip to content

Commit

Permalink
Change from using marionette to firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Nov 19, 2018
1 parent 6e1e3ea commit 148c825
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ matrix:
apt:
packages:
- awesome
- gemfile: gemfiles/Gemfile.edge-marionette
- gemfile: gemfiles/Gemfile.edge-firefox
rvm: ruby-head
env:
- CAPYBARA_FF=true
- CAPYBARA_REMOTE=true
- gemfile: gemfiles/Gemfile.edge-marionette
- gemfile: gemfiles/Gemfile.edge-firefox
rvm: ruby-head
env:
- CAPYBARA_REMOTE=true
- HEADLESS=true
- gemfile: gemfiles/Gemfile.edge-marionette
- gemfile: gemfiles/Gemfile.edge-firefox
rvm: ruby-head
env: CAPYBARA_FF=true RUBY_OPT=--jit
addons:
Expand All @@ -94,11 +94,11 @@ matrix:
script: bundle exec rake spec_rack
allow_failures:
- gemfile: gemfiles/Gemfile.beta-versions
- gemfile: gemfiles/Gemfile.edge-marionette
- gemfile: gemfiles/Gemfile.edge-firefox
- env: W3C=true HEADLESS=true
before_install:
- gem update --system
- if [[ $BUNDLE_GEMFILE =~ Gemfile.edge-marionette$ ]]; then
- if [[ $BUNDLE_GEMFILE =~ Gemfile.edge-firefox$ ]]; then
pushd ..;
git clone --depth 1 https://github.com/SeleniumHQ/selenium.git;
cd selenium; ./go //rb:gem:build;
Expand Down
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ require 'rspec/core/rake_task'
require 'cucumber/rake/task'
require 'yard'

desc 'Run all examples with Firefox non-marionette'
desc 'Run all examples with Firefox'

rspec_opts = %w[--color]

RSpec::Core::RakeTask.new(:spec_marionette) do |t|
RSpec::Core::RakeTask.new(:spec_firefox) do |t|
t.rspec_opts = rspec_opts
t.pattern = './spec{,/*/**}/*{_spec.rb,_spec_marionette.rb}'
t.pattern = './spec{,/*/**}/*{_spec.rb,_spec_firefox.rb}'
end

%w[chrome ie edge chrome_remote firefox_remote].each do |driver|
Expand All @@ -26,7 +26,7 @@ RSpec::Core::RakeTask.new(:spec_rack) do |t|
t.pattern = './spec{,/*/**}/*{_spec.rb}'
end

task spec: [:spec_marionette]
task spec: [:spec_firefox]

YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb']
Expand All @@ -41,7 +41,7 @@ task :travis do
if ENV['CAPYBARA_REMOTE'] && ENV['CAPYBARA_FF']
Rake::Task[:spec_firefox_remote].invoke
elsif ENV['CAPYBARA_FF']
Rake::Task[:spec_marionette].invoke
Rake::Task[:spec_firefox].invoke
elsif ENV['CAPYBARA_IE']
Rake::Task[:spec_ie].invoke
elsif ENV['CAPYBARA_EDGE']
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/capybara/queries/base_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def count_message
if count
message << " #{occurrences count}"
elsif between
message << " between #{between.first} and #{between.end ? between.last : "infinite"} times"
message << " between #{between.first} and #{between.end ? between.last : 'infinite'} times"
elsif maximum
message << " at most #{occurrences maximum}"
elsif minimum
Expand Down
4 changes: 2 additions & 2 deletions lib/capybara/selenium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def specialize_driver(sel_driver)
extend ChromeDriver
when :firefox
require 'capybara/selenium/patches/pause_duration_fix' if pause_broken?(sel_driver)
extend MarionetteDriver if sel_driver.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
extend FirefoxDriver if sel_driver.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
end
end

Expand Down Expand Up @@ -396,4 +396,4 @@ def accept_unhandled_reset_alert
end

require 'capybara/selenium/driver_specializations/chrome_driver'
require 'capybara/selenium/driver_specializations/marionette_driver'
require 'capybara/selenium/driver_specializations/firefox_driver'
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'capybara/selenium/nodes/marionette_node'
require 'capybara/selenium/nodes/firefox_node'

module Capybara::Selenium::Driver::MarionetteDriver
module Capybara::Selenium::Driver::FirefoxDriver
def resize_window_to(handle, width, height)
within_given_window(handle) do
# Don't set the size if already set - See https://github.com/mozilla/geckodriver/issues/643
Expand Down Expand Up @@ -45,6 +45,6 @@ def switch_to_frame(frame)
private

def build_node(native_node)
::Capybara::Selenium::MarionetteNode.new(self, native_node)
::Capybara::Selenium::FirefoxNode.new(self, native_node)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'capybara/selenium/extensions/html5_drag'

class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
class Capybara::Selenium::FirefoxNode < Capybara::Selenium::Node
include Html5Drag

def click(keys = [], **options)
Expand Down
32 changes: 16 additions & 16 deletions spec/selenium_spec_marionette.rb → spec/selenium_spec_firefox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv'
end

Capybara.register_driver :selenium_marionette do |app|
Capybara.register_driver :selenium_firefox do |app|
# ::Selenium::WebDriver.logger.level = "debug"
Capybara::Selenium::Driver.new(
app,
Expand All @@ -26,7 +26,7 @@
)
end

Capybara.register_driver :selenium_marionette_clear_storage do |app|
Capybara.register_driver :selenium_firefox_clear_storage do |app|
Capybara::Selenium::Driver.new(
app,
browser: :firefox,
Expand All @@ -37,29 +37,29 @@
end

module TestSessions
SeleniumMarionette = Capybara::Session.new(:selenium_marionette, TestApp)
SeleniumFirefox = Capybara::Session.new(:selenium_firefox, TestApp)
end

skipped_tests = %i[response_headers status_code trigger]
skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']

$stdout.puts `#{Selenium::WebDriver::Firefox.driver_path} --version` if ENV['CI']

Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, 'selenium', capybara_skip: skipped_tests do |example|
Capybara::SpecHelper.run_specs TestSessions::SeleniumFirefox, 'selenium', capybara_skip: skipped_tests do |example|
case example.metadata[:full_description]
when 'Capybara::Session selenium node #click should allow multiple modifiers'
pending "Firefox doesn't generate an event for shift+control+click" if marionette_gte?(62, @session) && !Gem.win_platform?
pending "Firefox doesn't generate an event for shift+control+click" if firefox_gte?(62, @session) && !Gem.win_platform?
when /^Capybara::Session selenium node #double_click/
pending "selenium-webdriver/geckodriver doesn't generate double click event" if marionette_lt?(59, @session)
pending "selenium-webdriver/geckodriver doesn't generate double click event" if firefox_lt?(59, @session)
when 'Capybara::Session selenium #accept_prompt should accept the prompt with a blank response when there is a default'
pending "Geckodriver doesn't set a blank response in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if marionette_lt?(63, @session)
pending "Geckodriver doesn't set a blank response in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if firefox_lt?(63, @session)
when 'Capybara::Session selenium #attach_file with multipart form should fire change once for each set of files uploaded'
pending 'Gekcodriver appends files so we have to first call clear for multiple files which creates an extra change ' \
'if files are already set'
when 'Capybara::Session selenium #attach_file with multipart form should fire change once when uploading multiple files from empty'
pending "FF < 62 doesn't support setting all files at once" if marionette_lt?(62, @session)
pending "FF < 62 doesn't support setting all files at once" if firefox_lt?(62, @session)
when 'Capybara::Session selenium #accept_confirm should work with nested modals'
skip 'Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358' if marionette_gte?(63, @session)
skip 'Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358' if firefox_gte?(63, @session)
when 'Capybara::Session selenium #click_link can download a file'
skip 'Need to figure out testing of file downloading on windows platform' if Gem.win_platform?
when 'Capybara::Session selenium #reset_session! removes ALL cookies'
Expand All @@ -69,8 +69,8 @@ module TestSessions

RSpec.describe 'Capybara::Session with firefox' do # rubocop:disable RSpec/MultipleDescribes
include Capybara::SpecHelper
include_examples 'Capybara::Session', TestSessions::SeleniumMarionette, :selenium_marionette
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumMarionette, :selenium_marionette
include_examples 'Capybara::Session', TestSessions::SeleniumFirefox, :selenium_firefox
include_examples Capybara::RSpecMatchers, TestSessions::SeleniumFirefox, :selenium_firefox
end

RSpec.describe Capybara::Selenium::Driver do
Expand Down Expand Up @@ -126,7 +126,7 @@ module TestSessions
context 'storage' do
describe '#reset!' do
it 'does not clear either storage by default' do
@session = TestSessions::SeleniumMarionette
@session = TestSessions::SeleniumFirefox
@session.visit('/with_js')
@session.find(:css, '#set-storage').click
@session.reset!
Expand All @@ -136,7 +136,7 @@ module TestSessions
end

it 'clears storage when set' do
@session = Capybara::Session.new(:selenium_marionette_clear_storage, TestApp)
@session = Capybara::Session.new(:selenium_firefox_clear_storage, TestApp)
@session.visit('/with_js')
@session.find(:css, '#set-storage').click
@session.reset!
Expand All @@ -151,7 +151,7 @@ module TestSessions
RSpec.describe Capybara::Selenium::Node do
context '#click' do
it 'warns when attempting on a table row' do
session = TestSessions::SeleniumMarionette
session = TestSessions::SeleniumFirefox
session.visit('/tables')
tr = session.find(:css, '#agent_table tr:first-child')
allow(tr.base).to receive(:warn)
Expand All @@ -160,7 +160,7 @@ module TestSessions
end

it 'should allow multiple modifiers', requires: [:js] do
session = TestSessions::SeleniumMarionette
session = TestSessions::SeleniumFirefox
session.visit('with_js')
# Firefox v62+ doesn't generate an event for control+shift+click
session.find(:css, '#click-test').click(:alt, :ctrl, :meta)
Expand All @@ -171,7 +171,7 @@ module TestSessions

context '#send_keys' do
it 'should process space' do
session = TestSessions::SeleniumMarionette
session = TestSessions::SeleniumFirefox
session.visit('/form')
session.find(:css, '#address1_city').send_keys('ocean', [:shift, :space, 'side'])
expect(session.find(:css, '#address1_city').value).to eq 'ocean SIDE'
Expand Down
8 changes: 4 additions & 4 deletions spec/selenium_spec_firefox_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ module TestSessions
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'
skip "Firefox doesn't generate an event for shift+control+click" if marionette_gte?(62, @session)
skip "Firefox doesn't generate an event for shift+control+click" if firefox_gte?(62, @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 in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if marionette_lt?(63, @session)
pending "Geckodriver doesn't set a blank response in FF < 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1486485" if firefox_lt?(63, @session)
when 'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once for each set of files uploaded'
pending 'Gekcodriver appends files so we have to first call clear for multiple files which creates an extra change ' \
'if files are already set'
when 'Capybara::Session selenium_firefox_remote #attach_file with multipart form should fire change once when uploading multiple files from empty'
pending "FF < 62 doesn't support setting all files at once" if marionette_lt?(62, @session)
pending "FF < 62 doesn't support setting all files at once" if firefox_lt?(62, @session)
when 'Capybara::Session selenium_firefox_remote #reset_session! removes ALL cookies'
pending "Geckodriver doesn't provide a way to remove cookies outside the current domain"
when /#accept_confirm should work with nested modals$/
# skip because this is timing based and hence flaky when set to pending
skip 'Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358' if marionette_gte?(63, @session)
skip 'Broken in FF 63 - https://bugzilla.mozilla.org/show_bug.cgi?id=1487358' if firefox_gte?(63, @session)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/shared_selenium_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@

describe 'Element#drag_to' do
before do
skip "Firefox < 62 doesn't support a DataTransfer constuctor" if marionette_lt?(62.0, session)
skip "Firefox < 62 doesn't support a DataTransfer constuctor" if firefox_lt?(62.0, session)
skip "IE doesn't support a DataTransfer constuctor" if ie?(session)
end

Expand Down Expand Up @@ -336,7 +336,7 @@

describe 'Capybara#Node#attach_file' do
it 'can attach a directory' do
pending "Geckodriver doesn't support uploading a directory" if marionette?(session)
pending "Geckodriver doesn't support uploading a directory" if firefox?(session)
pending "Selenium remote doesn't support transferring a directory" if remote?(session)
pending "Headless Chrome doesn't support directory upload - https://bugs.chromium.org/p/chromedriver/issues/detail?id=2521&q=directory%20upload&colspec=ID%20Status%20Pri%20Owner%20Summary" if chrome?(session) && ENV['HEADLESS']

Expand Down
10 changes: 5 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

module Capybara
module SpecHelper
def marionette?(session)
def firefox?(session)
browser_name(session) == :firefox &&
session.driver.browser.capabilities.is_a?(::Selenium::WebDriver::Remote::W3C::Capabilities)
end

def marionette_lt?(version, session)
marionette?(session) && (session.driver.browser.capabilities[:browser_version].to_f < version)
def firefox_lt?(version, session)
firefox?(session) && (session.driver.browser.capabilities[:browser_version].to_f < version)
end

def marionette_gte?(version, session)
marionette?(session) && (session.driver.browser.capabilities[:browser_version].to_f >= version)
def firefox_gte?(version, session)
firefox?(session) && (session.driver.browser.capabilities[:browser_version].to_f >= version)
end

def chrome?(session)
Expand Down

0 comments on commit 148c825

Please sign in to comment.