Skip to content

Commit

Permalink
rename Edge classes to support Selenium 4 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Feb 26, 2021
1 parent 6eb6027 commit 850e910
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.edge
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in webdrivers.gemspec
gemspec path: '..'
gem 'selenium-webdriver', github: 'seleniumhq/selenium', branch: 'trunk', glob: 'rb/*.gemspec'
gem 'selenium-webdriver', '>= 4.0.0.beta1'
12 changes: 6 additions & 6 deletions lib/webdrivers/edge_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def location
private

def user_defined_location
if Selenium::WebDriver::EdgeChrome.path
Webdrivers.logger.debug "Selenium::WebDriver::EdgeChrome.path: #{Selenium::WebDriver::EdgeChrome.path}"
return Selenium::WebDriver::EdgeChrome.path
if Selenium::WebDriver::Edge.path
Webdrivers.logger.debug "Selenium::WebDriver::Edge.path: #{Selenium::WebDriver::Edge.path}"
return Selenium::WebDriver::Edge.path
end

return if ENV['WD_EDGE_CHROME_PATH'].nil?
return if ENV['WD_EDGE_PATH'].nil?

Webdrivers.logger.debug "WD_EDGE_CHROME_PATH: #{ENV['WD_EDGE_CHROME_PATH']}"
ENV['WD_EDGE_CHROME_PATH']
Webdrivers.logger.debug "WD_EDGE_PATH: #{ENV['WD_EDGE_PATH']}"
ENV['WD_EDGE_PATH']
end

def win_location
Expand Down
17 changes: 1 addition & 16 deletions lib/webdrivers/edgedriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,4 @@ def download_url
end
end

if defined? Selenium::WebDriver::EdgeChrome
if ::Selenium::WebDriver::Service.respond_to? :driver_path=
::Selenium::WebDriver::EdgeChrome::Service.driver_path = proc { ::Webdrivers::Edgedriver.update }
else
# v3.141.0 and lower
module Selenium
module WebDriver
module EdgeChrome
def self.driver_path
@driver_path ||= Webdrivers::Edgedriver.update
end
end
end
end
end
end
::Selenium::WebDriver::Edge::Service.driver_path = proc { ::Webdrivers::Edgedriver.update }
20 changes: 9 additions & 11 deletions spec/webdrivers/edge_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
let(:edge_finder) { described_class }

before(:all) do # rubocop:disable RSpec/BeforeAfterAll
# Skip these tests if version of selenium-webdriver being tested with doesn't
# have Chromium based Edge support
unless defined?(Selenium::WebDriver::EdgeChrome)
if Selenium::WebDriver::VERSION[0].to_i < 4
skip "The current selenium-webdriver doesn't include Chromium based Edge support"
end
end
Expand All @@ -20,29 +18,29 @@
end

context 'when the user provides a path to the Edge binary' do
it 'uses Selenium::WebDriver::EdgeChrome.path when it is defined' do
Selenium::WebDriver::EdgeChrome.path = edge_finder.location
it 'uses Selenium::WebDriver::Edge.path when it is defined' do
Selenium::WebDriver::Edge.path = edge_finder.location
locations = %i[win_location mac_location linux_location]
allow(edge_finder).to receive_messages(locations)

expect(edge_finder.version).not_to be_nil
locations.each { |loc| expect(edge_finder).not_to have_received(loc) }
end

it "uses ENV['WD_EDGE_CHROME_PATH'] when it is defined" do
allow(ENV).to receive(:[]).with('WD_EDGE_CHROME_PATH').and_return(edge_finder.location)
it "uses ENV['WD_EDGE_PATH'] when it is defined" do
allow(ENV).to receive(:[]).with('WD_EDGE_PATH').and_return(edge_finder.location)
locations = %i[win_location mac_location linux_location]
allow(edge_finder).to receive_messages(locations)

expect(edge_finder.version).not_to be_nil
locations.each { |loc| expect(edge_finder).not_to have_received(loc) }
end

it 'uses Selenium::WebDriver::EdgeChrome.path over WD_EDGE_CHROME_PATH' do
Selenium::WebDriver::EdgeChrome.path = edge_finder.location
allow(ENV).to receive(:[]).with('WD_EDGE_CHROME_PATH').and_return('my_wd_chrome_path')
it 'uses Selenium::WebDriver::Edge.path over WD_EDGE_PATH' do
Selenium::WebDriver::Edge.path = edge_finder.location
allow(ENV).to receive(:[]).with('WD_EDGE_PATH').and_return('my_wd_chrome_path')
expect(edge_finder.version).not_to be_nil
expect(ENV).not_to have_received(:[]).with('WD_EDGE_CHROME_PATH')
expect(ENV).not_to have_received(:[]).with('WD_EDGE_PATH')
end
end

Expand Down
4 changes: 1 addition & 3 deletions spec/webdrivers/edgedriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
let(:edgedriver) { described_class }

before(:all) do # rubocop:disable RSpec/BeforeAfterAll
# Skip these tests if version of selenium-webdriver being tested with doesn't
# have Chromium based Edge support
unless defined?(Selenium::WebDriver::EdgeChrome)
if Selenium::WebDriver::VERSION[0].to_i < 4
skip "The current selenium-webdriver doesn't include Chromium based Edge support"
end
end
Expand Down

0 comments on commit 850e910

Please sign in to comment.