selenium-selenese 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. data/README.markdown +308 -0
  2. data/examples/script/google.rb +15 -0
  3. data/lib/nautilus/shell.rb +32 -0
  4. data/lib/selenium.rb +14 -0
  5. data/lib/selenium/client/base.rb +140 -0
  6. data/lib/selenium/client/driver.rb +11 -0
  7. data/lib/selenium/client/extensions.rb +118 -0
  8. data/lib/selenium/client/idiomatic.rb +488 -0
  9. data/lib/selenium/client/javascript_expression_builder.rb +116 -0
  10. data/lib/selenium/client/javascript_frameworks/jquery.rb +13 -0
  11. data/lib/selenium/client/javascript_frameworks/prototype.rb +13 -0
  12. data/lib/selenium/client/legacy_driver.rb +1711 -0
  13. data/lib/selenium/client/protocol.rb +131 -0
  14. data/lib/selenium/client/selenium_helper.rb +36 -0
  15. data/lib/selenium/command_error.rb +4 -0
  16. data/lib/selenium/protocol_error.rb +4 -0
  17. data/lib/selenium/rake/default_tasks.rb +16 -0
  18. data/lib/selenium/rake/remote_control_start_task.rb +71 -0
  19. data/lib/selenium/rake/remote_control_stop_task.rb +44 -0
  20. data/lib/selenium/rake/tasks.rb +6 -0
  21. data/lib/selenium/remote_control/remote_control.rb +35 -0
  22. data/lib/selenium/rspec/reporting/file_path_strategy.rb +78 -0
  23. data/lib/selenium/rspec/reporting/html_report.rb +123 -0
  24. data/lib/selenium/rspec/reporting/selenium_test_report_formatter.rb +87 -0
  25. data/lib/selenium/rspec/reporting/system_capture.rb +72 -0
  26. data/lib/selenium/rspec/rspec_extensions.rb +96 -0
  27. data/lib/selenium/rspec/spec_helper.rb +34 -0
  28. data/lib/selenium/selenese.rb +24 -0
  29. data/lib/tcp_socket_extension.rb +32 -0
  30. data/vendor/selenium-server.jar +0 -0
  31. metadata +101 -0
