rainux-selenium-webdriver 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +204 -0
- data/chrome/prebuilt/Win32/Release/npchromedriver.dll +0 -0
- data/chrome/prebuilt/x64/Release/npchromedriver.dll +0 -0
- data/chrome/src/extension/background.html +9 -0
- data/chrome/src/extension/background.js +995 -0
- data/chrome/src/extension/content_script.js +1321 -0
- data/chrome/src/extension/icons/busy.png +0 -0
- data/chrome/src/extension/icons/free.png +0 -0
- data/chrome/src/extension/manifest-nonwin.json +19 -0
- data/chrome/src/extension/manifest-win.json +20 -0
- data/chrome/src/extension/utils.js +231 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome.rb +8 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome/bridge.rb +358 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome/command_executor.rb +124 -0
- data/chrome/src/rb/lib/selenium/webdriver/chrome/launcher.rb +135 -0
- data/common/src/js/abstractcommandprocessor.js +134 -0
- data/common/src/js/asserts.js +296 -0
- data/common/src/js/by.js +149 -0
- data/common/src/js/command.js +304 -0
- data/common/src/js/context.js +58 -0
- data/common/src/js/core/Blank.html +7 -0
- data/common/src/js/core/InjectedRemoteRunner.html +8 -0
- data/common/src/js/core/RemoteRunner.html +101 -0
- data/common/src/js/core/SeleniumLog.html +109 -0
- data/common/src/js/core/TestPrompt.html +145 -0
- data/common/src/js/core/TestRunner-splash.html +55 -0
- data/common/src/js/core/TestRunner.html +165 -0
- data/common/src/js/core/icons/all.png +0 -0
- data/common/src/js/core/icons/continue.png +0 -0
- data/common/src/js/core/icons/continue_disabled.png +0 -0
- data/common/src/js/core/icons/pause.png +0 -0
- data/common/src/js/core/icons/pause_disabled.png +0 -0
- data/common/src/js/core/icons/selected.png +0 -0
- data/common/src/js/core/icons/step.png +0 -0
- data/common/src/js/core/icons/step_disabled.png +0 -0
- data/common/src/js/core/lib/cssQuery/cssQuery-p.js +6 -0
- data/common/src/js/core/lib/cssQuery/src/cssQuery-level2.js +142 -0
- data/common/src/js/core/lib/cssQuery/src/cssQuery-level3.js +150 -0
- data/common/src/js/core/lib/cssQuery/src/cssQuery-standard.js +53 -0
- data/common/src/js/core/lib/cssQuery/src/cssQuery.js +356 -0
- data/common/src/js/core/lib/prototype.js +2006 -0
- data/common/src/js/core/lib/scriptaculous/builder.js +101 -0
- data/common/src/js/core/lib/scriptaculous/controls.js +815 -0
- data/common/src/js/core/lib/scriptaculous/dragdrop.js +915 -0
- data/common/src/js/core/lib/scriptaculous/effects.js +958 -0
- data/common/src/js/core/lib/scriptaculous/scriptaculous.js +47 -0
- data/common/src/js/core/lib/scriptaculous/slider.js +283 -0
- data/common/src/js/core/lib/scriptaculous/unittest.js +383 -0
- data/common/src/js/core/lib/snapsie.js +91 -0
- data/common/src/js/core/scripts/find_matching_child.js +69 -0
- data/common/src/js/core/scripts/htmlutils.js +8716 -0
- data/common/src/js/core/scripts/injection.html +72 -0
- data/common/src/js/core/scripts/selenium-api.js +3291 -0
- data/common/src/js/core/scripts/selenium-browserbot.js +2457 -0
- data/common/src/js/core/scripts/selenium-browserdetect.js +153 -0
- data/common/src/js/core/scripts/selenium-commandhandlers.js +379 -0
- data/common/src/js/core/scripts/selenium-executionloop.js +175 -0
- data/common/src/js/core/scripts/selenium-logging.js +148 -0
- data/common/src/js/core/scripts/selenium-remoterunner.js +695 -0
- data/common/src/js/core/scripts/selenium-testrunner.js +1362 -0
- data/common/src/js/core/scripts/selenium-version.js +5 -0
- data/common/src/js/core/scripts/ui-doc.html +808 -0
- data/common/src/js/core/scripts/ui-element.js +1644 -0
- data/common/src/js/core/scripts/ui-map-sample.js +979 -0
- data/common/src/js/core/scripts/user-extensions.js +3 -0
- data/common/src/js/core/scripts/user-extensions.js.sample +75 -0
- data/common/src/js/core/scripts/xmlextras.js +153 -0
- data/common/src/js/core/selenium-logo.png +0 -0
- data/common/src/js/core/selenium-test.css +43 -0
- data/common/src/js/core/selenium.css +316 -0
- data/common/src/js/core/xpath/dom.js +566 -0
- data/common/src/js/core/xpath/javascript-xpath-0.1.11.js +2816 -0
- data/common/src/js/core/xpath/util.js +549 -0
- data/common/src/js/core/xpath/xmltoken.js +149 -0
- data/common/src/js/core/xpath/xpath.js +2481 -0
- data/common/src/js/extension/README +2 -0
- data/common/src/js/extension/dommessenger.js +152 -0
- data/common/src/js/factory.js +55 -0
- data/common/src/js/future.js +141 -0
- data/common/src/js/jsunit.js +40 -0
- data/common/src/js/jsunit/app/css/jsUnitStyle.css +50 -0
- data/common/src/js/jsunit/app/css/readme +10 -0
- data/common/src/js/jsunit/app/emptyPage.html +11 -0
- data/common/src/js/jsunit/app/jsUnitCore.js +534 -0
- data/common/src/js/jsunit/app/jsUnitMockTimeout.js +81 -0
- data/common/src/js/jsunit/app/jsUnitTestManager.js +705 -0
- data/common/src/js/jsunit/app/jsUnitTestSuite.js +44 -0
- data/common/src/js/jsunit/app/jsUnitTracer.js +102 -0
- data/common/src/js/jsunit/app/jsUnitVersionCheck.js +59 -0
- data/common/src/js/jsunit/app/main-counts-errors.html +12 -0
- data/common/src/js/jsunit/app/main-counts-failures.html +13 -0
- data/common/src/js/jsunit/app/main-counts-runs.html +13 -0
- data/common/src/js/jsunit/app/main-counts.html +21 -0
- data/common/src/js/jsunit/app/main-data.html +178 -0
- data/common/src/js/jsunit/app/main-errors.html +23 -0
- data/common/src/js/jsunit/app/main-frame.html +19 -0
- data/common/src/js/jsunit/app/main-loader.html +45 -0
- data/common/src/js/jsunit/app/main-progress.html +25 -0
- data/common/src/js/jsunit/app/main-results.html +67 -0
- data/common/src/js/jsunit/app/main-status.html +13 -0
- data/common/src/js/jsunit/app/testContainer.html +16 -0
- data/common/src/js/jsunit/app/testContainerController.html +77 -0
- data/common/src/js/jsunit/app/xbDebug.js +306 -0
- data/common/src/js/jsunit/changelog.txt +60 -0
- data/common/src/js/jsunit/css/jsUnitStyle.css +83 -0
- data/common/src/js/jsunit/images/green.gif +0 -0
- data/common/src/js/jsunit/images/logo_jsunit.gif +0 -0
- data/common/src/js/jsunit/images/powerby-transparent.gif +0 -0
- data/common/src/js/jsunit/images/red.gif +0 -0
- data/common/src/js/jsunit/licenses/JDOM_license.txt +56 -0
- data/common/src/js/jsunit/licenses/Jetty_license.html +213 -0
- data/common/src/js/jsunit/licenses/MPL-1.1.txt +470 -0
- data/common/src/js/jsunit/licenses/gpl-2.txt +340 -0
- data/common/src/js/jsunit/licenses/index.html +141 -0
- data/common/src/js/jsunit/licenses/lgpl-2.1.txt +504 -0
- data/common/src/js/jsunit/licenses/mpl-tri-license-c.txt +35 -0
- data/common/src/js/jsunit/licenses/mpl-tri-license-html.txt +35 -0
- data/common/src/js/jsunit/readme.txt +19 -0
- data/common/src/js/jsunit/testRunner.html +167 -0
- data/common/src/js/jsunit/version.txt +1 -0
- data/common/src/js/key.js +117 -0
- data/common/src/js/localcommandprocessor.js +185 -0
- data/common/src/js/testcase.js +217 -0
- data/common/src/js/timing.js +89 -0
- data/common/src/js/webdriver.js +890 -0
- data/common/src/js/webelement.js +485 -0
- data/common/src/rb/README +30 -0
- data/common/src/rb/lib/selenium-webdriver.rb +1 -0
- data/common/src/rb/lib/selenium/webdriver.rb +67 -0
- data/common/src/rb/lib/selenium/webdriver/bridge_helper.rb +91 -0
- data/common/src/rb/lib/selenium/webdriver/child_process.rb +180 -0
- data/common/src/rb/lib/selenium/webdriver/core_ext/dir.rb +41 -0
- data/common/src/rb/lib/selenium/webdriver/driver.rb +252 -0
- data/common/src/rb/lib/selenium/webdriver/driver_extensions/takes_screenshot.rb +24 -0
- data/common/src/rb/lib/selenium/webdriver/element.rb +262 -0
- data/common/src/rb/lib/selenium/webdriver/error.rb +67 -0
- data/common/src/rb/lib/selenium/webdriver/find.rb +89 -0
- data/common/src/rb/lib/selenium/webdriver/keys.rb +84 -0
- data/common/src/rb/lib/selenium/webdriver/navigation.rb +27 -0
- data/common/src/rb/lib/selenium/webdriver/options.rb +50 -0
- data/common/src/rb/lib/selenium/webdriver/platform.rb +86 -0
- data/common/src/rb/lib/selenium/webdriver/target_locator.rb +70 -0
- data/firefox/prebuilt/Win32/Release/webdriver-firefox.dll +0 -0
- data/firefox/prebuilt/linux/Release/libwebdriver-firefox.so +0 -0
- data/firefox/prebuilt/linux/Release/x_ignore_nofocus.so +0 -0
- data/firefox/prebuilt/linux64/Release/libwebdriver-firefox.so +0 -0
- data/firefox/prebuilt/linux64/Release/x_ignore_nofocus.so +0 -0
- data/firefox/prebuilt/nsICommandProcessor.xpt +0 -0
- data/firefox/prebuilt/nsINativeEvents.xpt +0 -0
- data/firefox/prebuilt/nsIResponseHandler.xpt +0 -0
- data/firefox/src/extension/chrome.manifest +3 -0
- data/firefox/src/extension/components/badCertListener.js +294 -0
- data/firefox/src/extension/components/context.js +37 -0
- data/firefox/src/extension/components/driver-component.js +127 -0
- data/firefox/src/extension/components/firefoxDriver.js +810 -0
- data/firefox/src/extension/components/json2.js +273 -0
- data/firefox/src/extension/components/keytest.html +554 -0
- data/firefox/src/extension/components/nsCommandProcessor.js +643 -0
- data/firefox/src/extension/components/promptService.js +208 -0
- data/firefox/src/extension/components/screenshooter.js +81 -0
- data/firefox/src/extension/components/socketListener.js +185 -0
- data/firefox/src/extension/components/utils.js +1263 -0
- data/firefox/src/extension/components/webLoadingListener.js +57 -0
- data/firefox/src/extension/components/webdriverserver.js +106 -0
- data/firefox/src/extension/components/wrappedElement.js +683 -0
- data/firefox/src/extension/content/fxdriver.xul +30 -0
- data/firefox/src/extension/content/server.js +95 -0
- data/firefox/src/extension/idl/nsICommandProcessor.idl +38 -0
- data/firefox/src/extension/idl/nsIResponseHandler.idl +34 -0
- data/firefox/src/extension/install.rdf +29 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox.rb +31 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/binary.rb +107 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/bridge.rb +484 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/extension_connection.rb +90 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/launcher.rb +155 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/profile.rb +233 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/profiles_ini.rb +59 -0
- data/firefox/src/rb/lib/selenium/webdriver/firefox/util.rb +23 -0
- data/jobbie/prebuilt/Win32/Release/InternetExplorerDriver.dll +0 -0
- data/jobbie/prebuilt/x64/Release/InternetExplorerDriver.dll +0 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie.rb +14 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie/bridge.rb +565 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie/lib.rb +99 -0
- data/jobbie/src/rb/lib/selenium/webdriver/ie/util.rb +147 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote.rb +16 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/bridge.rb +408 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/capabilities.rb +105 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/commands.rb +53 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/default_http_client.rb +71 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/response.rb +49 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/server_error.rb +32 -0
- metadata +303 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
module Firefox
|
4
|
+
class ExtensionConnection
|
5
|
+
|
6
|
+
def initialize(host, port)
|
7
|
+
@host = host
|
8
|
+
@port = port
|
9
|
+
end
|
10
|
+
|
11
|
+
def connect(timeout = 20)
|
12
|
+
Timeout.timeout(timeout) {
|
13
|
+
loop do
|
14
|
+
begin
|
15
|
+
return new_socket
|
16
|
+
rescue Errno::ECONNREFUSED, Errno::ENOTCONN, SocketError => e
|
17
|
+
$stderr.puts "#{self} caught #{e.message} for #{@host}:#{@port}" if $DEBUG
|
18
|
+
sleep 0.25
|
19
|
+
end
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def new_socket
|
25
|
+
@socket = TCPSocket.new(@host, @port)
|
26
|
+
@socket.sync = true
|
27
|
+
|
28
|
+
@socket
|
29
|
+
end
|
30
|
+
|
31
|
+
def connected?
|
32
|
+
@socket && !@socket.closed?
|
33
|
+
end
|
34
|
+
|
35
|
+
def send_string(str)
|
36
|
+
str = <<-HTTP
|
37
|
+
GET / HTTP/1.1
|
38
|
+
Host: localhost
|
39
|
+
Content-Length: #{str.length}
|
40
|
+
|
41
|
+
#{str}
|
42
|
+
HTTP
|
43
|
+
@socket.write str
|
44
|
+
@socket.flush
|
45
|
+
end
|
46
|
+
|
47
|
+
def quit
|
48
|
+
command = {'commandName' => 'quit', 'context' => ''}
|
49
|
+
send_string(command.to_json)
|
50
|
+
ensure
|
51
|
+
close
|
52
|
+
end
|
53
|
+
|
54
|
+
def close
|
55
|
+
@socket.close if connected?
|
56
|
+
end
|
57
|
+
|
58
|
+
def read_response
|
59
|
+
resp = ""
|
60
|
+
received = ""
|
61
|
+
|
62
|
+
until resp.include?("\n\n")
|
63
|
+
received = @socket.recv 1
|
64
|
+
if received
|
65
|
+
resp += received
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
length = Integer(resp.split(":").last.strip)
|
70
|
+
json_string = ''
|
71
|
+
bytes_received = 0
|
72
|
+
|
73
|
+
until bytes_received == length
|
74
|
+
read_string = @socket.recv(length - bytes_received)
|
75
|
+
|
76
|
+
bytes_received += read_string.length
|
77
|
+
json_string << read_string
|
78
|
+
end
|
79
|
+
|
80
|
+
if json_string.empty?
|
81
|
+
raise Error::WebDriverError, "empty response from extension"
|
82
|
+
end
|
83
|
+
|
84
|
+
JSON.parse json_string
|
85
|
+
end
|
86
|
+
|
87
|
+
end # ExtensionConnection
|
88
|
+
end # Firefox
|
89
|
+
end # WebDriver
|
90
|
+
end # Selenium
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require "fcntl"
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
module WebDriver
|
5
|
+
module Firefox
|
6
|
+
class Launcher
|
7
|
+
|
8
|
+
attr_reader :binary, :connection
|
9
|
+
SOCKET_LOCK_TIMEOUT = 45
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(binary, port = DEFAULT_PORT, profile = DEFAULT_PROFILE_NAME)
|
13
|
+
@binary = binary
|
14
|
+
@port = port.to_i
|
15
|
+
|
16
|
+
if profile.kind_of? Profile
|
17
|
+
@profile = profile
|
18
|
+
else
|
19
|
+
@profile_name = profile
|
20
|
+
@profile = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
# need to be really specific about what host to use
|
24
|
+
#
|
25
|
+
# on os x, "localhost" will resolve to 3 different addresses (see /etc/hosts)
|
26
|
+
# Ruby will loop over these and happily bind to the same port on each one,
|
27
|
+
# making it completely unusable for our purposes.
|
28
|
+
#
|
29
|
+
@host = "127.0.0.1"
|
30
|
+
end
|
31
|
+
|
32
|
+
def launch
|
33
|
+
with_lock do
|
34
|
+
find_free_port
|
35
|
+
create_profile
|
36
|
+
start_silent_and_wait
|
37
|
+
start
|
38
|
+
connect_until_stable
|
39
|
+
end
|
40
|
+
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def with_lock
|
45
|
+
max_time = Time.now + SOCKET_LOCK_TIMEOUT
|
46
|
+
locking_port = @port - 1
|
47
|
+
|
48
|
+
until Time.now > max_time
|
49
|
+
begin
|
50
|
+
socket_lock = TCPServer.new(@host, locking_port)
|
51
|
+
socket_lock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
|
52
|
+
|
53
|
+
yield
|
54
|
+
return
|
55
|
+
rescue SocketError, Errno::EADDRINUSE
|
56
|
+
sleep 0.1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
raise Error::WebDriverError,
|
61
|
+
"Unable to bind to locking port #{locking_port} within #{SOCKET_LOCK_TIMEOUT} seconds"
|
62
|
+
ensure
|
63
|
+
socket_lock.close if socket_lock
|
64
|
+
end
|
65
|
+
|
66
|
+
def find_free_port
|
67
|
+
port = @port
|
68
|
+
|
69
|
+
until free_port?(port)
|
70
|
+
port += 1
|
71
|
+
end
|
72
|
+
|
73
|
+
@port = port
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_profile
|
77
|
+
unless @profile
|
78
|
+
fetch_profile
|
79
|
+
if @profile.nil?
|
80
|
+
raise Error, WebDriverError, "could not find or create profile: #{profile.inspect}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
@profile.delete_extensions_cache
|
85
|
+
|
86
|
+
@profile.port = @port
|
87
|
+
@profile.add_webdriver_extension(true)
|
88
|
+
@profile.update_user_prefs
|
89
|
+
end
|
90
|
+
|
91
|
+
def start
|
92
|
+
assert_profile
|
93
|
+
@binary.start_with @profile
|
94
|
+
end
|
95
|
+
|
96
|
+
def start_silent_and_wait
|
97
|
+
assert_profile
|
98
|
+
@binary.start_with @profile, "--silent"
|
99
|
+
@binary.wait
|
100
|
+
end
|
101
|
+
|
102
|
+
def connect
|
103
|
+
@connection = ExtensionConnection.new(@host, @port)
|
104
|
+
@connection.connect(5)
|
105
|
+
end
|
106
|
+
|
107
|
+
def connect_until_stable
|
108
|
+
max_time = Time.now + 60
|
109
|
+
|
110
|
+
until Time.now >= max_time
|
111
|
+
begin
|
112
|
+
connection = ExtensionConnection.new(@host, @port)
|
113
|
+
connection.connect(1)
|
114
|
+
connection.close
|
115
|
+
|
116
|
+
connect
|
117
|
+
return
|
118
|
+
rescue Timeout::Error => e
|
119
|
+
puts "#{self} caught #{e.message}" if $DEBUG
|
120
|
+
# ok
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
raise Error::WebDriverError, "unable to obtain stable firefox connection"
|
125
|
+
end
|
126
|
+
|
127
|
+
def free_port?(port)
|
128
|
+
s = TCPServer.new(@host, port)
|
129
|
+
s.close
|
130
|
+
true
|
131
|
+
rescue SocketError, Errno::EADDRINUSE
|
132
|
+
false
|
133
|
+
end
|
134
|
+
|
135
|
+
def fetch_profile
|
136
|
+
existing = Profile.from_name @profile_name
|
137
|
+
|
138
|
+
unless existing
|
139
|
+
@binary.create_base_profile @profile_name
|
140
|
+
Profile.ini.refresh
|
141
|
+
existing = Profile.from_name @profile_name
|
142
|
+
raise "unable to find or create new profile" unless existing
|
143
|
+
end
|
144
|
+
|
145
|
+
@profile = existing
|
146
|
+
end
|
147
|
+
|
148
|
+
def assert_profile
|
149
|
+
raise "must create_profile first" if @profile.nil?
|
150
|
+
end
|
151
|
+
|
152
|
+
end # Launcher
|
153
|
+
end # Firefox
|
154
|
+
end # WebDriver
|
155
|
+
end # Selenium
|
@@ -0,0 +1,233 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
module Firefox
|
4
|
+
class Profile
|
5
|
+
|
6
|
+
ANONYMOUS_PROFILE_NAME = "WEBDRIVER_ANONYMOUS_PROFILE"
|
7
|
+
EXTENSION_NAME = "fxdriver@googlecode.com"
|
8
|
+
EM_NAMESPACE_URI = "http://www.mozilla.org/2004/em-rdf#"
|
9
|
+
NO_FOCUS_LIBRARY_NAME = "x_ignore_nofocus.so"
|
10
|
+
|
11
|
+
DEFAULT_EXTENSION_SOURCE = File.expand_path("#{WebDriver.root}/firefox/src/extension")
|
12
|
+
|
13
|
+
XPTS = [
|
14
|
+
["#{WebDriver.root}/firefox/prebuilt/nsINativeEvents.xpt", "components/nsINativeEvents.xpt"],
|
15
|
+
["#{WebDriver.root}/firefox/prebuilt/nsICommandProcessor.xpt", "components/nsICommandProcessor.xpt"],
|
16
|
+
["#{WebDriver.root}/firefox/prebuilt/nsIResponseHandler.xpt", "components/nsIResponseHandler.xpt"],
|
17
|
+
]
|
18
|
+
|
19
|
+
NATIVE_WINDOWS = ["#{WebDriver.root}/firefox/prebuilt/Win32/Release/webdriver-firefox.dll", "platform/WINNT_x86-msvc/components/webdriver-firefox.dll"]
|
20
|
+
NATIVE_LINUX = [
|
21
|
+
["#{WebDriver.root}/firefox/prebuilt/linux/Release/libwebdriver-firefox.so", "platform/Linux_x86-gcc3/components/libwebdriver-firefox.so"],
|
22
|
+
["#{WebDriver.root}/firefox/prebuilt/linux64/Release/libwebdriver-firefox.so", "platform/Linux_x86_64-gcc3/components/libwebdriver-firefox.so"]
|
23
|
+
]
|
24
|
+
|
25
|
+
NO_FOCUS = [
|
26
|
+
["#{WebDriver.root}/firefox/prebuilt/linux64/Release/x_ignore_nofocus.so", "amd64/x_ignore_nofocus.so"],
|
27
|
+
["#{WebDriver.root}/firefox/prebuilt/linux/Release/x_ignore_nofocus.so", "x86/x_ignore_nofocus.so"],
|
28
|
+
]
|
29
|
+
|
30
|
+
SHARED = [
|
31
|
+
["#{WebDriver.root}/common/src/js/extension/dommessenger.js", "content/dommessenger.js"]
|
32
|
+
]
|
33
|
+
|
34
|
+
attr_reader :name, :directory
|
35
|
+
attr_writer :secure_ssl, :native_events, :load_no_focus_lib
|
36
|
+
attr_accessor :port
|
37
|
+
|
38
|
+
class << self
|
39
|
+
|
40
|
+
def ini
|
41
|
+
@ini ||= ProfilesIni.new
|
42
|
+
end
|
43
|
+
|
44
|
+
def from_name(name)
|
45
|
+
ini[name]
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize(directory = nil)
|
51
|
+
@directory = directory ? create_tmp_copy(directory) : Dir.mktmpdir("webdriver-profile")
|
52
|
+
|
53
|
+
unless File.directory? @directory
|
54
|
+
raise Error::WebDriverError, "Profile directory does not exist: #{@directory.inspect}"
|
55
|
+
end
|
56
|
+
|
57
|
+
# TODO: replace constants with options hash
|
58
|
+
@port = DEFAULT_PORT
|
59
|
+
@extension_source = DEFAULT_EXTENSION_SOURCE
|
60
|
+
@native_events = DEFAULT_ENABLE_NATIVE_EVENTS
|
61
|
+
@secure_ssl = DEFAULT_SECURE_SSL
|
62
|
+
@load_no_focus_lib = DEFAULT_LOAD_NO_FOCUS_LIB
|
63
|
+
end
|
64
|
+
|
65
|
+
def absolute_path
|
66
|
+
if Platform.win?
|
67
|
+
directory.gsub("/", "\\")
|
68
|
+
else
|
69
|
+
directory
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_user_prefs
|
74
|
+
prefs = current_user_prefs.merge DEFAULT_PREFERENCES
|
75
|
+
prefs['webdriver_firefox_port'] = @port
|
76
|
+
prefs['webdriver_accept_untrusted_certs'] = 'true' unless secure_ssl?
|
77
|
+
prefs['webdriver_enable_native_events'] = 'true' if native_events?
|
78
|
+
|
79
|
+
write_prefs prefs
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_webdriver_extension(force_creation = false)
|
83
|
+
ext_path = File.join(extensions_dir, EXTENSION_NAME)
|
84
|
+
|
85
|
+
if File.exists?(ext_path)
|
86
|
+
return unless force_creation
|
87
|
+
end
|
88
|
+
|
89
|
+
FileUtils.rm_rf ext_path
|
90
|
+
FileUtils.mkdir_p File.dirname(ext_path), :mode => 0700
|
91
|
+
FileUtils.cp_r @extension_source, ext_path
|
92
|
+
|
93
|
+
from_to = XPTS + SHARED
|
94
|
+
|
95
|
+
if native_events?
|
96
|
+
case Platform.os
|
97
|
+
when :linux
|
98
|
+
NATIVE_LINUX.each do |lib|
|
99
|
+
from_to << lib
|
100
|
+
end
|
101
|
+
when :windows
|
102
|
+
from_to << NATIVE_WINDOWS
|
103
|
+
else
|
104
|
+
raise Error::WebDriverError, "can't enable native events on #{Platform.os.inspect}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if load_no_focus_lib?
|
109
|
+
from_to += NO_FOCUS
|
110
|
+
modify_link_library_path(NO_FOCUS.map { |source, dest| File.join(ext_path, File.dirname(dest)) })
|
111
|
+
end
|
112
|
+
|
113
|
+
from_to.each do |source, destination|
|
114
|
+
dest = File.join(ext_path, destination)
|
115
|
+
FileUtils.mkdir_p File.dirname(dest)
|
116
|
+
FileUtils.cp source, dest
|
117
|
+
end
|
118
|
+
|
119
|
+
delete_extensions_cache
|
120
|
+
end
|
121
|
+
|
122
|
+
# TODO: add_extension
|
123
|
+
|
124
|
+
def extensions_dir
|
125
|
+
@extensions_dir ||= File.join(directory, "extensions")
|
126
|
+
end
|
127
|
+
|
128
|
+
def user_prefs_path
|
129
|
+
@user_prefs_js ||= File.join(directory, "user.js")
|
130
|
+
end
|
131
|
+
|
132
|
+
def delete_extensions_cache
|
133
|
+
cache = File.join(directory, "extensions.cache")
|
134
|
+
FileUtils.rm_f cache if File.exist?(cache)
|
135
|
+
end
|
136
|
+
|
137
|
+
def modify_link_library_path(paths)
|
138
|
+
old_path = ENV['LD_LIBRARY_PATH']
|
139
|
+
|
140
|
+
unless [nil, ''].include?(old_path)
|
141
|
+
paths << old_path
|
142
|
+
end
|
143
|
+
|
144
|
+
ENV['LD_LIBRARY_PATH'] = paths.join(File::PATH_SEPARATOR)
|
145
|
+
ENV['LD_PRELOAD'] = NO_FOCUS_LIBRARY_NAME
|
146
|
+
end
|
147
|
+
|
148
|
+
def native_events?
|
149
|
+
@native_events == true
|
150
|
+
end
|
151
|
+
|
152
|
+
def load_no_focus_lib?
|
153
|
+
@load_no_focus_lib == true
|
154
|
+
end
|
155
|
+
|
156
|
+
def secure_ssl?
|
157
|
+
@secure_ssl == true
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def create_tmp_copy(directory)
|
163
|
+
tmp_directory = Dir.mktmpdir("webdriver-rb-profilecopy")
|
164
|
+
|
165
|
+
# TODO: must be a better way..
|
166
|
+
FileUtils.rm_rf tmp_directory
|
167
|
+
FileUtils.mkdir_p File.dirname(tmp_directory), :mode => 0700
|
168
|
+
FileUtils.cp_r directory, tmp_directory
|
169
|
+
|
170
|
+
tmp_directory
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def current_user_prefs
|
175
|
+
return {} unless File.exist?(user_prefs_path)
|
176
|
+
|
177
|
+
prefs = {}
|
178
|
+
|
179
|
+
File.read(user_prefs_path).split("\n").each do |line|
|
180
|
+
if line =~ /user_pref\("([^"]+)"\s*,\s*(.+?)\);/
|
181
|
+
prefs[$1.strip] = $2.strip
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
prefs
|
186
|
+
end
|
187
|
+
|
188
|
+
def write_prefs(prefs)
|
189
|
+
File.open(user_prefs_path, "w") do |file|
|
190
|
+
prefs.each do |key, value|
|
191
|
+
file.puts "user_pref(#{key.inspect}, #{value});"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
DEFAULT_PREFERENCES = {
|
197
|
+
"app.update.auto" => 'false',
|
198
|
+
"app.update.enabled" => 'false',
|
199
|
+
"browser.download.manager.showWhenStarting" => 'false',
|
200
|
+
"browser.EULA.override" => 'true',
|
201
|
+
"browser.EULA.3.accepted" => 'true',
|
202
|
+
"browser.link.open_external" => '2',
|
203
|
+
"browser.link.open_newwindow" => '2',
|
204
|
+
"browser.safebrowsing.enabled" => 'false',
|
205
|
+
"browser.search.update" => 'false',
|
206
|
+
"browser.sessionstore.resume_from_crash" => 'false',
|
207
|
+
"browser.shell.checkDefaultBrowser" => 'false',
|
208
|
+
"browser.startup.page" => '0',
|
209
|
+
"browser.tabs.warnOnClose" => 'false',
|
210
|
+
"browser.tabs.warnOnOpen" => 'false',
|
211
|
+
"dom.disable_open_during_load" => 'false',
|
212
|
+
"extensions.update.enabled" => 'false',
|
213
|
+
"extensions.update.notifyUser" => 'false',
|
214
|
+
"security.warn_entering_secure" => 'false',
|
215
|
+
"security.warn_submit_insecure" => 'false',
|
216
|
+
"security.warn_entering_secure.show_once" => 'false',
|
217
|
+
"security.warn_entering_weak" => 'false',
|
218
|
+
"security.warn_entering_weak.show_once" => 'false',
|
219
|
+
"security.warn_leaving_secure" => 'false',
|
220
|
+
"security.warn_leaving_secure.show_once" => 'false',
|
221
|
+
"security.warn_submit_insecure" => 'false',
|
222
|
+
"security.warn_viewing_mixed" => 'false',
|
223
|
+
"security.warn_viewing_mixed.show_once" => 'false',
|
224
|
+
"signon.rememberSignons" => 'false',
|
225
|
+
"startup.homepage_welcome_url" => '"about:blank"',
|
226
|
+
"javascript.options.showInConsole" => 'true',
|
227
|
+
"browser.dom.window.dump.enabled" => 'true'
|
228
|
+
}
|
229
|
+
|
230
|
+
end # Profile
|
231
|
+
end # Firefox
|
232
|
+
end # WebDriver
|
233
|
+
end # Selenium
|