Skip to content

Commit

Permalink
rb - fix legacy firefox tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 3, 2016
1 parent 8db03a0 commit 4888aa8
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 172 deletions.
108 changes: 62 additions & 46 deletions rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,80 @@

module Selenium
module WebDriver
module Firefox
compliant_on browser: :ff_legacy do
describe Driver do
describe '.new' do
before do
@opt = {}
@opt[:url] = GlobalTestEnv.remote_server.webdriver_url if GlobalTestEnv.driver == :remote
end
compliant_on browser: :firefox do
describe Firefox do
def restart_remote_server
server = GlobalTestEnv.reset_remote_server
server.start
server.webdriver_url
end

it 'takes a binary path as an argument' do
pending "Set ENV['ALT_FIREFOX_BINARY'] to test this" unless ENV['ALT_FIREFOX_BINARY']
before(:all) do
driver
quit_driver
end

begin
default_path = Firefox::Binary.path
before(:each) do
@opt = {}
@opt[:url] = restart_remote_server if GlobalTestEnv.driver == :remote
end

caps1 = Remote::Capabilities.firefox(marionette: false)
@opt[:desired_capabilities] = caps1
it 'creates default capabilities' do
driver_name = GlobalTestEnv.driver
driver_name = :firefox if driver_name == :firefox

driver1 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt
default_version = driver1.capabilities[:version]
driver1.quit
begin
driver1 = Selenium::WebDriver.for driver_name, @opt
expect(driver1.capabilities.browser_version).to match(/^\d\d\./)
expect(driver1.capabilities.platform_name).to_not be_nil
expect(driver1.capabilities.platform_version).to_not be_nil
expect(driver1.capabilities.accept_ssl_certs).to be == false
expect(driver1.capabilities.page_load_strategy).to be == 'normal'
expect(driver1.capabilities.proxy).to be_nil
if GlobalTestEnv.driver == :remote
expect(driver1.capabilities.remote_session_id).to match(/^\h{8}-\h{4}-\h{4}-\h{4}-\h{10}/)
else
expect(driver1.capabilities.remote_session_id).to be_nil
end
expect(driver1.capabilities.raise_accessibility_exceptions).to be == false
expect(driver1.capabilities.rotatable).to be == false
ensure
driver1.quit
end
end

caps2 = Remote::Capabilities.firefox(
firefox_binary: ENV['ALT_FIREFOX_BINARY'],
marionette: false
)
@opt[:desired_capabilities] = caps2
driver2 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt
# Test this in isolation; Firefox doesn't like to switch between binaries in same session
not_compliant_on driver: :remote do
it 'takes a binary path as an argument' do
pending "Set ENV['ALT_FIREFOX_BINARY'] to test this" unless ENV['ALT_FIREFOX_BINARY']

expect(driver2.capabilities[:version]).to_not be == default_version
driver2.quit
ensure
Firefox::Binary.path = default_path
end
end
begin
driver1 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt

default_version = driver1.capabilities.version
expect { driver1.capabilities.browser_version }.to_not raise_exception NoMethodError
driver1.quit

not_compliant_on driver: :remote do
it 'takes a Firefox::Profile instance as argument' do
begin
@opt[:desired_capabilities] = Remote::Capabilities.firefox(marionette: false)
profile = Selenium::WebDriver::Firefox::Profile.new
@opt[:profile] = profile
driver2 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt
caps = Remote::Capabilities.firefox(firefox_binary: ENV['ALT_FIREFOX_BINARY'])
@opt[:desired_capabilities] = caps
driver2 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt

stored_profile = driver2.instance_variable_get('@bridge')
.instance_variable_get('@launcher')
.instance_variable_get('@profile')
expect(stored_profile).to be == profile
ensure
driver2.quit if driver2
end
end
expect(driver2.capabilities.version).to_not eql(default_version)
expect { driver2.capabilities.browser_version }.to_not raise_exception NoMethodError
driver2.quit
ensure
Firefox::Binary.reset_path!
end
end
end

it_behaves_like 'driver that can be started concurrently', :firefox
# https://github.com/mozilla/geckodriver/issues/58
not_compliant_on browser: :firefox do
context 'when shared example' do
it_behaves_like 'driver that can be started concurrently', :firefox
end
end
end
end # Firefox
end
end # WebDriver
end # Selenium
57 changes: 57 additions & 0 deletions rb/spec/integration/selenium/webdriver/firefox/legacy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# encoding: utf-8
#
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

require_relative '../spec_helper'

