Skip to content

Commit

Permalink
Use W3C version of Edge (version 18)
Browse files Browse the repository at this point in the history
This commit updates implementation of Edge browser via MicrosoftWebDriver
to the recent stable version which uses W3C mode by default.
This renders unnecessary a custom bridge implementation which mixed
OSS and W3C dialects. The new version is tested on Edge version 18,
though we might need to change it when a new Chromium-based version
will be released.
  • Loading branch information
p0deje committed Apr 28, 2019
1 parent 87efe1b commit 8fe0635
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 109 deletions.
1 change: 0 additions & 1 deletion rb/lib/selenium/webdriver/edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

require 'net/http'

require 'selenium/webdriver/edge/bridge'
require 'selenium/webdriver/edge/driver'
require 'selenium/webdriver/edge/options'

Expand Down
76 changes: 0 additions & 76 deletions rb/lib/selenium/webdriver/edge/bridge.rb

This file was deleted.

17 changes: 12 additions & 5 deletions rb/lib/selenium/webdriver/edge/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ module Edge
#

class Driver < WebDriver::Driver
include DriverExtensions::HasWebStorage
include DriverExtensions::TakesScreenshot

def initialize(opts = {})
opts[:desired_capabilities] ||= Remote::Capabilities.edge
opts[:desired_capabilities] = create_capabilities(opts)

opts[:url] ||= service_url(opts)

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

# Edge is mostly using W3C dialect, but a request to
# create session responds with OSS-like body,
# so we need to force W3C implementation.
@bridge = Remote::Bridge.new(opts)
@bridge.create_session(desired_capabilities)
@bridge.extend Edge::Bridge

super(@bridge, listener: listener)
end
Expand All @@ -57,6 +54,16 @@ def quit
@service&.stop
end

private

def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.edge }
options = opts.delete(:options) { Options.new }
options = options.as_json
caps.merge!(options) unless options.empty?

caps
end
end # Driver
end # Edge
end # WebDriver
Expand Down
7 changes: 3 additions & 4 deletions rb/lib/selenium/webdriver/edge/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ class Service < WebDriver::Service
DEFAULT_PORT = 17556
EXECUTABLE = 'MicrosoftWebDriver'
MISSING_TEXT = <<~ERROR
Unable to find MicrosoftWebDriver. Please download the server from
https://www.microsoft.com/en-us/download/details.aspx?id=48212 and place it somewhere on your PATH.
More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver.
Unable to find MicrosoftWebDriver. Please install it following instructions
at https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/.
ERROR
SHUTDOWN_SUPPORTED = true
SHUTDOWN_SUPPORTED = false

private

Expand Down
16 changes: 5 additions & 11 deletions rb/spec/integration/selenium/webdriver/action_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@

module Selenium
module WebDriver
describe ActionBuilder, except: {browser: :edge} do
after do
if driver.action.respond_to?(:clear_all_actions)
driver.action.clear_all_actions
else
driver.action.instance_variable_set(:@actions, [])
end
end
describe ActionBuilder do
after { driver.action.clear_all_actions }

describe 'Key actions' do
it 'sends keys to the active element', except: {browser: %i[safari safari_preview]} do
Expand All @@ -44,7 +38,7 @@ module WebDriver
expect(driver.find_element(id: 'result').text.strip).to be_empty
end

it 'can send keys with shift pressed', except: {browser: %i[safari safari_preview]} do
it 'can send keys with shift pressed', except: {browser: %i[edge safari safari_preview]} do
driver.navigate.to url_for('javascriptPage.html')

event_input = driver.find_element(id: 'theworks')
Expand All @@ -59,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' do
it 'can press and release modifier keys', expect: {browser: :edge} do
driver.navigate.to url_for('javascriptPage.html')

event_input = driver.find_element(id: 'theworks')
Expand Down Expand Up @@ -165,7 +159,7 @@ module WebDriver
expect(element.attribute(:value)).to eq('ContextClicked')
end

it 'can release pressed buttons via release action', except: {browser: :safari}, only: {browser: %i[firefox ie]} do
it 'can release pressed buttons via release action', except: {browser: :safari}, only: {browser: %i[edge firefox ie]} do
driver.navigate.to url_for('javascriptPage.html')

