forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Safari::Options + add support for custom extensions.
This fixes issue 6815.
- Loading branch information
Showing
9 changed files
with
211 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module Selenium | ||
module WebDriver | ||
module Safari | ||
class Options | ||
attr_accessor :port, :data_dir, :skip_extension_installation | ||
attr_reader :extensions | ||
|
||
def initialize(opts = {}) | ||
@extensions = [] | ||
extract_options(opts) | ||
end | ||
|
||
def add_extension(ext) | ||
@extensions << verify_safari_extension(ext) | ||
end | ||
|
||
def clean_session? | ||
!!@clean_session | ||
end | ||
|
||
def skip_extension_installation? | ||
!!@skip_extension_installation | ||
end | ||
|
||
def to_capabilities | ||
caps = Remote::Capabilities.safari | ||
caps.merge!('safari.options' => as_json) | ||
|
||
caps | ||
end | ||
|
||
def as_json | ||
{ | ||
'port' => port, | ||
'dataDir' => data_dir, | ||
'cleanSession' => clean_session?, | ||
'extensions' => extensions_as_json, | ||
'skipExtensionInstallation' => skip_extension_installation? | ||
} | ||
end | ||
|
||
private | ||
|
||
def extensions_as_json | ||
@extensions.map do |path| | ||
{'filename' => path.basename, 'contents' => Base64.strict_encode64(path.read) } | ||
end | ||
end | ||
|
||
def extract_options(opts) | ||
@port = Integer(opts[:port] || PortProber.random) | ||
@data_dir = opts[:custom_data_dir] || opts[:data_dir] | ||
@clean_session = opts[:clean_session] | ||
|
||
Array(opts[:extensions]).each { |ext| add_extension(ext) } | ||
|
||
if opts.key?(:install_extension) | ||
@skip_extension_installation = !opts[:install_extension] | ||
elsif opts.key?(:skip_extension_installation) | ||
@skip_extension_installation = opts[:skip_extension_installation] | ||
else | ||
@skip_extension_installation = false | ||
end | ||
end | ||
|
||
def verify_safari_extension(path) | ||
pn = Pathname.new(path) | ||
|
||
unless pn.file? && pn.extname == '.safariextz' | ||
raise ArgumentError, "invalid Safari extension path: #{path}" | ||
end | ||
|
||
pn | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
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,13 @@ | ||
module Selenium | ||
module WebDriver | ||
module Safari | ||
class SessionData | ||
|
||
def self.for_platform | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
require File.expand_path("../spec_helper", __FILE__) | ||
require 'pry' | ||
|
||
module Selenium | ||
module WebDriver | ||
|
46 changes: 46 additions & 0 deletions
46
rb/spec/integration/selenium/webdriver/safari/custom_extension_spec.rb
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,46 @@ | ||
module Selenium | ||
module WebDriver | ||
module Safari | ||
|
||
describe 'with custom extension', focus: true do | ||
before { GlobalTestEnv.quit_driver } | ||
after { @driver.quit if @driver } | ||
|
||
let(:wait) { Wait.new(timeout: 2) } | ||
let(:extension_path) { } | ||
|
||
def create_driver(with_extension = false) | ||
extensions = [] | ||
|
||
if with_extension | ||
extensions << GlobalTestEnv.root.join('java/client/test/org/openqa/selenium/safari/setAttribute.safariextz').to_s | ||
end | ||
|
||
@driver = WebDriver.for :safari, extensions: extensions | ||
@driver.get url_for('blank.html') | ||
|
||
@driver | ||
end | ||
|
||
def custom_extension_installed?(driver) | ||
wait.until { driver.find_element(css: "html[istestsafariextzinstalled759='yes']") } | ||
true | ||
rescue Error::TimeOutError | ||
false | ||
end | ||
|
||
it 'should start without custom extension by default' do | ||
driver = create_driver | ||
custom_extension_installed?(driver).should be_false | ||
end | ||
|
||
it 'should start with custom extension if requested' do | ||
driver = create_driver(true) | ||
custom_extension_installed?(driver).should be_true | ||
end | ||
end | ||
|
||
end # Safari | ||
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
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