Skip to content

Instantly share code, notes, and snippets.

@Snarp
Created June 24, 2021 01:24
Show Gist options
  • Save Snarp/3fc3fc9ce66be546012687fd0db7cdb8 to your computer and use it in GitHub Desktop.
Save Snarp/3fc3fc9ce66be546012687fd0db7cdb8 to your computer and use it in GitHub Desktop.
Initialize a Microsoft Edge Watir/Selenium browser/driver on Ubuntu 18.04
# NOTE: The Edge version in use here is:
# `92.0.902.15 (Official build) beta (64-bit)`
gem 'selenium-webdriver', '=4.0.0.beta4'
require 'selenium-webdriver'
gem 'watir', '~> 6.19'
require 'watir'
# gem 'webdrivers', '~> 4.6' # Edge not supported on Linux as of latest release
# require 'webdrivers'
# Since `webdrivers` gem doesn't support Edge on Linux, define paths manually.
# Executable path can be found by opening Edge normally, going to
# `edge://version/`, and looking under `Executable path:`
# @edge_browser_path='/opt/microsoft/msedge-beta/microsoft-edge-beta'
# # ...or you can use one of these shims? Smarter?:
# @edge_browser_path='/usr/bin/microsoft-edge-beta'
@edge_browser_path='/usr/bin/microsoft-edge'
# Have to manually download correct version of msedgedriver for installed
# version of Edge from:
#
# <https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/>
@edge_driver_path=File.join(Dir.home,'.webdrivers','msedgedriver')
# REVIEW: This works, but doesn't open the default user profile...
# Profile path can be found by opening Edge normally, going to
# `edge://version/`, and looking under `Profile path:` (directly below
# `Executable path:`)
@edge_profile_path=File.join(Dir.home,'.config','microsoft-edge-beta','Default')
# ...and okay, as of the current version of Selenium
# (`selenium-webdriver 4.0.0.beta4`), there does not appear to be
# any supported method of actually loading the profile - the `Edge::Profile`
# class is still empty:
#
# <https://github.com/SeleniumHQ/selenium/blob/trunk/rb/lib/selenium/webdriver/edge/profile.rb>
#
# So, never mind!
def init_browser
if @edge_driver_path
Selenium::WebDriver::Edge::Service.driver_path = @edge_driver_path
end
if @edge_browser_path
Selenium::WebDriver::Edge.path = @edge_browser_path
end
@driver = Selenium::WebDriver.for(:edge)
@browser = Watir::Browser.new(@driver)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment