Skip to content

Commit

Permalink
[rb] fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jun 27, 2019
1 parent 986b940 commit 6bb1875
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 131 deletions.
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ task :test_rb_local => [
task :test_rb_remote => [
"//rb:remote-chrome-test",
"//rb:remote-firefox-test",
("//rb:remote-safari-preview-test" if mac?),
("//rb:remote-safari-test" if mac?),
("//rb:remote-ie-test" if windows?),
("//rb:remote-edge-test" if windows?)
Expand Down
5 changes: 1 addition & 4 deletions rb/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ ruby_library(name = "remote",
"lib/selenium/webdriver/remote/**/*.rb",
"lib/selenium/webdriver/remote.rb"
],
deps = [
"//java/server/src/org/openqa/grid/selenium:selenium",
":common"
]
deps = [":common"]
)

ruby_test(name = "remote",
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def initialize(jar, opts = {})
@timeout = opts.fetch(:timeout, 30)
@background = opts.fetch(:background, false)
@log = opts[:log]

@log_file = nil
@additional_args = []
end

Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

require 'net/http'

require 'selenium/webdriver/chrome/bridge'
require 'selenium/webdriver/chrome/driver'
require 'selenium/webdriver/chrome/profile'
require 'selenium/webdriver/chrome/options'
Expand Down Expand Up @@ -52,3 +51,4 @@ def self.path
end # Selenium

require 'selenium/webdriver/chrome/service'
require 'selenium/webdriver/chrome/bridge'
3 changes: 2 additions & 1 deletion rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def initialize(opts = {})

listener = opts.delete(:listener)
desired_capabilities = opts.delete(:desired_capabilities)
options = opts.delete(:options)

@bridge = Remote::Bridge.new(opts)
@bridge.extend Bridge
@bridge.create_session(desired_capabilities)
@bridge.create_session(desired_capabilities, options)

super(@bridge, listener: listener)
end
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def for(browser, opts = {})
#

def initialize(bridge, listener: nil)
@service = nil
@bridge = bridge
@bridge = Support::EventFiringBridge.new(bridge, listener) if listener
end
Expand Down
12 changes: 10 additions & 2 deletions rb/lib/selenium/webdriver/common/profile_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ def self.included(base)
base.extend ClassMethods
end

def self.decoded(json)
JSON.parse(json).fetch('zip')
end

def encoded
Zipper.zip(layout_on_disk)
end

def as_json(*)
{"zip" => Zipper.zip(layout_on_disk)}
{"zip" => encoded}
end

def to_json(*)
Expand Down Expand Up @@ -63,7 +71,7 @@ def verify_model(model)

module ClassMethods
def from_json(json)
data = JSON.parse(json).fetch('zip')
data = decoded(json)

# can't use Tempfile here since it doesn't support File::BINARY mode on 1.8
# can't use Dir.mktmpdir(&blk) because of http://jira.codehaus.org/browse/JRUBY-4082
Expand Down
3 changes: 2 additions & 1 deletion rb/lib/selenium/webdriver/firefox/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ def initialize(opts = {})

listener = opts.delete(:listener)
desired_capabilities = opts.delete(:desired_capabilities)
options = opts.delete(:options)

@bridge = Remote::Bridge.new(opts)
@bridge.extend Bridge
@bridge.create_session(desired_capabilities)
@bridge.create_session(desired_capabilities, options)

super(@bridge, listener: listener)
end
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/firefox/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def headless!
# @param [Profile, String] profile Profile to be used
#

undef profile=
def profile=(profile)
process_profile(profile)
end
Expand Down
12 changes: 5 additions & 7 deletions rb/lib/selenium/webdriver/firefox/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def default_preferences
File.read(File.expand_path("#{WebDriver.root}/selenium/webdriver/firefox/extension/prefs.json"))
).freeze
end

def decoded(json)
JSON.parse(json)
end
end

#
Expand Down Expand Up @@ -178,13 +182,7 @@ def proxy=(proxy)
end
end

def encoded
Zipper.zip(layout_on_disk)
end

def as_json
encoded
end
alias_method :as_json, :encoded

private

Expand Down
3 changes: 2 additions & 1 deletion rb/lib/selenium/webdriver/ie/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def initialize(opts = {})

listener = opts.delete(:listener)
desired_capabilities = opts.delete(:desired_capabilities)
options = opts.delete(:options)

@bridge = Remote::Bridge.new(opts)
@bridge.create_session(desired_capabilities)
@bridge.create_session(desired_capabilities, options)

super(@bridge, listener: listener)
end
Expand Down
4 changes: 3 additions & 1 deletion rb/lib/selenium/webdriver/safari/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Safari
class Driver < WebDriver::Driver
include DriverExtensions::HasDebugger
include DriverExtensions::HasPermissions
include DriverExtensions::HasWebStorage
include DriverExtensions::TakesScreenshot

def initialize(opts = {})
Expand All @@ -38,10 +39,11 @@ def initialize(opts = {})

listener = opts.delete(:listener)
desired_capabilities = opts.delete(:desired_capabilities)
options = opts.delete(:options)

@bridge = Remote::Bridge.new(opts)
@bridge.extend Bridge
@bridge.create_session(desired_capabilities)
@bridge.create_session(desired_capabilities, options)

super(@bridge, listener: listener)
end
Expand Down
4 changes: 2 additions & 2 deletions rb/spec/integration/selenium/webdriver/action_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module WebDriver
expect(keylogger.text.strip).to match(/^(focus )?keydown keydown keypress keyup keydown keypress keyup keyup$/)
end

it 'can press and release modifier keys', expect: {browser: :edge} do
it 'can press and release modifier keys', except: {browser: %i[edge safari_preview]} do
driver.navigate.to url_for('javascriptPage.html')

event_input = driver.find_element(id: 'theworks')
Expand Down Expand Up @@ -102,7 +102,7 @@ module WebDriver
expect(input.attribute(:value)).to eq('abcd')
end

it 'can release pressed keys via release action' do
it 'can release pressed keys via release action', except: {browser: :safari_preview} do
driver.navigate.to url_for('javascriptPage.html')

event_input = driver.find_element(id: 'theworks')
Expand Down
17 changes: 0 additions & 17 deletions rb/spec/integration/selenium/webdriver/chrome/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@ module Chrome
describe Profile do
let(:profile) { Profile.new }

it 'can be manually verified without mocks', only: {driver: :chrome} do
# Example for command line in mac to create a new data directory
# /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/path/to/data
# directory = File.expand_path('../', __FILE__)
# profile = Profile.new(directory)
profile = Profile.new
profile['browser.show_home_button'] = true
file = File.expand_path('sample.crx', __dir__)
profile.add_extension(file)

create_driver!(profile: profile) do |driver|
driver.navigate.to url_for('xhtmlTest.html')
expect('verify manually - home button displayed') # rubocop:disable RSpec/ExpectActual,RSpec/VoidExpect
expect('verify manually - make page red extension properly installed') # rubocop:disable RSpec/ExpectActual,RSpec/VoidExpect
end
end

it 'adds an extension' do
ext_path = '/some/path.crx'

Expand Down
9 changes: 5 additions & 4 deletions rb/spec/integration/selenium/webdriver/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module WebDriver
describe Element do
it 'should click' do
driver.navigate.to url_for('formPage.html')
driver.find_element(id: 'imageButton').click
expect { driver.find_element(id: 'imageButton').click }.not_to raise_error
reset_driver!(1) if %i[safari safari_preview].include? GlobalTestEnv.browser
end

# Safari returns "click intercepted" error instead of "element click intercepted"
Expand All @@ -42,14 +43,14 @@ module WebDriver
it 'should submit' do
driver.navigate.to url_for('formPage.html')
wait_for_element(id: 'submitButton')
driver.find_element(id: 'submitButton').submit
expect { driver.find_element(id: 'submitButton').submit }.not_to raise_error
reset_driver!
end

it 'should send string keys' do
driver.navigate.to url_for('formPage.html')
wait_for_element(id: 'working')
driver.find_element(id: 'working').send_keys('foo', 'bar')
expect { driver.find_element(id: 'working').send_keys('foo', 'bar') }.not_to raise_error
end

it 'should send key presses' do
Expand Down Expand Up @@ -100,7 +101,7 @@ module WebDriver

it 'should clear' do
driver.navigate.to url_for('formPage.html')
driver.find_element(id: 'withText').clear
expect { driver.find_element(id: 'withText').clear }.not_to raise_error
end

it 'should get and set selected' do
Expand Down
44 changes: 0 additions & 44 deletions rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,6 @@ module WebDriver
expect(driver.capabilities.remote_session_id).to be_truthy
end
end

it 'takes a binary path as an argument', only: {driver: :firefox} do
skip "Set ENV['ALT_FIREFOX_BINARY'] to test this" unless ENV['ALT_FIREFOX_BINARY']

begin
path = Firefox::Binary.path
default_version = nil

create_driver! do |driver|
default_version = driver.capabilities.version
expect { driver.capabilities.browser_version }.not_to raise_exception
end

caps = Remote::Capabilities.firefox(firefox_options: {binary: ENV['ALT_FIREFOX_BINARY']})
create_driver!(desired_capabilities: caps) do |driver|
expect(driver.capabilities.version).not_to eql(default_version)
expect { driver.capabilities.browser_version }.not_to raise_exception
end
ensure
Firefox::Binary.path = path
end
end

it 'gives precedence to firefox options versus argument switch', only: {driver: :firefox} do
skip "Set ENV['ALT_FIREFOX_BINARY'] to test this" unless ENV['ALT_FIREFOX_BINARY']

begin
path = Firefox::Binary.path
default_version = nil

create_driver! do |driver|
default_version = driver.capabilities.version
expect { driver.capabilities.browser_version }.not_to raise_exception
end

caps = Remote::Capabilities.firefox(firefox_options: {binary: ENV['ALT_FIREFOX_BINARY']})
create_driver!(desired_capabilities: caps, driver_opts: {binary: path}) do |driver|
expect(driver.capabilities.version).not_to eql(default_version)
expect { driver.capabilities.browser_version }.not_to raise_exception
end
ensure
Firefox::Binary.path = path
end
end
end
end # WebDriver
end # Selenium
3 changes: 2 additions & 1 deletion rb/spec/integration/selenium/webdriver/manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
module Selenium
module WebDriver
describe Manager do
describe 'logs', except: {browser: %i[chrome edge edge_chrome firefox ie safari safari_preview]} do
describe 'logs', except: [{browser: %i[edge edge_chrome firefox ie safari safari_preview]},
{driver: :remote, browser: :chrome}] do
it 'can fetch remote log types', only: {driver: :remote} do
expect(driver.manage.logs.available_types).to include(:server, :browser, :driver)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ def remote_server?
end

def remote_server_jar
if ENV['DOWNLOAD_SERVER']
@remote_server_jar ||= "#{root.join('rb/selenium-server-standalone')}-#{Selenium::Server.latest}.jar"
@remote_server_jar = root.join("rb/#{Selenium::Server.download(:latest)}").to_s unless File.exist? @remote_server_jar
else
@remote_server_jar ||= root.join('buck-out/gen/java/server/src/org/openqa/grid/selenium/selenium.jar').to_s
end
@remote_server_jar
file_name = "selenium-server-standalone-#{Selenium::Server.latest}.jar"
locations = ["#{root}/#{file_name}", "#{root.join('rb/')}#{file_name}"]
@remote_server_jar = locations.find { |file| File.exist?(file) }
return @remote_server_jar if @remote_server_jar

Selenium::Server.download(:latest)
@remote_server_jar = locations.find { |file| File.exist?(file) }
end

def quit
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
module Selenium
module WebDriver
module DriverExtensions
describe HasWebStorage, only: {browser: %i[edge edge_chrome chrome ie firefox]} do
describe HasWebStorage, only: {browser: %i[edge edge_chrome chrome ie firefox safari]} do
shared_examples 'web storage' do
before do
driver.navigate.to url_for('clicks.html')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module WebDriver
end

# Doesn't switch to frame by id directly
it 'should switch to a frame directly', except: {browser: :safari} do
it 'should switch to a frame directly' do
driver.navigate.to url_for('iframes.html')
driver.switch_to.frame('iframe1')

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 @@ -30,7 +30,7 @@ module WebDriver

after { driver.manage.timeouts.implicit_wait = 0 }

it 'should implicitly wait for a single element', except: {browser: :safari_preview} do
it 'should implicitly wait for a single element' do
driver.manage.timeouts.implicit_wait = 6

driver.find_element(id: 'adder').click
Expand Down
5 changes: 3 additions & 2 deletions rb/spec/integration/selenium/webdriver/window_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ module WebDriver

# Edge: Not Yet - https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/
# https://github.com/mozilla/geckodriver/issues/1281
it 'can minimize the window', only: {window_manager: true, browser: %i[edge edge_chrome ie firefox safari safari_preview]},
exclude: {driver: :remote, browser: :firefox, platform: :linux} do
it 'can minimize the window', only: {window_manager: true},
exclude: [{driver: :remote, browser: :firefox, platform: :linux},
{driver: :remote, browser: :safari}] do
window.minimize
expect(driver.execute_script('return document.hidden;')).to be true
end
Expand Down
Loading

0 comments on commit 6bb1875

Please sign in to comment.