Skip to content

Commit

Permalink
Add Chrome based Edge to the Ruby bindings (#7257)
Browse files Browse the repository at this point in the history
* Add Chrome based Edge to the Ruby bindings
  • Loading branch information
twalpole authored Jun 10, 2019
1 parent 49dc495 commit 7a72023
Show file tree
Hide file tree
Showing 26 changed files with 497 additions and 30 deletions.
23 changes: 20 additions & 3 deletions rb/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ruby_test(name = "chrome",

ruby_library(name = "edge",
srcs = [
"lib/selenium/webdriver/edge/**/*.rb",
"lib/selenium/webdriver/edge_html/**/*.rb",
"lib/selenium/webdriver/edge.rb"
],
deps = [":common"]
Expand All @@ -82,12 +82,29 @@ ruby_library(name = "edge",
ruby_test(name = "edge",
srcs = [
"spec/integration/selenium/webdriver/*_spec.rb",
"spec/integration/selenium/webdriver/edge/**/*_spec.rb"
"spec/integration/selenium/webdriver/edge_html/**/*_spec.rb"
],
include = ["rb/spec/integration", "build/rb/lib"],
deps = [ ":edge" ]
)

ruby_library(name = "edge-chrome",
srcs = [
"lib/selenium/webdriver/edge_chrome/**/*.rb",
"lib/selenium/webdriver/edge.rb"
],
deps = [":common"]
)

ruby_test(name = "edge-chrome",
srcs = [
"spec/integration/selenium/webdriver/*_spec.rb",
"spec/integration/selenium/webdriver/edge_chrome/**/*_spec.rb"
],
include = ["rb/spec/integration", "build/rb/lib"],
deps = [ ":edge-chrome", ":chrome"]
)

ruby_library(name = "firefox",
srcs = [
"lib/selenium/webdriver/firefox/**/*.rb",
Expand Down Expand Up @@ -212,7 +229,7 @@ ruby_test(name = "remote-ie",
ruby_test(name = "remote-edge",
srcs = [
"spec/integration/selenium/webdriver/*_spec.rb",
"spec/integration/selenium/webdriver/edge/**/*_spec.rb",
"spec/integration/selenium/webdriver/edge_html/**/*_spec.rb",
"spec/integration/selenium/webdriver/remote/**/*_spec.rb"
],
include = ["rb/spec/integration", "build/rb/lib"],
Expand Down
16 changes: 9 additions & 7 deletions rb/lib/selenium/webdriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ module WebDriver
Rectangle = Struct.new(:x, :y, :width, :height)
Location = Struct.new(:latitude, :longitude, :altitude)

autoload :Chrome, 'selenium/webdriver/chrome'
autoload :Edge, 'selenium/webdriver/edge'
autoload :Firefox, 'selenium/webdriver/firefox'
autoload :IE, 'selenium/webdriver/ie'
autoload :Remote, 'selenium/webdriver/remote'
autoload :Safari, 'selenium/webdriver/safari'
autoload :Support, 'selenium/webdriver/support'
autoload :Chrome, 'selenium/webdriver/chrome'
autoload :Edge, 'selenium/webdriver/edge'
autoload :EdgeHtml, 'selenium/webdriver/edge'
autoload :EdgeChrome, 'selenium/webdriver/edge'
autoload :Firefox, 'selenium/webdriver/firefox'
autoload :IE, 'selenium/webdriver/ie'
autoload :Remote, 'selenium/webdriver/remote'
autoload :Safari, 'selenium/webdriver/safari'
autoload :Support, 'selenium/webdriver/support'

# @api private

Expand Down
4 changes: 4 additions & 0 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def for(browser, opts = {})
Firefox::Driver.new(opts)
when :edge
Edge::Driver.new(opts)
when :edge_chrome
EdgeChrome::Driver.new(opts)
when :edge_html
EdgeHtml::Driver.new(opts)
when :remote
Remote::Driver.new(opts)
else
Expand Down
8 changes: 8 additions & 0 deletions rb/lib/selenium/webdriver/common/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def edge(**opts)
Edge::Service.new(**opts)
end

def edge_chrome(**opts)
EdgeChrome::Service.new(**opts)
end

def edge_html(**opts)
EdgeHtml::Service.new(**opts)
end

def safari(**opts)
Safari::Service.new(**opts)
end
Expand Down
28 changes: 23 additions & 5 deletions rb/lib/selenium/webdriver/edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

require 'net/http'

require 'selenium/webdriver/edge/driver'
require 'selenium/webdriver/edge/options'
require 'selenium/webdriver/edge_html/driver'
require 'selenium/webdriver/edge_html/options'
require 'selenium/webdriver/edge_chrome/bridge'
require 'selenium/webdriver/edge_chrome/driver'
require 'selenium/webdriver/edge_chrome/profile'
require 'selenium/webdriver/edge_chrome/options'

module Selenium
module WebDriver
module Edge
module EdgeHtml
def self.driver_path=(path)
WebDriver.logger.deprecate 'Selenium::WebDriver::Edge#driver_path=',
'Selenium::WebDriver::Edge::Service#driver_path='
Expand All @@ -36,8 +40,22 @@ def self.driver_path
'Selenium::WebDriver::Edge::Service#driver_path'
Selenium::WebDriver::Edge::Service.driver_path
end
end # Edge
end # EdgeHtml

module EdgeChrome
def self.path=(path)
Platform.assert_executable path
@path = path
end

def self.path
@path ||= nil
end
end # EdgeChrome

Edge = EdgeHtml # Alias EdgeHtml as Edge for now
end # WebDriver
end # Selenium

require 'selenium/webdriver/edge/service'
require 'selenium/webdriver/edge_html/service'
require 'selenium/webdriver/edge_chrome/service'
30 changes: 30 additions & 0 deletions rb/lib/selenium/webdriver/edge_chrome/bridge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

# 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 'selenium/webdriver/chrome/bridge'

module Selenium
module WebDriver
module EdgeChrome
module Bridge
include Selenium::WebDriver::Chrome::Bridge
end # Bridge
end # EdgeChrome
end # WebDriver
end # Selenium
46 changes: 46 additions & 0 deletions rb/lib/selenium/webdriver/edge_chrome/driver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

# 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 'selenium/webdriver/chrome/driver'

module Selenium
module WebDriver
module EdgeChrome

#
# Driver implementation for EdgeChrome.
# @api private
#

class Driver < Selenium::WebDriver::Chrome::Driver
def browser
:edge_chrome
end

private

def create_capabilities(opts)
opts[:desired_capabilities] ||= Remote::Capabilities.edge_chrome
opts[:options] ||= Options.new
super(opts)
end
end # Driver
end # Chrome
end # WebDriver
end # Selenium
50 changes: 50 additions & 0 deletions rb/lib/selenium/webdriver/edge_chrome/options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

# 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 'selenium/webdriver/chrome/options'

module Selenium
module WebDriver
module EdgeChrome
class Options < Selenium::WebDriver::Chrome::Options
#
# Create a new Options instance.
#
# @example
# options = Selenium::WebDriver::EdgeChrome::Options.new(args: ['start-maximized', 'user-data-dir=/tmp/temp_profile'])
# driver = Selenium::WebDriver.for(:edge_chrome, options: options)
#
# @param [Hash] opts the pre-defined options to create the Chrome::Options with
# @option opts [Array<String>] :args List of command-line arguments to use when starting Chrome
# @option opts [String] :binary Path to the Chrome executable to use
# @option opts [Hash] :prefs A hash with each entry consisting of the name of the preference and its value
# @option opts [Array<String>] :extensions A list of paths to (.crx) Chrome extensions to install on startup
# @option opts [Hash] :options A hash for raw options
# @option opts [Hash] :emulation A hash for raw emulation options
#

def initialize(**opts)
opts[:binary] ||= EdgeChrome.path
super(**opts)
end

end # Options
end # EdgeChrome
end # WebDriver
end # Selenium
33 changes: 33 additions & 0 deletions rb/lib/selenium/webdriver/edge_chrome/profile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

# 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 'selenium/webdriver/chrome/profile'

module Selenium
module WebDriver
module EdgeChrome
#
# @private
#

class Profile < Selenium::WebDriver::Chrome::Profile
end # Profile
end # EdgeChrome
end # WebDriver
end # Selenium
40 changes: 40 additions & 0 deletions rb/lib/selenium/webdriver/edge_chrome/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

# 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 'selenium/webdriver/chrome/service'

module Selenium
module WebDriver
module EdgeChrome
#
# @api private
#

class Service < Selenium::WebDriver::Chrome::Service
DEFAULT_PORT = 9515
EXECUTABLE = 'msedgedriver'
MISSING_TEXT = <<~ERROR
Unable to find msedgedriver. Please download the server from
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ and place it somewhere on your PATH.
ERROR
SHUTDOWN_SUPPORTED = true
end # Service
end # EdgeChrome
end # WebDriver
end # Selenium
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

module Selenium
module WebDriver
module Edge
module EdgeHtml

#
# Driver implementation for Microsoft Edge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

module Selenium
module WebDriver
module Edge
module EdgeHtml
class Options
attr_accessor :in_private, :start_page
attr_reader :extension_paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

module Selenium
module WebDriver
module Edge
module EdgeHtml
#
# @api private
#
Expand Down
10 changes: 10 additions & 0 deletions rb/lib/selenium/webdriver/remote/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,22 @@ def chrome(opts = {})
end

def edge(opts = {})
edge_html(opts)
end

def edge_html(opts = {})
new({
browser_name: 'MicrosoftEdge',
platform_name: :windows
}.merge(opts))
end

def edge_chrome(opts = {})
new({
browser_name: 'MicrosoftEdge'
}.merge(opts))
end

def firefox(opts = {})
opts[:browser_version] = opts.delete(:version) if opts.key?(:version)
opts[:platform_name] = opts.delete(:platform) if opts.key?(:platform)
Expand Down
Loading

0 comments on commit 7a72023

Please sign in to comment.