-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rb: Initial attempt at supporting Microsoft Edge
- Loading branch information
1 parent
e37ad82
commit 24e20e0
Showing
11 changed files
with
312 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# 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 'net/http' | ||
|
||
require 'selenium/webdriver/edge/service' | ||
require 'selenium/webdriver/edge/bridge' | ||
|
||
module Selenium | ||
module WebDriver | ||
|
||
module Edge | ||
def self.driver_path=(path) | ||
Service.executable_path = path | ||
end | ||
|
||
def self.path=(path) | ||
Platform.assert_executable path | ||
@path = path | ||
end | ||
|
||
def self.path | ||
@path ||= nil | ||
end | ||
|
||
end # Edge | ||
end # WebDriver | ||
end # Selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# 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. | ||
|
||
module Selenium | ||
module WebDriver | ||
module Edge | ||
|
||
# @api private | ||
class Bridge < Remote::Bridge | ||
|
||
def initialize(opts = {}) | ||
http_client = opts.delete(:http_client) | ||
|
||
if opts.has_key?(:url) | ||
url = opts.delete(:url) | ||
else | ||
@service = Service.default_service(*extract_service_args(opts)) | ||
@service.start | ||
|
||
url = @service.uri | ||
end | ||
|
||
caps = create_capabilities(opts) | ||
|
||
remote_opts = { | ||
:url => url, | ||
:desired_capabilities => caps | ||
} | ||
|
||
remote_opts.merge!(:http_client => http_client) if http_client | ||
|
||
super(remote_opts) | ||
end | ||
|
||
def browser | ||
:edge | ||
end | ||
|
||
def driver_extensions | ||
[ | ||
DriverExtensions::TakesScreenshot, | ||
DriverExtensions::HasInputDevices | ||
] | ||
end | ||
|
||
def capabilities | ||
@capabilities ||= Remote::Capabilities.edge | ||
end | ||
|
||
def quit | ||
super | ||
ensure | ||
@service.stop if @service | ||
end | ||
|
||
private | ||
|
||
def create_capabilities(opts) | ||
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.edge } | ||
page_load_strategy = opts.delete(:page_load_strategy) || "normal" | ||
|
||
unless opts.empty? | ||
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}" | ||
end | ||
|
||
edge_options = caps['edgeOptions'] || {} | ||
caps['edgeOptions'] = edge_options | ||
caps['page_load_strategy'] = page_load_strategy | ||
|
||
caps | ||
end | ||
|
||
def extract_service_args(opts) | ||
args = [] | ||
|
||
if opts.has_key?(:service_log_path) | ||
args << "--log-path=#{opts.delete(:service_log_path)}" | ||
end | ||
|
||
args | ||
end | ||
|
||
end # Bridge | ||
end # Edge | ||
end # WebDriver | ||
end # Selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# 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. | ||
|
||
module Selenium | ||
module WebDriver | ||
module Edge | ||
|
||
# | ||
# @api private | ||
# | ||
class Service | ||
START_TIMEOUT = 20 | ||
SOCKET_LOCK_TIMEOUT = 45 | ||
STOP_TIMEOUT = 5 | ||
DEFAULT_PORT = 17556 | ||
MISSING_TEXT = "Unable to find MicrosoftWebDriver. Please download the server from https://www.microsoft.com/en-us/download/details.aspx?id=48212. More info at https://github.com/SeleniumHQ/selenium/wiki/MicrosoftWebDriver." | ||
|
||
def self.executable_path | ||
@executable_path ||= ( | ||
path = Platform.find_binary "MicrosoftWebDriver" | ||
path or raise Error::WebDriverError, MISSING_TEXT | ||
Platform.assert_executable path | ||
|
||
path | ||
) | ||
end | ||
|
||
def self.executable_path=(path) | ||
Platform.assert_executable path | ||
@executable_path = path | ||
end | ||
|
||
def self.default_service(*extra_args) | ||
new executable_path, DEFAULT_PORT, *extra_args | ||
end | ||
|
||
def initialize(executable_path, port, *extra_args) | ||
@executable_path = executable_path | ||
@host = Platform.localhost | ||
@port = Integer(port) | ||
|
||
raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1 | ||
|
||
@extra_args = extra_args | ||
end | ||
|
||
def start | ||
Platform.exit_hook { stop } # make sure we don't leave the server running | ||
|
||
socket_lock.locked do | ||
find_free_port | ||
start_process | ||
connect_until_stable | ||
end | ||
end | ||
|
||
def stop | ||
return if @process.nil? || @process.exited? | ||
|
||
Net::HTTP.start(@host, @port) do |http| | ||
http.open_timeout = STOP_TIMEOUT / 2 | ||
http.read_timeout = STOP_TIMEOUT / 2 | ||
|
||
http.head("/shutdown") | ||
end | ||
|
||
@process.poll_for_exit STOP_TIMEOUT | ||
rescue ChildProcess::TimeoutError | ||
# ok, force quit | ||
@process.stop STOP_TIMEOUT | ||
end | ||
|
||
def uri | ||
URI.parse "http://#{@host}:#{@port}" | ||
end | ||
|
||
def find_free_port | ||
@port = PortProber.above @port | ||
end | ||
|
||
def start_process | ||
server_command = [@executable_path, "--port=#{@port}", *@extra_args] | ||
@process = ChildProcess.build(*server_command) | ||
|
||
@process.io.inherit! if $DEBUG == true | ||
@process.start | ||
end | ||
|
||
def connect_until_stable | ||
@socket_poller = SocketPoller.new @host, @port, START_TIMEOUT | ||
|
||
unless @socket_poller.connected? | ||
raise Error::WebDriverError, "unable to connect to MicrosoftWebDriver #{@host}:#{@port}" | ||
end | ||
end | ||
|
||
def socket_lock | ||
@socket_lock ||= SocketLock.new(@port - 1, SOCKET_LOCK_TIMEOUT) | ||
end | ||
|
||
end # Service | ||
end # Edge | ||
end # WebDriver | ||
end # Service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.