event_input = driver.find_element(id: 'clickField')
Expand Down
6 changes: 3 additions & 3 deletions rb/spec/integration/selenium/webdriver/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module WebDriver
expect(key_reporter.attribute('value')).to eq('Hello')
end

it 'should handle file uploads', except: {browser: %i[safari edge safari_preview]} do
it 'should handle file uploads', except: {browser: %i[safari safari_preview]} do
driver.navigate.to url_for('formPage.html')

element = driver.find_element(id: 'upload')
Expand All @@ -101,7 +101,7 @@ module WebDriver
expect(driver.find_element(id: 'withText').attribute('nonexistent')).to be_nil
end

it 'should get property value', except: {browser: :edge} do
it 'should get property value' do
driver.navigate.to url_for('formPage.html')
expect(driver.find_element(id: 'withText').property('nodeName')).to eq('TEXTAREA')
end
Expand Down Expand Up @@ -180,7 +180,7 @@ module WebDriver
end

# IE - https://github.com/SeleniumHQ/selenium/pull/4043
it 'should drag and drop', except: {browser: %i[edge ie]} do
it 'should drag and drop', except: {browser: :ie} do
driver.navigate.to url_for('dragAndDropTest.html')

img1 = driver.find_element(id: 'test1')
Expand Down
2 changes: 1 addition & 1 deletion rb/spec/integration/selenium/webdriver/manage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
module Selenium
module WebDriver
describe Manager do
describe 'logs', except: {browser: %i[chrome firefox ie safari safari_preview]} do
describe 'logs', except: {browser: %i[chrome edge firefox ie safari safari_preview]} 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 @@ -18,8 +18,6 @@
# under the License.

shared_examples_for 'driver that can be started concurrently' do |guard|
before { quit_driver }

after do
drivers.each(&:quit)
threads.select(&:alive?).each(&:kill)
Expand All @@ -30,9 +28,11 @@

it 'starts 3 drivers sequentially', guard do
3.times do
threads << Thread.new do
thread = Thread.new do
drivers << create_driver!
end
thread.report_on_exception = false
threads << thread
end

expect { threads.each(&:join) }.not_to raise_error
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[chrome ie firefox]} do
describe HasWebStorage, only: {browser: %i[edge chrome ie firefox]} do
shared_examples 'web storage' do
before do
driver.navigate.to url_for('clicks.html')
Expand Down
4 changes: 2 additions & 2 deletions 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: %i[edge safari_preview]} do
it 'should implicitly wait for a single element', except: {browser: :safari_preview} do
driver.manage.timeouts.implicit_wait = 6

driver.find_element(id: 'adder').click
Expand All @@ -49,7 +49,7 @@ module WebDriver
expect { driver.find_element(id: 'box0') }.to raise_error(WebDriver::Error::NoSuchElementError)
end

it 'should implicitly wait until at least one element is found when searching for many', except: {browser: :edge} do
it 'should implicitly wait until at least one element is found when searching for many' do
add = driver.find_element(id: 'adder')

driver.manage.timeouts.implicit_wait = 6
Expand Down
4 changes: 2 additions & 2 deletions rb/spec/integration/selenium/webdriver/window_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module WebDriver
expect(new_pos.y).to eq(target_y)
end

it 'gets the rect of the current window', only: {browser: %i[firefox ie chrome safari safari_preview]} do
it 'gets the rect of the current window', only: {browser: %i[edge firefox ie chrome safari safari_preview]} do
rect = window.rect

expect(rect).to be_a(Rectangle)
Expand Down Expand Up @@ -132,7 +132,7 @@ 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[ie firefox safari safari_preview]},
it 'can minimize the window', only: {window_manager: true, browser: %i[edge ie firefox safari safari_preview]},
exclude: {driver: :remote, browser: :firefox, platform: :linux} do
window.minimize
expect(driver.execute_script('return document.hidden;')).to be true
Expand Down

0 comments on commit 8fe0635

Please sign in to comment.