module Selenium
module WebDriver
module Firefox
compliant_on browser: :ff_legacy do
describe Driver do
describe '.new' do
before do
@opt = {}
@opt[:url] = GlobalTestEnv.remote_server.webdriver_url if GlobalTestEnv.driver == :remote
end

not_compliant_on driver: :remote do
it 'takes a Firefox::Profile instance as argument' do
begin
@opt[:desired_capabilities] = Remote::Capabilities.firefox(marionette: false)
profile = Selenium::WebDriver::Firefox::Profile.new
@opt[:profile] = profile
driver2 = Selenium::WebDriver.for :firefox, @opt

stored_profile = driver2.instance_variable_get('@bridge')
.instance_variable_get('@launcher')
.instance_variable_get('@profile')
expect(stored_profile).to be == profile
ensure
driver2.quit if driver2
end
end
end
end

it_behaves_like 'driver that can be started concurrently', :ff_legacy
end
end
end # Firefox
end # WebDriver
end # Selenium
100 changes: 0 additions & 100 deletions rb/spec/integration/selenium/webdriver/firefox/marionette_spec.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,32 @@

shared_examples_for 'driver that can be started concurrently' do |browser_name|
it 'is started sequentially' do
marionette = browser_name == :ff_legacy ? {marionette: false} : {}
browser_name = :firefox if browser_name == :ff_legacy
caps_opt = {}
if browser_name == :ff_legacy
caps_opt[:firefox_binary] = ENV['FF_LEGACY_BINARY']
caps_opt[:marionette] = false
browser_name = :firefox
end

expect do
# start 5 drivers concurrently
threads = []
drivers = []

opt = {}
if GlobalTestEnv.remote_server?
opt[:url] = GlobalTestEnv.remote_server.webdriver_url
end
driver = if GlobalTestEnv.remote_server?
opt[:url] = GlobalTestEnv.remote_server.webdriver_url
:remote
else
browser_name
end

caps = if browser_name == :firefox
WebDriver::Remote::Capabilities.firefox(marionette)
else
WebDriver::Remote::Capabilities.send(browser_name)
end
caps = WebDriver::Remote::Capabilities.send(browser_name, caps_opt)
opt[:desired_capabilities] = caps

5.times do
threads << Thread.new do
drivers << Selenium::WebDriver.for(GlobalTestEnv.driver, opt.dup)
drivers << Selenium::WebDriver.for(driver, opt.dup)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,17 @@ def create_driver

def remote_capabilities
opt = {}
browser_name = browser == :ff_legacy ? :firefox : browser
opt[:marionette] = false if browser == :ff_legacy
browser_name = if browser == :ff_legacy
unless ENV['FF_LEGACY_BINARY']
raise DriverInstantiationError, "ENV['FF_LEGACY_BINARY'] must be set to test legacy firefox"
end

opt[:firefox_binary] = ENV['FF_LEGACY_BINARY']
opt[:marionette] = false
:firefox
else
browser
end

caps = WebDriver::Remote::Capabilities.send(browser_name, opt)

Expand Down Expand Up @@ -182,22 +191,20 @@ def create_remote_driver
)
end

def create_firefox_driver(marionette = true)
WebDriver::Firefox.path = ENV['FIREFOX_BINARY'] if ENV['FIREFOX_BINARY']
def create_firefox_driver
WebDriver::Firefox::Binary.path = ENV['FIREFOX_BINARY'] if ENV['FIREFOX_BINARY']
WebDriver::Driver.for :firefox
end

opt = if marionette
{}
else
WebDriver::Firefox.path = ENV['FF_LEGACY_BINARY'] if ENV['FF_LEGACY_BINARY']
{marionette: false}
def create_ff_legacy_driver
unless ENV['FF_LEGACY_BINARY']
raise StandardError, "ENV['FF_LEGACY_BINARY'] must be set to test legacy firefox"
end
caps = WebDriver::Remote::Capabilities.firefox(opt)
WebDriver::Firefox::Binary.path = ENV['FF_LEGACY_BINARY']

WebDriver::Driver.for :firefox, desired_capabilities: caps
end
caps = WebDriver::Remote::Capabilities.firefox(marionette: false)

def create_ff_legacy_driver
create_firefox_driver(false)
WebDriver::Driver.for :firefox, desired_capabilities: caps
end

def create_chrome_driver
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/timeout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module WebDriver
expect(driver.find_elements(class_name: 'redbox')).to be_empty
end

not_compliant_on browser: :marionette, platform: :windows do
not_compliant_on browser: :firefox, platform: :windows do
it 'should return after first attempt to find many after disabling implicit waits' do
add = driver.find_element(id: 'adder')

Expand Down

0 comments on commit 4888aa8

Please sign in to comment.