selenium-webdriver 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,4 +1,13 @@
1
- 0.1.0 (2010-11-??)
1
+ 0.1.1 (2010-11-29)
2
+ ==================
3
+
4
+ * Fix for Chrome.path=
5
+ * Remote drivers always add Content-Length for POST requests (thanks joshuachisholm)
6
+ * Fix for JS execution bug in the IE driver
7
+ * Add ability to specify a proxy on the Http::Default client.
8
+ * The remote drivers' :http_client argument now take a configured instance.
9
+
10
+ 0.1.0 (2010-11-11)
2
11
  ===================
3
12
 
4
13
  * selenium-client code (Se1/RC client) is now included in the gem (require "selenium/client").
@@ -6,7 +6,7 @@ module Selenium
6
6
  class Bridge < Remote::Bridge
7
7
 
8
8
  def initialize(opts = {})
9
- @launcher = Launcher.launcher(
9
+ @launcher = Launcher.new(
10
10
  :default_profile => opts[:default_profile],
11
11
  :secure_ssl => opts[:secure_ssl]
12
12
  )
@@ -8,21 +8,6 @@ module Selenium
8
8
 
9
9
  attr_reader :pid
10
10
 
11
- def self.launcher(*args)
12
- launcher = case Platform.os
13
- when :windows
14
- WindowsLauncher.new(*args)
15
- when :macosx
16
- MacOSXLauncher.new(*args)
17
- when :unix, :linux
18
- UnixLauncher.new(*args)
19
- else
20
- raise "unknown OS: #{Platform.os}"
21
- end
22
-
23
- launcher
24
- end
25
-
26
11
  def initialize(opts = {})
27
12
  @default_profile = opts[:default_profile]
28
13
  @secure_ssl = !!opts[:secure_ssl]
@@ -122,10 +107,39 @@ module Selenium
122
107
  )
123
108
  end
124
109
 
125
- class WindowsLauncher < Launcher
126
- def self.possible_paths
110
+ class << self
111
+ def possible_paths
112
+ case Platform.os
113
+ when :windows
114
+ windows_paths
115
+ when :macosx
116
+ macosx_paths
117
+ when :unix, :linux
118
+ unix_paths
119
+ else
120
+ raise "unknown OS: #{Platform.os}"
121
+ end
122
+ end
123
+
124
+ def unix_paths
125
+ [
126
+ Platform.find_binary("google-chrome"),
127
+ Platform.find_binary("chromium"),
128
+ Platform.find_binary("chromium-browser"),
129
+ "/usr/bin/google-chrome"
130
+ ].compact
131
+ end
132
+
133
+ def macosx_paths
134
+ [
135
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
136
+ "#{Platform.home}/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
137
+ ]
138
+ end
139
+
140
+ def windows_paths
127
141
  [
128
- registry_path,
142
+ windows_registry_path,
129
143
  "#{ENV['USERPROFILE']}\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe",
130
144
  "#{ENV['USERPROFILE']}\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe",
131
145
  "#{Platform.home}\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe",
@@ -133,10 +147,12 @@ module Selenium
133
147
  ].compact
134
148
  end
135
149
 
136
- def self.registry_path
150
+ def windows_registry_path
137
151
  require "win32/registry"
138
152
 
139
- reg = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe")
153
+ reg = Win32::Registry::HKEY_LOCAL_MACHINE.open(
154
+ "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe")
155
+
140
156
  reg[""]
141
157
  rescue LoadError
142
158
  # older JRuby and IronRuby does not have win32/registry
@@ -144,23 +160,7 @@ module Selenium
144
160
  rescue Win32::Registry::Error
145
161
  nil
146
162
  end
147
- end
148
-
149
- class UnixLauncher < Launcher
150
- def self.possible_paths
151
- [Platform.find_binary("google-chrome"), Platform.find_binary("chromium"), "/usr/bin/google-chrome"].compact
152
- end
153
-
154
- end
155
-
156
- class MacOSXLauncher < UnixLauncher
157
- def self.possible_paths
158
- [
159
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
160
- "#{Platform.home}/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
161
- ]
162
- end
163
- end
163
+ end # class << self
164
164
 
165
165
  end # Launcher
166
166
  end # Chrome
@@ -34,12 +34,10 @@ module Selenium
34
34
  end
35
35
 
36
36
  def ==(other)
37
- return false unless other.kind_of? self.class
38
- as_json == other.as_json
37
+ other.kind_of?(self.class) && as_json == other.as_json
39
38
  end
40
39
  alias_method :eql?, :==
41
40
 
42
-
43
41
  def ftp=(value)
44
42
  self.type = :manual
45
43
  @ftp = value
@@ -111,7 +109,6 @@ module Selenium
111
109
 
112
110
  proxy
113
111
  end
114
-
115
112
  end # class << self
116
113
 
117
114
  end # Proxy
@@ -37,15 +37,16 @@ module Selenium
37
37
  # Initializes the bridge with the given server URL.
38
38
  #
39
39
  # @param url [String] url for the remote server
40
- # @param http_client [Class] an HTTP client class that implements the same interface as DefaultHttpClient
40
+ # @param http_client [Object] an HTTP client instance that implements the same protocol as Http::Default
41
41
  # @param desired_capabilities [Capabilities] an instance of Remote::Capabilities describing the capabilities you want
42
42
  #
43
43
 
44
44
  def initialize(opts = {})