data/README.markdown ADDED
@@ -0,0 +1,308 @@
1
+ Welcome to the official Ruby driver for [Selenium Remote Control](http://selenium-rc.openqa.org)
2
+
3
+ Mission
4
+ =======
5
+
6
+ Provide a **lightweight, simple and idiomatic API to write
7
+ Selenium tests in Ruby**. Focus is also on improving test
8
+ feedback -- especially on failures -- by providing
9
+ out-of-the-box **state-of-the-art reporting capabilities**.
10
+ With screenshots, HTML snapshopts and log captures,
11
+ investigating test failures becomes a breeze.
12
+
13
+
14
+ Install It
15
+ ==========
16
+
17
+ The easiest way to install the install selenium-to-selenese using RubyGems:
18
+
19
+ sudo gem install selenium-to-selenese
20
+
21
+ Features
22
+ ========
23
+
24
+ * Backward compatible with the old-fashioned, XSL generated Selenium Ruby API.
25
+ See [the generated driver](http://seleni-selenese.rubyforge.org/classes/Selenium/Client/GeneratedDriver.html) to get an extensive reference.
26
+
27
+ * Idiomatic interface to the Selenium API.
28
+ See [the Idiomatic module](http://seleni-selenese.rubyforge.org/classes/Selenium/Client/Idiomatic.html)
29
+ for more details.
30
+
31
+ * Convenience methods for AJAX.
32
+ See the [Extensions](http://seleni-selenese.rubyforge.org/classes/Selenium/Client/Extensions.html)
33
+ for more details.
34
+
35
+ * Flexible wait semantics inline with the trigerring action. e.g.
36
+
37
+ Check out the `click`, `go_back` and `wait_for` methods of the [Idiomatic Module](http://seleni-selenese.rubyforge.org/classes/Selenium/Client/Idiomatic.html)
38
+
39
+ * Leveraging latest innovations in Selenium Remote Control (screenshots, log captures, ...)
40
+
41
+ * Robust Rake task to start/stop the Selenium Remote Control server. More details in the next section.
42
+
43
+ * State-of-the-art reporting for RSpec.
44
+
45
+ Plain API
46
+ =========
47
+
48
+ Selenium-to-selenese is just a plain Ruby API, so you can use it wherever you can use Ruby.
49
+
50
+ To used the new API just require the client driver:
51
+
52
+ require "rubygems"
53
+ require "selenium/selenese"
54
+
55
+ For instance
56
+ to write a little Ruby script using selenium-to-selenese you could write something like:
57
+
58
+ #!/usr/bin/env ruby
59
+ #
60
+ # Sample Ruby script
61
+ #
62
+ require "rubygems"
63
+ require "selenium/selenese"
64
+
65
+ begin
66
+ @browser = Selenium::Client::Driver.new \
67
+ :host => "localhost",
68
+ :port => 4444,
69
+ :browser => "*firefox",
70
+ :url => "http://www.google.com",
71
+ :timeout_in_second => 60
72
+
73
+ @browser.start_new_browser_session
74
+ @browser.open "/"
75
+ @browser.type "q", "Selenium seleniumhq.org"
76
+ @browser.click "btnG", :wait_for => :page
77
+ puts @browser.text?("seleniumhq.org")
78
+ ensure
79
+ @browser.close_current_browser_session
80
+ end
81
+
82
+
83
+ Writing Tests
84
+ =============
85
+
86
+ Most likely you will be writing functional and acceptance tests. If you are a
87
+ `Test::Unit` fan your tests will look like:
88
+
89
+ #!/usr/bin/env ruby
90
+ #
91
+ # Sample Test:Unit based test case using the selenium-to-selenese API
92
+ #
93
+ require "test/unit"
94
+ require "rubygems"
95
+ require "selenium/selenese"
96
+
97
+ class ExampleTest < Test::Unit::TestCase
98
+ attr_reader :browser
99
+
100
+ def setup
101
+ @browser = Selenium::Client::Driver.new \
102
+ :host => "localhost",
103
+ :port => 4444,
104
+ :browser => "*firefox",
105
+ :url => "http://www.google.com",
106
+ :timeout_in_second => 60
107
+
108
+ browser.start_new_browser_session
109
+ end
110
+
111
+ def teardown
112
+ browser.close_current_browser_session
113
+ end
114
+
115
+ def test_page_search
116
+ browser.open "/"
117
+ assert_equal "Google", browser.title
118
+ browser.type "q", "Selenium seleniumhq"
119
+ browser.click "btnG", :wait_for => :page
120
+ assert_equal "Selenium seleniumhq - Google Search", browser.title
121
+ assert_equal "Selenium seleniumhq", browser.field("q")
122
+ assert browser.text?("seleniumhq.org")
123
+ assert browser.element?("link=Cached")
124
+ end
125
+
126
+ end
127
+
128
+ If BDD is more your style, here is how you can achieve the same thing using RSpec:
129
+
130
+ require 'rubygems'
131
+ gem "rspec", ">=1.2.8"
132
+ gem "selenium-client", ">=1.2.16"
133
+ require "selenium/selenese"
134
+ require "selenium/rspec/spec_helper"
135
+
136
+ describe "Google Search" do
137
+ attr_reader :selenium_driver
138
+ alias :page :selenium_driver
139
+
140
+ before(:all) do
141
+ @selenium_driver = Selenium::Client::Driver.new \
142
+ :host => "localhost",
143
+ :port => 4444,
144
+ :browser => "*firefox",
145
+ :url => "http://www.google.com",
146
+ :timeout_in_second => 60
147
+ end
148
+
149
+ before(:each) do
150
+ selenium_driver.start_new_browser_session
151
+ end
152
+
153
+ # The system capture need to happen BEFORE closing the Selenium session
154
+ append_after(:each) do
155
+ @selenium_driver.close_current_browser_session
156
+ end
157
+
158
+ it "can find Selenium" do
159
+ page.open "/"
160
+ page.title.should eql("Google")
161
+ page.type "q", "Selenium seleniumhq"
162
+ page.click "btnG", :wait_for => :page
163
+ page.value("q").should eql("Selenium seleniumhq")
164
+ page.text?("seleniumhq.org").should be_true
165
+ page.title.should eql("Selenium seleniumhq - Google Search")
166
+ page.text?("seleniumhq.org").should be_true
167
+ page.element?("link=Cached").should be_true
168
+ end
169
+
170
+ end
171
+
172
+ Start/Stop a Selenium Remote Control Server
173
+ ===========================================
174
+
175
+ Selenium client comes with some convenient Rake tasks to start/stop a Remote Control server.
176
+ To leverage the latest selenium-client capabilities, you may need to download
177
+ a recent nightly build of a standalone packaging of Selenium Remote
178
+ Control. You will find the nightly build at
179
+ http://nexus.openqa.org/content/repositories/snapshots/org/seleniumhq/selenium/server/selenium-server/
180
+
181
+ You typically "freeze" the Selenium Remote Control jar in your `vendor`
182
+ directory.
183
+
184
+ require 'selenium/rake/tasks'
185
+
186
+ Selenium::Rake::RemoteControlStartTask.new do |rc|
187
+ rc.port = 4444
188
+ rc.timeout_in_seconds = 3 * 60
189
+ rc.background = true
190
+ rc.wait_until_up_and_running = true
191
+ rc.jar_file = "/path/to/where/selenium-rc-standalone-jar-is-installed"
192
+ rc.additional_args << "-singleWindow"
193
+ end
194
+
195
+ Selenium::Rake::RemoteControlStopTask.new do |rc|
196
+ rc.host = "localhost"
197
+ rc.port = 4444
198
+ rc.timeout_in_seconds = 3 * 60
199
+ end
200
+
201
+ If you do not explicitly specify the path to selenium remote control jar
202
+ it will be "auto-discovered" in `vendor` directory using the following
203
+ path : `vendor/selenium-remote-control/selenium-server*-standalone.jar`
204
+
205
+ Check out [RemoteControlStartTask](http://seleni-selenese.rubyforge.org/classes/Selenium/Rake/RemoteControlStartTask.html) and [RemoteControlStopTask](http://seleni-selenese.rubyforge.org/classes/Selenium/Rake/RemoteControlStopTask.html) for more
206
+ details.
207
+
208
+ State-of-the-Art RSpec Reporting
209
+ ================================
210
+
211
+ Selenium Client comes with out-of-the-box RSpec reporting that include HTML snapshots, O.S. screenshots, in-browser page
212
+ screenshots (not limited to current viewport), and a capture of the latest remote controls for all failing tests. And all
213
+ course all this works even if your infrastructure is distributed (In particular in makes wonders with [Selenium
214
+ Grid](http://selenium-grid.openqa.org))
215
+
216
+ Using selenium-client RSpec reporting is as simple as using `SeleniumTestReportFormatter` as one of you RSpec formatters. For instance:
217
+
218
+ require 'spec/rake/spectask'
219
+ desc 'Run acceptance tests for web application'
220
+ Spec::Rake::SpecTask.new(:'test:acceptance:web') do |t|
221
+ t.libs << "test"
222
+ t.pattern = "test/*_spec.rb"
223
+ t.spec_opts << '--color'
224
+ t.spec_opts << "--require 'rubygems,selenium/rspec/reporting/selenium_test_report_formatter'"
225
+ t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./tmp/acceptance_tests_report.html"
226
+ t.spec_opts << "--format=progress"
227
+ t.verbose = true
228
+ end
229
+
230
+ You can then get cool reports like [this one](http://ph7spot.com/examples/selenium_rspec_report.html)
231
+
232
+ To capture screenshots and logs on failures, also make sure you
233
+ require the following files in your `spec_helper`:
234
+
235
+ require "rubygems"
236
+ require "spec"
237
+ require "selenium/client"
238
+ require "selenium/rspec/spec_helper"
239
+
240
+ Other Resources
241
+ ===============
242
+
243
+ * Report bugs at http://github.com/ph7/selenium-client/issues
244
+ * Browse API at http://seleni-selenese.rubyforge.org
245
+
246
+
247
+ Contribute and Join the Fun!
248
+ ============================
249
+
250
+ We welcome new features, add-ons, bug fixes, example, documentation,
251
+ etc. Make the gem work the way you envision!
252
+
253
+ * Report bugs at http://github.com/ph7/selenium-client/issues
254
+
255
+ * I recommend cloning the selenium-client
256
+ [reference repository](http://github.com/ph7/selenium-client/tree/master)
257
+
258
+ * You can also check out the [RubyForge page](http://rubyforge.org/projects/selenium-client)
259
+ and the [RDoc](http://seleni-selenese.rubyforge.org)
260
+
261
+ * We also have a [continuous integration server](http://xserve.openqa.org:8080/view/Ruby%20Client)
262
+
263
+ * Stories live in [Pivotal Tracker](https://www.pivotaltracker.com/projects/6280)
264
+ * To build, run `rake clean default package`. You can then install the
265
+ generated gem with `sudo gem install pkg/*.gem`
266
+ * You can also run all integration tests with `rake ci:integration`
267
+
268
+
269
+ Core Team
270
+ =========
271
+
272
+ * Philippe Hanrigou (`ph7`): Current Maintainer and main contributor
273
+ * Aslak Hellesoy and Darren Hobbs : Original version of the Selenium Ruby driver
274
+
275
+ Contributors
276
+ ============
277
+
278
+ * Aaron Tinio (`aptinio`):
279
+ - More robust Selenium RC shutdown
280
+ - Support for locator including single quotes in `wait_for_...` methods
281
+ - Do not capture system state on execution errors for pending examples
282
+ (ExamplePendingError, NotYetImplementedError)
283
+ - Auto-highlighting support
284
+
285
+ * Rick Lee-Morlang (`rleemorlang`):
286
+ - Fix for incremental calls to `wait_for_text`
287
+ - Regex support in `wait_for_text`
288
+
289
+ * [Paul Boone](http://www.mindbucket.com) (`paulboone`)
290
+ - Fixed method_missing in selenium_helper to only delegate to methods
291
+ that @selenium responds to
292
+
293
+ * [Adam Greene](http://blog.sweetspot.dm) (`skippy`)
294
+ - Added the ability to redirect output to a log file, when
295
+ launching Selenium Remote Control with the Rake task
296
+
297
+ * [Eliot Sykes](http://blog.eliotsykes.com) (`eliotsykes`)
298
+ - wait_for_visibility [patch](http://github.com/eliotsykes/selenium-client/commit/4c7f3d01aa75a6b1917fbf71335b0069392ed546)
299
+
300
+ * [Frederik Fix](http://github.com/derfred)(`derfred`)
301
+ - Fix escaping bug when dealing with embedded regexes such as
302
+ "webratlink=evalregex:/Pastry Lovers \\(Organizer\\)/"
303
+ [patch](http://github.com/derfred/selenium-client/commit/4342cbb39d1a92b8db8f26ee0dc6c1a8f3287737)
304
+
305
+ * [Alex Chaffe](http://alexch.github.com)
306
+ - Better error reporting and fixed bug where if the response
307
+ doesn't start with "OK" it swallows the first three
308
+ chars (leading to annoying "ed out after 5000 msec" messages)
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Sample Ruby script
4
+ #
5
+ require "rubygems"
6
+ require "selenium/selenese"
7
+
8
+ @browser = Selenium::Client::Driver.new(:browser => "*firefox",:url => "http://www.google.com",:timeout_in_second => 60)
9
+ @browser.start_new_browser_session
10
+ @browser.open "/"
11
+ @browser.type "q", "Selenium seleniumhq.org"
12
+ @browser.click "btnG", :wait_for => :page
13
+ puts @browser.text?("seleniumhq.org")
14
+ @browser.close_current_browser_session
15
+
@@ -0,0 +1,32 @@
1
+ module Nautilus
2
+
3
+ class Shell
4
+
5
+ def run(command, options = {})
6
+ sh build_command(command, options)
7
+ end
8
+
9
+ def build_command(command, options = {})
10
+ actual_command = command.kind_of?(Array) ? command.join(" ") : command
11
+ if options[:background]
12
+ if windows?
13
+ actual_command = "start /wait /b " + command
14
+ elsif options[:background]
15
+ actual_command << " &"
16
+ end
17
+ end
18
+ actual_command
19
+ end
20
+
21
+ def windows?
22
+ RUBY_PLATFORM =~ /mswin/
23
+ end
24
+
25
+ def sh(command)
26
+ successful = system(command)
27
+ raise "Error while running >>#{command}<<" unless successful
28
+ end
29
+
30
+ end
31
+
32
+ end
data/lib/selenium.rb ADDED
@@ -0,0 +1,14 @@
1
+ # Legacy helper providing backward compatibility
2
+
3
+ # -----------------
4
+ # Original code by Aslak Hellesoy and Darren Hobbs
5
+ # This file has been automatically generated via XSL
6
+ # -----------------
7
+
8
+ require File.expand_path(File.dirname(__FILE__) + '/selenium/client')
9
+
10
+ # Backward compatibility
11
+
12
+ SeleniumHelper = Selenium::Client::SeleniumHelper
13
+ SeleniumCommandError = Selenium::CommandError
14
+ Selenium::SeleniumDriver = Selenium::Client::Driver
@@ -0,0 +1,140 @@
1
+ module Selenium
2
+ module Client
3
+
4
+ # Driver constructor and session management commands
5
+ module Base
6
+ include Selenium::Client::Protocol
7
+ include Selenium::Client::GeneratedDriver
8
+ include Selenium::Client::Extensions
9
+ include Selenium::Client::Idiomatic
10
+
11
+ attr_reader :host, :port, :browser_string, :browser_url,
12
+ :default_timeout_in_seconds,
13
+ :default_javascript_framework,
14
+ :highlight_located_element_by_default
15
+
16
+ #
17
+ # Create a new client driver
18
+ #
19
+ # Example:
20
+ #
21
+ # Selenium::Client::Driver.new \
22
+ # :host => "localhost",
23
+ # :port => 4444,
24
+ # :browser => "*firefox",
25
+ # :timeout_in_seconds => 10,
26
+ # :url => "http://localhost:3000",
27
+ #
28
+ # You can also set the default javascript framework used for :wait_for
29
+ # AJAX and effects semantics (:prototype is the default value):
30
+ #
31
+ # Selenium::Client::Driver.new \
32
+ # :host => "localhost",
33
+ # :port => 4444,
34
+ # :browser => "*firefox",
35
+ # :timeout_in_seconds => 10,
36
+ # :url => "http://localhost:3000",
37
+ # :javascript_framework => :jquery
38
+ #
39
+ # You can also enables automatic highlighting of located elements
40
+ # by passing the highlight_located_element option, e.g.
41
+ #
42
+ # Selenium::Client::Driver.new \
43
+ # :host => "localhost",
44
+ # :port => 4444,
45
+ # :browser => "*firefox",
46
+ # :highlight_located_element => true
47
+ #
48
+ def initialize(*args)
49
+ command = "java -jar \"#{jar_path}\""
50
+ begin
51
+ fork do
52
+ system(command)
53
+ end
54
+ rescue NotImplementedError
55
+ Thread.start do
56
+ system(command)
57
+ end
58
+ end
59
+ if args[0].kind_of?(Hash)
60
+ options = args[0]
61
+ @host = "localhost"
62
+ @port = 4444
63
+ @browser_string = options[:browser]
64
+ @browser_url = options[:url]
65
+ @default_timeout_in_seconds = (options[:timeout_in_seconds] || 300).to_i
66
+ @default_javascript_framework = options[:javascript_framework] || :prototype
67
+ @highlight_located_element_by_default = options[:highlight_located_element] || false
68
+ else
69
+ @host = args[0]
70
+ @port = args[1].to_i
71
+ @browser_string = args[2]
72
+ @browser_url = args[3]
73
+ @default_timeout_in_seconds = (args[4] || 300).to_i
74
+ @default_javascript_framework = :prototype
75
+ @highlight_located_element_by_default = false
76
+ end
77
+
78
+ @extension_js = ""
79
+ @session_id = nil
80
+ end
81
+
82
+ def session_started?
83
+ not @session_id.nil?
84
+ end
85
+
86
+ # Starts a new browser session (launching a new browser matching
87
+ # configuration provided at driver creation time).
88
+ #
89
+ # Browser session specific option can also be provided. e.g.
90
+ #
91
+ # driver.start_new_browser_session(:captureNetworkTraffic => true)
92
+ #
93
+ def start_new_browser_session(options={})
94
+ options_as_string = options.collect {|key,value| "#{key.to_s}=#{value.to_s}"}.sort.join(";")
95
+ result = string_command "getNewBrowserSession", [@browser_string, @browser_url, @extension_js, options_as_string]
96
+ @session_id = result
97
+ # Consistent timeout on the remote control and driver side.
98
+ # Intuitive and this is what you want 90% of the time
99
+ self.remote_control_timeout_in_seconds = @default_timeout_in_seconds
100
+ self.highlight_located_element = true if highlight_located_element_by_default
101
+ end
102
+
103
+ def close_current_browser_session
104
+ remote_control_command "testComplete" if @session_id
105
+ @session_id = nil
106
+ end
107
+
108
+ def start
109
+ start_new_browser_session
110
+ end
111
+
112
+ def stop
113
+ close_current_browser_session
114
+ end
115
+
116
+ def chrome_backend?
117
+ ["*chrome", "*firefox", "*firefox2", "*firefox3"].include?(@browser_string)
118
+ end
119
+
120
+ #goto method added by Priya
121
+
122
+ #def goto(url)
123
+ # start_new_browser_session
124
+ # open "/"
125
+ # window_maximize
126
+ #end
127
+
128
+ def jar_path
129
+ File.expand_path("#{File.dirname(__FILE__)}/../../../vendor/selenium-server.jar")
130
+ end
131
+
132
+ def javascript_extension=(new_javascript_extension)
133
+ @extension_js = new_javascript_extension
134
+ end
135
+ alias :set_extension_js :javascript_extension=
136
+
137
+ end
138
+
139
+ end
140
+ end