Skip to content

Commit 645d318

Browse files
committed
rb - better implementation for how to use Marionette with Wires
1 parent f9cc42d commit 645d318

File tree

4 files changed

+79
-29
lines changed

4 files changed

+79
-29
lines changed

rb/lib/selenium/webdriver/common/driver.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ def for(browser, opts = {})
5252
else
5353
Firefox::Bridge.new(opts)
5454
end
55-
when :firefox_nightly
56-
Firefox::Binary.nightly_path
57-
Firefox::W3CBridge.new(opts)
5855
when :remote
5956
Remote::Bridge.new(opts)
6057
when :ie, :internet_explorer

rb/lib/selenium/webdriver/firefox/binary.rb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,8 @@ def path
149149
@path
150150
end
151151

152-
def nightly_path
153-
@path = case Platform.os
154-
when :macosx
155-
"/Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin"
156-
when :windows
157-
"#{Platform.find_in_program_files("\\Nightly\\firefox.exe").gsub('m Files (x86)', '~2')}"
158-
when :linux
159-
ENV['FIREFOX_NIGHTLY_PATH'] or raise Error::WebDriverError, "Set ENV['FIREFOX_NIGHTLY_PATH'] when using Firefox Nightly on Linux"
160-
end
161-
162-
unless File.file?(@path.to_s) && version > 43
163-
raise Error::WebDriverError, "Could not find Firefox Nightly binary. Make sure Firefox Nightly is installed or set the path manually with #{self}.path="
164-
end
165-
166-
@path
167-
end
168-
169152
def version
170-
@version ||= case Platform.os
153+
@version = case Platform.os
171154
when :macosx
172155
`#{path} -v`.strip[/[^\s]*$/][/^\d+/].to_i
173156
when :windows

rb/lib/selenium/webdriver/remote/w3c_capabilities.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,13 @@ def firefox(opts = {})
6969
}.merge(opts))
7070
end
7171

72-
def w3c?(opts = {})
73-
return true if opts[:browser_name] == :firefox_nightly
74-
w3c_opts? || Firefox::Binary.version > 43
75-
end
72+
alias_method :ff, :firefox
7673

77-
def w3c_opts?(opts = {})
78-
intersect = Remote::W3CCapabilities::DEFAULTS.keys & opts.keys
79-
common = [:takes_screenshot, :proxy]
80-
!(intersect - common).empty?
74+
def w3c?(opts = {})
75+
return false unless opts[:desired_capabilities].is_a?(W3CCapabilities) || opts.delete(:wires)
76+
firefox_version = Firefox::Binary.version
77+
raise ArgumentError, "Firefox Version #{firefox_version} does not support W3CCapabilities" if firefox_version < 43
78+
true
8179
end
8280

8381
#
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# encoding: utf-8
2+
#
3+
# Licensed to the Software Freedom Conservancy (SFC) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The SFC licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
require 'selenium-webdriver'
21+
22+
module Selenium
23+
module WebDriver
24+
25+
describe Firefox do
26+
27+
context "when designated firefox installation includes Marionette" do
28+
before(:all) { Firefox::Binary.path = "/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin" }
29+
after { @driver.quit }
30+
31+
# Currently versions that support Wires do not support Legacy Firefox Extension
32+
xit "Does not use wires by default" do
33+
@driver = Selenium::WebDriver.for :firefox
34+
expect(@driver.instance_variable_get('@bridge').instance_variable_get('@launcher')).to_not be_nil
35+
end
36+
37+
it "Uses Wires when initialized with :desired_capabilities" do
38+
caps = Selenium::WebDriver::Remote::W3CCapabilities.firefox
39+
expect { @driver = Selenium::WebDriver.for :firefox, :desired_capabilities => caps }.to_not raise_exception
40+
end
41+
42+
it "Uses Wires when initialized with wires option" do
43+
@driver = Selenium::WebDriver.for :firefox, {wires: true}
44+
expect(@driver.instance_variable_get('@bridge').instance_variable_get('@launcher')).to be_nil
45+
end
46+
end
47+
48+
context "when designated firefox installation does not include Marionette" do
49+
before(:all) { Firefox::Binary.path = "/Applications/Firefox.app/Contents/MacOS/firefox-bin" }
50+
let(:message) { /Firefox Version \d\d does not support W3CCapabilities/ }
51+
52+
it "Does not use Wires by default" do
53+
driver = Selenium::WebDriver.for :firefox
54+
expect(driver.instance_variable_get('@bridge').instance_variable_get('@launcher')).to_not be_nil
55+
driver.quit
56+
end
57+
58+
it "Raises Wires Exception when initialized with :desired_capabilities" do
59+
caps = Selenium::WebDriver::Remote::W3CCapabilities.firefox
60+
opt = {:desired_capabilities => caps}
61+
expect { @driver = Selenium::WebDriver.for :firefox, opt }.to raise_exception ArgumentError, message
62+
end
63+
64+
it "Raises Wires Exception when initialized with wires option" do
65+
expect{@driver = Selenium::WebDriver.for :firefox, {wires: true}}.to raise_exception ArgumentError, message
66+
end
67+
end
68+
69+
70+
end # Driver
71+
end # WebDriver
72+
end # Selenium

0 commit comments

Comments
 (0)