45
- opts = default_options.merge(opts)
46
- http_client_class = opts.delete(:http_client)
47
- desired_capabilities = opts.delete(:desired_capabilities)
48
- url = opts.delete(:url)
45
+ opts = opts.dup
46
+
47
+ http_client = opts.delete(:http_client) { Http::Default.new }
48
+ desired_capabilities = opts.delete(:desired_capabilities) { Capabilities.firefox }
49
+ url = opts.delete(:url) { "http://localhost:4444/wd/hub" }
49
50
 
50
51
  unless opts.empty?
51
52
  raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
@@ -62,7 +63,9 @@ module Selenium
62
63
  uri = URI.parse(url)
63
64
  uri.path += "/" unless uri.path =~ /\/$/
64
65
 
65
- @http = http_client_class.new uri
66
+ http_client.server_url = uri
67
+
68
+ @http = http_client
66
69
  @capabilities = create_session(desired_capabilities)
67
70
  end
68
71
 
@@ -406,14 +409,6 @@ module Selenium
406
409
  http.call verb, path, command_hash
407
410
  end
408
411
 
409
- def default_options
410
- {
411
- :url => "http://localhost:4444/wd/hub",
412
- :http_client => Http::Default,
413
- :desired_capabilities => Capabilities.firefox
414
- }
415
- end
416
-
417
412
  end # Bridge
418
413
  end # Remote
419
414
  end # WebDriver
@@ -7,16 +7,17 @@ module Selenium
7
7
  CONTENT_TYPE = "application/json"
8
8
  DEFAULT_HEADERS = { "Accept" => CONTENT_TYPE }
9
9
 
10
- class << self
11
- attr_accessor :timeout
10
+ # deprecated.
11
+ def self.timeout=(timeout)
12
+ raise Error::WebDriverError,
13
+ "Configuration of HTTP timeouts has changed. See http://code.google.com/p/selenium/wiki/RubyBindings for updated intructions."
12
14
  end
13
15
 
14
- def initialize(url)
15
- @server_url = url
16
- end
16
+ attr_accessor :timeout
17
+ attr_writer :server_url
17
18
 
18
19
  def call(verb, url, command_hash)
19
- url = @server_url.merge(url) unless url.kind_of?(URI)
20
+ url = server_url.merge(url) unless url.kind_of?(URI)
20
21
  headers = DEFAULT_HEADERS.dup
21
22
 
22
23
  if command_hash
@@ -28,6 +29,8 @@ module Selenium
28
29
  puts " >>> #{payload}"
29
30
  puts " > #{headers.inspect}"
30
31
  end
32
+ elsif verb == :post
33
+ headers["Content-Length"] = "0"
31
34
  end
32
35
 
33
36
  request verb, url, headers, payload
@@ -35,6 +38,10 @@ module Selenium
35
38
 
36
39
  private
37
40
 
41
+ def server_url
42
+ @server_url or raise Error::WebDriverError, "server_url not set"
43
+ end
44
+
38
45
  def request(verb, url, headers, payload)
39
46
  raise NotImplementedError, "subclass responsibility"
40
47
  end
@@ -19,7 +19,7 @@ module Selenium
19
19
  # require 'selenium/webdriver/remote/http/curb'
20
20
  # include Selenium
21
21
  #
22
- # driver = WebDriver.for :firefox, :http_client => WebDriver::Remote::Http::Curb
22
+ # driver = WebDriver.for :firefox, :http_client => WebDriver::Remote::Http::Curb.new
23
23
  #
24
24
 
25
25
  class Curb < Common
@@ -65,7 +65,7 @@ module Selenium
65
65
 
66
66
  c.max_redirects = MAX_REDIRECTS
67
67
  c.follow_location = true
68
- c.timeout = self.class.timeout if self.class.timeout
68
+ c.timeout = @timeout if @timeout
69
69
  c.verbose = !!$DEBUG
70
70
 
71
71
  c
@@ -6,21 +6,21 @@ module Selenium
6
6
  module Http
7
7
  # @private
8
8
  class Default < Common
9
+ attr_accessor :proxy
9
10
 
10
11
  private
11
12
 
12
13
  def http
13
- # ignoring SSL for now
14
14
  @http ||= (
15
- http = Net::HTTP.new @server_url.host, @server_url.port
16
- if @server_url.scheme == "https"
15
+ http = new_http_client
16
+ if server_url.scheme == "https"
17
17
  http.use_ssl = true
18
18
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
19
19
  end
20
20
 
21
- if self.class.timeout
22
- http.open_timeout = self.class.timeout
23
- http.read_timeout = self.class.timeout
21
+ if @timeout
22
+ http.open_timeout = @timeout
23
+ http.read_timeout = @timeout
24
24
  end
25
25
 
26
26
  http
@@ -54,13 +54,27 @@ module Selenium
54
54
  def new_request_for(verb, url, headers)
55
55
  req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
56
56
 
57
- if @server_url.userinfo
58
- req.basic_auth @server_url.user, @server_url.password
57
+ if server_url.userinfo
58
+ req.basic_auth server_url.user, server_url.password
59
59
  end
60
60
 
61
61
  req
62
62
  end
63
63
 
64
+ def new_http_client
65
+ if @proxy
66
+ unless @proxy.respond_to?(:http) && url = @proxy.http
67
+ raise Error::WebDriverError, "expected HTTP proxy, got #{@proxy.inspect}"
68
+ end
69
+ proxy = URI.parse(url)
70
+
71
+ clazz = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password)
72
+ clazz.new(server_url.host, server_url.port)
73
+ else
74
+ Net::HTTP.new server_url.host, server_url.port
75
+ end
76
+ end
77
+
64
78
  end # Default
65
79
  end # Http
66
80
  end # Remote
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
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-11-11 00:00:00 +01:00
17
+ date: 2010-11-30 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency