selenium-webdriver 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/common/src/rb/CHANGES +8 -0
- data/firefox/src/extension/components/nsCommandProcessor.js +4 -2
- data/firefox/src/extension/components/webdriverserver.js +1 -1
- data/firefox/src/rb/lib/selenium/webdriver/firefox/bridge.rb +11 -1
- data/remote/client/src/rb/lib/selenium/webdriver/remote.rb +5 -2
- data/remote/client/src/rb/lib/selenium/webdriver/remote/bridge.rb +2 -11
- data/remote/client/src/rb/lib/selenium/webdriver/remote/http/common.rb +56 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/http/curb.rb +61 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/http/default.rb +42 -0
- data/remote/client/src/rb/lib/selenium/webdriver/remote/response.rb +10 -12
- metadata +6 -5
- data/remote/client/src/rb/lib/selenium/webdriver/remote/default_http_client.rb +0 -81
- data/remote/client/src/rb/lib/selenium/webdriver/remote/patron_http_client.rb +0 -58
data/common/src/rb/CHANGES
CHANGED
@@ -133,7 +133,7 @@ Response.prototype = {
|
|
133
133
|
set status(newStatus) { this.json_.status = newStatus; },
|
134
134
|
get status() { return this.json_.status; },
|
135
135
|
set value(val) { this.json_.value = val; },
|
136
|
-
get value() { return this.json_.value; }
|
136
|
+
get value() { return this.json_.value; }
|
137
137
|
};
|
138
138
|
|
139
139
|
|
@@ -540,7 +540,9 @@ nsCommandProcessor.prototype.getSessionCapabilities = function(response) {
|
|
540
540
|
'browserName': 'firefox',
|
541
541
|
'version': appInfo.version,
|
542
542
|
'javascriptEnabled': true,
|
543
|
-
'platform': xulRuntime.OS // same as Platform.valueOf("name");
|
543
|
+
'platform': xulRuntime.OS, // same as Platform.valueOf("name");
|
544
|
+
'cssSelectorsEnabled': true,
|
545
|
+
'takesScreenshot': true
|
544
546
|
};
|
545
547
|
response.send();
|
546
548
|
};
|
@@ -44,7 +44,7 @@ WebDriverServer.prototype.newDriver = function(window) {
|
|
44
44
|
var prefs =
|
45
45
|
Utils.getService("@mozilla.org/preferences-service;1", "nsIPrefBranch");
|
46
46
|
if (!prefs.prefHasUserValue("webdriver_enable_native_events")) {
|
47
|
-
Utils.dumpn('webdriver_enable_native_events not set; defaulting to
|
47
|
+
Utils.dumpn('webdriver_enable_native_events not set; defaulting to false');
|
48
48
|
}
|
49
49
|
this.enableNativeEvents =
|
50
50
|
prefs.prefHasUserValue("webdriver_enable_native_events") ?
|
@@ -13,12 +13,22 @@ module Selenium
|
|
13
13
|
opts.delete(:profile) || DEFAULT_PROFILE_NAME
|
14
14
|
)
|
15
15
|
|
16
|
+
http_client = opts.delete(:http_client)
|
17
|
+
|
16
18
|
unless opts.empty?
|
17
19
|
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
|
18
20
|
end
|
19
21
|
|
20
22
|
@launcher.launch
|
21
|
-
|
23
|
+
|
24
|
+
remote_opts = {
|
25
|
+
:url => @launcher.url,
|
26
|
+
:desired_capabilities => :firefox
|
27
|
+
}
|
28
|
+
|
29
|
+
remote_opts.merge!(:http_client => http_client) if http_client
|
30
|
+
|
31
|
+
super(remote_opts)
|
22
32
|
end
|
23
33
|
|
24
34
|
def browser
|
@@ -1,9 +1,12 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
1
3
|
require "selenium/webdriver/remote/capabilities"
|
2
|
-
require "selenium/webdriver/remote/default_http_client"
|
3
4
|
require "selenium/webdriver/remote/bridge"
|
4
5
|
require "selenium/webdriver/remote/server_error"
|
5
6
|
require "selenium/webdriver/remote/response"
|
6
7
|
require "selenium/webdriver/remote/commands"
|
8
|
+
require "selenium/webdriver/remote/http/common"
|
9
|
+
require "selenium/webdriver/remote/http/default"
|
7
10
|
|
8
11
|
module Selenium
|
9
12
|
module WebDriver
|
@@ -15,4 +18,4 @@ module Selenium
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
|
-
|
21
|
+
|
@@ -395,21 +395,12 @@ module Selenium
|
|
395
395
|
def default_options
|
396
396
|
{
|
397
397
|
:url => "http://localhost:4444/wd/hub",
|
398
|
-
|
399
|
-
:http_client => DefaultHttpClient,
|
398
|
+
:http_client => Http::Default,
|
400
399
|
:desired_capabilities => Capabilities.firefox
|
401
400
|
}
|
402
401
|
end
|
403
402
|
|
404
|
-
def http_client_class
|
405
|
-
require "selenium/webdriver/remote/patron_http_client"
|
406
|
-
PatronHttpClient
|
407
|
-
rescue LoadError
|
408
|
-
# patron not available
|
409
|
-
DefaultHttpClient
|
410
|
-
end
|
411
|
-
|
412
403
|
end # Bridge
|
413
404
|
end # Remote
|
414
405
|
end # WebDriver
|
415
|
-
end # Selenium
|
406
|
+
end # Selenium
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Selenium
|
2
|
+
module WebDriver
|
3
|
+
module Remote
|
4
|
+
module Http
|
5
|
+
class Common
|
6
|
+
MAX_REDIRECTS = 20 # same as chromium/gecko
|
7
|
+
CONTENT_TYPE = "application/json"
|
8
|
+
DEFAULT_HEADERS = { "Accept" => CONTENT_TYPE, "Content-Length" => "0" }
|
9
|
+
|
10
|
+
def initialize(url)
|
11
|
+
@server_url = url
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(verb, url, command_hash)
|
15
|
+
url = @server_url.merge(url) unless url.kind_of?(URI)
|
16
|
+
headers = DEFAULT_HEADERS.dup
|
17
|
+
|
18
|
+
if command_hash
|
19
|
+
payload = command_hash.to_json
|
20
|
+
headers["Content-Type"] = "#{CONTENT_TYPE}; charset=utf-8"
|
21
|
+
headers["Content-Length"] = payload.bytesize.to_s if [:post, :put].include?(verb)
|
22
|
+
|
23
|
+
if $DEBUG
|
24
|
+
puts " >>> #{payload}"
|
25
|
+
puts " > #{headers.inspect}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
request verb, url, headers, payload
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def request(verb, url, headers, payload)
|
35
|
+
raise NotImplementedError, "subclass responsibility"
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_response(code, body, content_type)
|
39
|
+
code, body, content_type = code.to_i, body.to_s.strip, content_type.to_s
|
40
|
+
puts "<- #{body}\n" if $DEBUG
|
41
|
+
|
42
|
+
if content_type.include? CONTENT_TYPE
|
43
|
+
raise Error::WebDriverError, "empty body: #{content_type.inspect} (#{code})\n#{body}" if body.empty?
|
44
|
+
Response.new(code, JSON.parse(body))
|
45
|
+
elsif code == 204
|
46
|
+
Response.new(code)
|
47
|
+
else
|
48
|
+
raise Error::WebDriverError, "unexpected content type: #{content_type.inspect} (#{code})\n#{body}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end # Common
|
53
|
+
end # Http
|
54
|
+
end # Remote
|
55
|
+
end # WebDriver
|
56
|
+
end # Selenium
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'curb'
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
module WebDriver
|
5
|
+
module Remote
|
6
|
+
module Http
|
7
|
+
|
8
|
+
#
|
9
|
+
# An alternative to the default Net::HTTP client.
|
10
|
+
#
|
11
|
+
# This can be used for the Firefox and Remote drivers if you have Curb
|
12
|
+
# installed.
|
13
|
+
#
|
14
|
+
# @example Using Curb
|
15
|
+
#
|
16
|
+
# include Selenium
|
17
|
+
#
|
18
|
+
# driver = WebDriver.for :firefox, :http_client => WebDriver::Remote::Http::Curb
|
19
|
+
#
|
20
|
+
|
21
|
+
class Curb < Common
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def request(verb, url, headers, payload)
|
26
|
+
client.url = url.to_s
|
27
|
+
client.headers = headers
|
28
|
+
|
29
|
+
case verb
|
30
|
+
when :get
|
31
|
+
client.http_get
|
32
|
+
when :post
|
33
|
+
client.post_body = payload || ""
|
34
|
+
client.http_post
|
35
|
+
when :put
|
36
|
+
client.put_data = payload || ""
|
37
|
+
client.http_put
|
38
|
+
when :delete
|
39
|
+
client.http_delete
|
40
|
+
else
|
41
|
+
raise Error::WebDriverError, "unknown HTTP verb: #{verb.inspect}"
|
42
|
+
end
|
43
|
+
|
44
|
+
create_response client.response_code, client.body_str, client.content_type
|
45
|
+
end
|
46
|
+
|
47
|
+
def client
|
48
|
+
@client ||= (
|
49
|
+
c = Curl::Easy.new
|
50
|
+
c.max_redirects = MAX_REDIRECTS
|
51
|
+
c.follow_location = true
|
52
|
+
|
53
|
+
c
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
end # Curb
|
58
|
+
end # Http
|
59
|
+
end # Remote
|
60
|
+
end # WebDriver
|
61
|
+
end # Selenium
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
module WebDriver
|
5
|
+
module Remote
|
6
|
+
module Http
|
7
|
+
# @private
|
8
|
+
class Default < Common
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def http
|
13
|
+
# ignoring SSL for now
|
14
|
+
@http ||= Net::HTTP.new @server_url.host, @server_url.port
|
15
|
+
end
|
16
|
+
|
17
|
+
def request(verb, url, headers, payload, redirects = 0)
|
18
|
+
request = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
|
19
|
+
|
20
|
+
retried = false
|
21
|
+
begin
|
22
|
+
response = http.request(request, payload)
|
23
|
+
rescue Errno::ECONNABORTED, Errno::ECONNRESET
|
24
|
+
# this happens sometimes on windows?!
|
25
|
+
raise if retried
|
26
|
+
retried = true
|
27
|
+
retry
|
28
|
+
end
|
29
|
+
|
30
|
+
if response.kind_of? Net::HTTPRedirection
|
31
|
+
raise Error::WebDriverError, "too many redirects" if redirects >= MAX_REDIRECTS
|
32
|
+
request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
|
33
|
+
else
|
34
|
+
create_response response.code, response.body, response.content_type
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end # Default
|
39
|
+
end # Http
|
40
|
+
end # Remote
|
41
|
+
end # WebDriver
|
42
|
+
end # Selenium
|
@@ -5,28 +5,26 @@ module Selenium
|
|
5
5
|
# @private
|
6
6
|
class Response
|
7
7
|
|
8
|
-
|
9
|
-
attr_writer
|
8
|
+
attr_reader :code, :payload
|
9
|
+
attr_writer :payload
|
10
|
+
|
11
|
+
def initialize(code, payload = nil)
|
12
|
+
@code = code
|
13
|
+
@payload = payload || {}
|
10
14
|
|
11
|
-
def initialize
|
12
|
-
yield self if block_given?
|
13
15
|
assert_ok
|
14
16
|
end
|
15
17
|
|
16
18
|
def error
|
17
|
-
Error.for_code
|
19
|
+
Error.for_code @payload['status']
|
18
20
|
end
|
19
21
|
|
20
22
|
def error_message
|
21
|
-
payload['value']['message']
|
23
|
+
@payload['value']['message']
|
22
24
|
end
|
23
25
|
|
24
26
|
def [](key)
|
25
|
-
payload[key]
|
26
|
-
end
|
27
|
-
|
28
|
-
def payload
|
29
|
-
@payload ||= {}
|
27
|
+
@payload[key]
|
30
28
|
end
|
31
29
|
|
32
30
|
private
|
@@ -44,4 +42,4 @@ module Selenium
|
|
44
42
|
end # Response
|
45
43
|
end # Remote
|
46
44
|
end # WebDriver
|
47
|
-
end # Selenium
|
45
|
+
end # Selenium
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 21
|
9
|
+
version: 0.0.21
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jari Bakken
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-11 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -271,10 +271,11 @@ files:
|
|
271
271
|
- remote/client/src/rb/lib/selenium/webdriver/remote/bridge.rb
|
272
272
|
- remote/client/src/rb/lib/selenium/webdriver/remote/capabilities.rb
|
273
273
|
- remote/client/src/rb/lib/selenium/webdriver/remote/commands.rb
|
274
|
-
- remote/client/src/rb/lib/selenium/webdriver/remote/default_http_client.rb
|
275
|
-
- remote/client/src/rb/lib/selenium/webdriver/remote/patron_http_client.rb
|
276
274
|
- remote/client/src/rb/lib/selenium/webdriver/remote/response.rb
|
277
275
|
- remote/client/src/rb/lib/selenium/webdriver/remote/server_error.rb
|
276
|
+
- remote/client/src/rb/lib/selenium/webdriver/remote/http/common.rb
|
277
|
+
- remote/client/src/rb/lib/selenium/webdriver/remote/http/curb.rb
|
278
|
+
- remote/client/src/rb/lib/selenium/webdriver/remote/http/default.rb
|
278
279
|
has_rdoc: true
|
279
280
|
homepage: http://selenium.googlecode.com
|
280
281
|
licenses: []
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require "net/http"
|
2
|
-
|
3
|
-
module Selenium
|
4
|
-
module WebDriver
|
5
|
-
module Remote
|
6
|
-
|
7
|
-
# @private
|
8
|
-
class DefaultHttpClient
|
9
|
-
MAX_REDIRECTS = 20 # same as chromium/gecko
|
10
|
-
CONTENT_TYPE = "application/json"
|
11
|
-
DEFAULT_HEADERS = { "Accept" => CONTENT_TYPE, "Content-Length" => "0" }
|
12
|
-
|
13
|
-
def initialize(url)
|
14
|
-
@server_url = url
|
15
|
-
end
|
16
|
-
|
17
|
-
def call(verb, url, command_hash)
|
18
|
-
response = nil
|
19
|
-
url = @server_url.merge(url) unless url.kind_of?(URI)
|
20
|
-
headers = DEFAULT_HEADERS.dup
|
21
|
-
|
22
|
-
if command_hash
|
23
|
-
payload = command_hash.to_json
|
24
|
-
headers["Content-Type"] = "#{CONTENT_TYPE}; charset=utf-8"
|
25
|
-
headers["Content-Length"] = payload.bytesize.to_s if [:post, :put].include?(verb)
|
26
|
-
|
27
|
-
if $DEBUG
|
28
|
-
puts " >>> #{payload}"
|
29
|
-
puts " > #{headers.inspect}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
request verb, url, headers, payload
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def http
|
39
|
-
# ignoring SSL for now
|
40
|
-
@http ||= Net::HTTP.new @server_url.host, @server_url.port
|
41
|
-
end
|
42
|
-
|
43
|
-
def request(verb, url, headers, payload, redirects = 0)
|
44
|
-
request = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
|
45
|
-
|
46
|
-
retried = false
|
47
|
-
begin
|
48
|
-
response = http.request(request, payload)
|
49
|
-
rescue Errno::ECONNABORTED
|
50
|
-
# this happens sometimes on windows?!
|
51
|
-
raise if retried
|
52
|
-
retried = true
|
53
|
-
retry
|
54
|
-
end
|
55
|
-
|
56
|
-
if response.kind_of? Net::HTTPRedirection
|
57
|
-
raise Error::WebDriverError, "too many redirects" if redirects >= MAX_REDIRECTS
|
58
|
-
request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
|
59
|
-
else
|
60
|
-
create_response response
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def create_response(res)
|
65
|
-
puts "<- #{res.body}\n" if $DEBUG
|
66
|
-
if res.content_type == CONTENT_TYPE
|
67
|
-
Response.new do |r|
|
68
|
-
r.code = res.code.to_i
|
69
|
-
r.payload = JSON.parse(res.body.strip)
|
70
|
-
end
|
71
|
-
elsif res.code == '204'
|
72
|
-
Response.new { |r| r.code = res.code.to_i }
|
73
|
-
else
|
74
|
-
raise Error::WebDriverError, "unexpected content type: #{res.content_type.inspect} (#{res.code})\n#{res.body}"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end # DefaultHttpClient
|
79
|
-
end # Remote
|
80
|
-
end # WebDriver
|
81
|
-
end # Selenium
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require "patron"
|
2
|
-
|
3
|
-
module Selenium
|
4
|
-
module WebDriver
|
5
|
-
module Remote
|
6
|
-
|
7
|
-
# @private
|
8
|
-
class PatronHttpClient
|
9
|
-
CONTENT_TYPE = "application/json"
|
10
|
-
DEFAULT_HEADERS = { "Accept" => CONTENT_TYPE, "Content-Length" => "0" }
|
11
|
-
|
12
|
-
def initialize(url)
|
13
|
-
@session = Patron::Session.new
|
14
|
-
@session.base_url = url
|
15
|
-
end
|
16
|
-
|
17
|
-
def call(verb, url, command_hash)
|
18
|
-
DEFAULT_HEADERS.each do |key, val|
|
19
|
-
@session.headers[key] = val
|
20
|
-
end
|
21
|
-
|
22
|
-
if command_hash
|
23
|
-
payload = command_hash.to_json
|
24
|
-
@session.headers['Content-Type'] = "#{CONTENT_TYPE}; charset=utf-8;"
|
25
|
-
@session.headers['Content-Length'] = payload.bytesize.to_s if [:post, :put].include?(verb)
|
26
|
-
if $DEBUG
|
27
|
-
puts " >>> #{payload}"
|
28
|
-
puts " > #{@session.headers.inspect}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
if [:post, :put].include?(verb)
|
33
|
-
create_response @session.send(verb, url, payload || '')
|
34
|
-
else
|
35
|
-
create_response @session.send(verb, url)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def create_response(res)
|
42
|
-
puts "<- #{res.body}\n" if $DEBUG
|
43
|
-
if res.headers['Content-Type'].include? CONTENT_TYPE
|
44
|
-
Response.new do |r|
|
45
|
-
r.code = res.status.to_i
|
46
|
-
r.payload = JSON.parse(res.body.strip)
|
47
|
-
end
|
48
|
-
elsif res.status == '204'
|
49
|
-
Response.new { |r| r.code = res.code.to_i }
|
50
|
-
else
|
51
|
-
raise "Unexpected content type: #{res.headers.inspect} (#{res.status})\n#{res.body}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end # PatronHttpClient
|
56
|
-
end # Remote
|
57
|
-
end # WebDriver
|
58
|
-
end # Selenium
|