rwebspec-mechanize 0.2.1

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.
data/CHANGELOG ADDED
@@ -0,0 +1,12 @@
1
+ 0.2
2
+ - upgrade rwebspec 4
3
+
4
+ 0.1.4
5
+ - send different socket
6
+
7
+ 0.1.3
8
+ - remove dependeny on Santize, using Nokogiri for get html text view
9
+
10
+ 0.1.2
11
+ - click_button_with_id default to submit the form if the button not found
12
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2006-2008 Zhimin Zhan, zhimin@zhimin.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README ADDED
@@ -0,0 +1,41 @@
1
+
2
+ RWebSpec wraps the popular web testing framework WATIR with RSpec Syntax to provide better easy to read automated web test cases. By using TestWise/Watir recorder, the RWebSpec test scripts can be recorded in Firefox. TestWise, The Next-Generation Functional Testing IDE, makes editing/executing test cases with ease.
3
+
4
+ Sample RWebSpec Test:
5
+
6
+ load File.dirname(__FILE__) + '/test_helper.rb'
7
+
8
+ specification "User Profile" do
9
+ include TestHelper
10
+
11
+ before(:all) do
12
+ open_browser("http://demo.adminwise.com")
13
+ reset_database
14
+ end
15
+
16
+ after(:all) do
17
+ fail_safe { logout }
18
+ end
19
+
20
+ story "[8] User can change password" do
21
+ login_as("bob", "password")
22
+ click_link("Profile")
23
+ click_link("Change password")
24
+
25
+ password_change_page = expect_page PasswordChangePage
26
+ password_change_page.enter_current("password")
27
+ password_change_page.enter_new("newpass")
28
+ password_change_page.enter_confirm("newpass")
29
+ password_change_page.click_button("Change")
30
+
31
+ logout
32
+ login_as("bob", "newpass")
33
+ assert_link_present_with_text("Profile") # login Ok
34
+ end
35
+
36
+ end
37
+
38
+
39
+
40
+ TestWise Homepage: http://www.testwisely.com/en/testwise
41
+
data/Rakefile ADDED
@@ -0,0 +1,102 @@
1
+ require 'rubygems'
2
+ require 'rspec/core/rake_task'
3
+ # require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+ # require 'rdoc' # require rdoc 2
6
+ # gem 'darkfish-rdoc'
7
+ # require 'darkfish-rdoc'
8
+
9
+ $:.unshift(File.dirname(__FILE__) + "/lib")
10
+ #require 'rwebspec'
11
+
12
+ desc "Default task"
13
+ task :default => [ :clean, :spec, :rdoc, :chm, :gem]
14
+
15
+ desc "Continous build"
16
+ task :build => [:clean, :spec]
17
+
18
+ desc "Clean generated files"
19
+ task :clean do
20
+ rm_rf 'pkg'
21
+ rm_rf 'doc'
22
+ rm_rf 'chm'
23
+ end
24
+
25
+ desc 'Run all specs'
26
+ Spec::Rake::SpecTask.new('spec') do |t|
27
+ t.spec_opts = ['--format', 'specdoc', '--colour']
28
+ # t.libs = ["lib", "server/lib" ]
29
+ t.pattern = Dir['spec/**/*_spec.rb'].sort
30
+ end
31
+
32
+ # Generate the RDoc documentation
33
+ # Rake::RDocTask.new { |rdoc|
34
+ # rdoc.rdoc_dir = 'doc'
35
+ # rdoc.title = 'rWebUnit'
36
+ # rdoc.template = "#{ENV['template']}.rb" if ENV['template']
37
+ # rdoc.rdoc_files.include('README')
38
+ # rdoc.rdoc_files.include('lib/rwebspec.rb')
39
+ # rdoc.rdoc_files.include('lib/rwebspec/*.rb')
40
+ # }
41
+
42
+ =begin
43
+ # using DarkFish - http://deveiate.org/projects/Darkfish-Rdoc/
44
+ Rake::RDocTask.new do |rdoc|
45
+ rdoc.rdoc_dir = 'doc'
46
+ rdoc.title = 'RWebSpec-Mechanize'
47
+ rdoc.rdoc_files.include('lib/rwebspec.rb')
48
+ rdoc.rdoc_files.include('lib/rwebspec/*.rb')
49
+ rdoc.rdoc_files.include('lib/extensions/*.rb')
50
+ rdoc.rdoc_files.delete("lib/rwebspec/web_testcase.rb")
51
+ rdoc.rdoc_files.delete("lib/rwebspec/checkJSDialog.rb")
52
+ rdoc.options += [
53
+ '-SHN',
54
+ '-f', 'darkfish', # This is the important bit
55
+ ]
56
+ end
57
+
58
+ Rake::RDocTask.new("chm") do |rdoc|
59
+ rdoc.rdoc_dir = 'chm'
60
+ rdoc.title = 'RWebSpec-Mechanize'
61
+ rdoc.rdoc_files.include('lib/rwebspec.rb')
62
+ rdoc.rdoc_files.include('lib/rwebspec/*.rb')
63
+ rdoc.rdoc_files.delete("lib/rwebspec/web_testcase.rb")
64
+ rdoc.rdoc_files.delete("lib/rwebspec/checkJSDialog.rb")
65
+ rdoc.options += [
66
+ '-SHN',
67
+ '-f', 'chm', # This is the important bit
68
+ ]
69
+ end
70
+
71
+ =end
72
+
73
+ spec = Gem::Specification.new do |s|
74
+ s.platform= Gem::Platform::RUBY
75
+ s.name = "rwebspec-mechanize"
76
+ s.version = "0.2.1"
77
+ s.summary = "Web application load testing specification in Ruby"
78
+ s.description = "Load test specification for web applications in RSpec syntax and Watir"
79
+
80
+ s.author = "Zhimin Zhan"
81
+ s.email = "zhimin@agileway.com.au"
82
+ s.homepage= "http://github.com/zhimin/rwebspec-mechanize/tree/master"
83
+ s.rubyforge_project = "rwebspec-mechanize"
84
+
85
+ s.has_rdoc = true
86
+ s.requirements << 'none'
87
+ s.require_path = "lib"
88
+ s.autorequire = "rwebspec-mechanize"
89
+
90
+ s.files = [ "Rakefile", "README", "CHANGELOG", "MIT-LICENSE" ]
91
+ s.files = s.files + Dir.glob( "lib/**/*" )
92
+ s.files = s.files + Dir.glob( "test/**/*" )
93
+ s.files = s.files + Dir.glob( "sample/**/*")
94
+ s.files = s.files + Dir.glob( "docs/**/*" )
95
+ s.add_dependency(%q<rspec>, ["2.10.0"])
96
+ s.add_dependency("mechanize", ">= 2.5")
97
+ s.add_dependency("nokogiri")
98
+ end
99
+
100
+ Rake::GemPackageTask.new(spec) do |pkg|
101
+ pkg.need_zip = true
102
+ end
@@ -0,0 +1,388 @@
1
+ require 'test/unit/assertions'
2
+
3
+ module RWebSpec
4
+ module Mechanize
5
+ module Assert
6
+ include Test::Unit::Assertions
7
+
8
+ def assert_not(condition, msg = "")
9
+ perform_assertion { assert(!condition, msg) }
10
+ end
11
+
12
+ def assert_nil(actual, msg="")
13
+ perform_assertion { assert(actual.nil?, msg) }
14
+ end
15
+
16
+ def assert_not_nil(actual, msg="")
17
+ perform_assertion { assert(!actual.nil?, msg) }
18
+ end
19
+
20
+ def fail(message)
21
+ perform_assertion { assert(false, message) }
22
+ end
23
+
24
+ # assertions
25
+ def assert_title_equals(title)
26
+ assert_equals(title, @web_browser.page_title)
27
+ end
28
+
29
+ alias assert_title assert_title_equals
30
+
31
+ # Assert text present in page source (html)
32
+ # assert_text_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
33
+ def assert_text_in_page_source(text)
34
+ perform_assertion { assert((@web_browser.page_source.include? text), 'expected html: ' + text + ' not found') }
35
+ end
36
+
37
+ # Assert text not present in page source (html)
38
+ # assert_text_not_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
39
+ def assert_text_not_in_page_source(text)
40
+ perform_assertion { assert(!(@web_browser.page_source.include? text), 'expected html: ' + text + ' found') }
41
+ end
42
+
43
+ # Assert text present in page source (html)
44
+ # assert_text_present("iTest2 Cool") # <b>iTest2</b> Cool
45
+ def assert_text_present(text)
46
+ perform_assertion { assert((@web_browser.text.include? text), 'expected text: ' + text + ' not found') }
47
+ end
48
+
49
+ # Assert text not present in page source (html)
50
+ # assert_text_not_present("iTest2 Cool") # <b>iTest2</b> Cool
51
+ def assert_text_not_present(text)
52
+ perform_assertion { assert(!(@web_browser.text.include? text), 'expected text: ' + text + ' found') }
53
+ end
54
+
55
+
56
+ ##
57
+ # Link
58
+
59
+ # Assert a link with specified text (exact match) in the page
60
+ #
61
+ # <a href="">Click Me</a>
62
+ # assert_link_present_with_exact("Click Me") => true
63
+ # assert_link_present_with_exact("Click") => false
64
+ #
65
+ def assert_link_present_with_exact(link_text)
66
+ @web_browser.links.each { |link|
67
+ return if link_text == link.text
68
+ }
69
+ fail( "can't find the link with text: #{link_text}")
70
+ end
71
+
72
+ def assert_link_not_present_with_exact(link_text)
73
+ @web_browser.links.each { |link|
74
+ perform_assertion { assert(link_text != link.text, "unexpected link (exact): #{link_text} found") }
75
+ }
76
+ end
77
+
78
+ # Assert a link containing specified text in the page
79
+ #
80
+ # <a href="">Click Me</a>
81
+ # assert_link_present_with_text("Click ") # =>
82
+ #
83
+ def assert_link_present_with_text(link_text)
84
+ @web_browser.links.each { |link|
85
+ return if link.text.include?(link_text)
86
+ }
87
+ fail( "can't find the link containing text: #{link_text}")
88
+ end
89
+
90
+ def assert_link_not_present_with_text(link_text)
91
+ @web_browser.links.each { |link|
92
+ perform_assertion { assert(!link.text.include?(link_text), "unexpected link containing: #{link_text} found") }
93
+ }
94
+ end
95
+
96
+
97
+ ##
98
+ # Checkbox
99
+ def assert_checkbox_not_selected(checkbox_name)
100
+ @web_browser.checkboxes.each { |checkbox|
101
+ if (checkbox.name == checkbox_name) then
102
+ perform_assertion { assert(!checkbox.isSet?, "Checkbox #{checkbox_name} is checked unexpectly") }
103
+ end
104
+ }
105
+ end
106
+
107
+ alias assert_checkbox_not_checked assert_checkbox_not_selected
108
+
109
+ def assert_checkbox_selected(checkbox_name)
110
+ @web_browser.checkboxes.each { |checkbox|
111
+ if (checkbox.name == checkbox_name) then
112
+ perform_assertion { assert(checkbox.isSet?, "Checkbox #{checkbox_name} not checked") }
113
+ end
114
+ }
115
+ end
116
+
117
+ alias assert_checkbox_checked assert_checkbox_selected
118
+
119
+ ##
120
+ # select
121
+ def assert_option_value_not_present(select_name, option_value)
122
+ @web_browser.select_lists.each { |select|
123
+ continue unless select.name == select_name
124
+ select.o.each do |option| # items in the list
125
+ perform_assertion { assert(!(option.value == option_value), "unexpected select option: #{option_value} for #{select_name} found") }
126
+ end
127
+ }
128
+ end
129
+
130
+ alias assert_select_value_not_present assert_option_value_not_present
131
+
132
+ def assert_option_not_present(select_name, option_label)
133
+ @web_browser.select_lists.each { |select|
134
+ next unless select.name == select_name
135
+ select.o.each do |option| # items in the list
136
+ perform_assertion { assert(!(option.text == option_label), "unexpected select option: #{option_label} for #{select_name} found") }
137
+ end
138
+ }
139
+ end
140
+
141
+ alias assert_select_label_not_present assert_option_not_present
142
+
143
+ def assert_option_value_present(select_name, option_value)
144
+ @web_browser.select_lists.each { |select|
145
+ next unless select.name == select_name
146
+ select.o.each do |option| # items in the list
147
+ return if option.value == option_value
148
+ end
149
+ }
150
+ fail("can't find the combo box with value: #{option_value}")
151
+ end
152
+
153
+ alias assert_select_value_present assert_option_value_present
154
+ alias assert_menu_value_present assert_option_value_present
155
+
156
+ def assert_option_present(select_name, option_label)
157
+ @web_browser.select_lists.each { |select|
158
+ next unless select.name == select_name
159
+ select.o.each do |option| # items in the list
160
+ return if option.text == option_label
161
+ end
162
+ }
163
+ fail("can't find the combob box: #{select_name} with value: #{option_label}")
164
+ end
165
+
166
+ alias assert_select_label_present assert_option_present
167
+ alias assert_menu_label_present assert_option_present
168
+
169
+ def assert_option_equals(select_name, option_label)
170
+ @web_browser.select_lists.each { |select|
171
+ next unless select.name == select_name
172
+ select.o.each do |option| # items in the list
173
+ if (option.text == option_label) then
174
+ perform_assertion { assert_equal(select.value, option.value, "Select #{select_name}'s value is not equal to expected option label: '#{option_label}'") }
175
+ end
176
+ end
177
+ }
178
+ end
179
+
180
+ alias assert_select_label assert_option_equals
181
+ alias assert_menu_label assert_option_equals
182
+
183
+ def assert_option_value_equals(select_name, option_value)
184
+ @web_browser.select_lists.each { |select|
185
+ next unless select.name == select_name
186
+ perform_assertion { assert_equal(select.value, option_value, "Select #{select_name}'s value is not equal to expected: '#{option_value}'") }
187
+ }
188
+ end
189
+
190
+ alias assert_select_value assert_option_value_equals
191
+ alias assert_menu_value assert_option_value_equals
192
+
193
+ ##
194
+ # radio
195
+
196
+ # radio_group is the name field, radio options 'value' field
197
+ def assert_radio_option_not_present(radio_group, radio_option)
198
+ @web_browser.radios.each { |radio|
199
+ if (radio.name == radio_group) then
200
+ perform_assertion { assert(!(radio_option == radio.value), "unexpected radio option: " + radio_option + " found") }
201
+ end
202
+ }
203
+ end
204
+
205
+ def assert_radio_option_present(radio_group, radio_option)
206
+ @web_browser.radios.each { |radio|
207
+ return if (radio.name == radio_group) and (radio_option == radio.value)
208
+ }
209
+ fail("can't find the radio option : '#{radio_option}'")
210
+ end
211
+
212
+ def assert_radio_option_selected(radio_group, radio_option)
213
+ @web_browser.radios.each { |radio|
214
+ if (radio.name == radio_group and radio_option == radio.value) then
215
+ perform_assertion { assert(radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] not checked") }
216
+ end
217
+ }
218
+ end
219
+
220
+ alias assert_radio_button_checked assert_radio_option_selected
221
+ alias assert_radio_option_checked assert_radio_option_selected
222
+
223
+ def assert_radio_option_not_selected(radio_group, radio_option)
224
+ @web_browser.radios.each { |radio|
225
+ if (radio.name == radio_group and radio_option == radio.value) then
226
+ perform_assertion { assert(!radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] checked unexpected") }
227
+ end
228
+ }
229
+ end
230
+
231
+ alias assert_radio_button_not_checked assert_radio_option_not_selected
232
+ alias assert_radio_option_not_checked assert_radio_option_not_selected
233
+
234
+ ##
235
+ # Button
236
+ def assert_button_not_present(button_id)
237
+ @web_browser.buttons.each { |button|
238
+ perform_assertion { assert(button.id != button_id, "unexpected button id: #{button_id} found") }
239
+ }
240
+ end
241
+
242
+ def assert_button_not_present_with_text(text)
243
+ @web_browser.buttons.each { |button|
244
+ perform_assertion { assert(button.value != text, "unexpected button id: #{text} found") }
245
+ }
246
+ end
247
+
248
+ def assert_button_present(button_id)
249
+ @web_browser.buttons.each { |button|
250
+ return if button_id == button.id
251
+ }
252
+ fail("can't find the button with id: #{button_id}")
253
+ end
254
+
255
+ def assert_button_present_with_text(button_text)
256
+ @web_browser.buttons.each { |button|
257
+ return if button_text == button.value
258
+ }
259
+ fail("can't find the button with text: #{button_text}")
260
+ end
261
+
262
+
263
+ def assert_equals(expected, actual, msg=nil)
264
+ perform_assertion { assert(expected == actual, (msg.nil?) ? "Expected: #{expected} diff from actual: #{actual}" : msg) }
265
+ end
266
+
267
+
268
+ # Check a HTML element exists or not
269
+ # Example:
270
+ # assert_exists("label", "receipt_date")
271
+ # assert_exists(:span, :receipt_date)
272
+ def assert_exists(tag, element_id)
273
+ perform_assertion { assert(eval("#{tag}(:id, '#{element_id.to_s}').exists?"), "Element '#{tag}' with id: '#{element_id}' not found") }
274
+ end
275
+
276
+ alias assert_exists? assert_exists
277
+ alias assert_element_exists assert_exists
278
+
279
+ def assert_not_exists(tag, element_id)
280
+ perform_assertion { assert_not(eval("#{tag}(:id, '#{element_id.to_s}').exists?"), "Unexpected element'#{tag}' + with id: '#{element_id}' found")}
281
+ end
282
+
283
+ alias assert_not_exists? assert_not_exists
284
+ alias assert_element_not_exists? assert_not_exists
285
+
286
+
287
+ # Assert tag with element id is visible?, eg.
288
+ # assert_visible(:div, "public_notice")
289
+ # assert_visible(:span, "public_span")
290
+ def assert_visible(tag, element_id)
291
+ perform_assertion { assert(eval("#{tag}(:id, '#{element_id.to_s}').visible?"), "Element '#{tag}' with id: '#{element_id}' not visible") }
292
+ end
293
+
294
+ # Assert tag with element id is hidden?, example
295
+ # assert_hidden(:div, "secret")
296
+ # assert_hidden(:span, "secret_span")
297
+ def assert_hidden(tag, element_id)
298
+ perform_assertion { assert(!eval("#{tag}(:id, '#{element_id.to_s}').visible?"), "Element '#{tag}' with id: '#{element_id}' is visible") }
299
+ end
300
+
301
+ alias assert_not_visible assert_hidden
302
+
303
+
304
+ # Assert given text appear inside a table (inside <table> tag like below)
305
+ #
306
+ # <table id="t1">
307
+ #
308
+ # <tbody>
309
+ # <tr id="row_1">
310
+ # <td id="cell_1_1">A</td>
311
+ # <td id="cell_1_2">B</td>
312
+ # </tr>
313
+ # <tr id="row_2">
314
+ # <td id="cell_2_1">a</td>
315
+ # <td id="cell_2_2">b</td>
316
+ # </tr>
317
+ # </tbody>
318
+ #
319
+ # </table>
320
+ #
321
+ # The plain text view of above table
322
+ # A B a b
323
+ #
324
+ # Examples
325
+ # assert_text_present_in_table("t1", ">A<") # => true
326
+ # assert_text_present_in_table("t1", ">A<", :just_plain_text => true) # => false
327
+ def assert_text_present_in_table(table_id, text, options = { :just_plain_text => false })
328
+ perform_assertion { assert(table_source(table_id, options).include?(text), "the text #{text} not found in table #{table_id}") }
329
+ end
330
+
331
+ alias assert_text_in_table assert_text_present_in_table
332
+
333
+ def assert_text_not_present_in_table(table_id, text, options = { :just_plain_text => false })
334
+ perform_assertion { assert_not(table_source(table_id, options).include?(text), "the text #{text} not found in table #{table_id}") }
335
+ end
336
+
337
+ alias assert_text_not_in_table assert_text_not_present_in_table
338
+
339
+ # Assert a text field (with given name) has the value
340
+ #
341
+ # <input id="tid" name="text1" value="text already there" type="text">
342
+ #
343
+ # assert_text_field_value("text1", "text already there") => true
344
+ #
345
+ def assert_text_field_value(textfield_name, text)
346
+ perform_assertion { assert_equal(text, text_field(:name, textfield_name).value) }
347
+ end
348
+
349
+
350
+ #-- Not tested
351
+ # -----
352
+
353
+ def assert_text_in_element(element_id, text)
354
+ elem = element_by_id(element_id)
355
+ assert_not_nil(elem.innerText, "element #{element_id} has no text")
356
+ perform_assertion { assert(elem.innerText.include?(text), "the text #{text} not found in element #{element_id}") }
357
+ end
358
+
359
+ # Use
360
+ #
361
+
362
+ #TODO for drag-n-drop, check the postion in list
363
+ # def assert_position_in_list(list_element_id)
364
+ # raise "not implemented"
365
+ # end
366
+
367
+ private
368
+ def table_source(table_id, options)
369
+ elem_table = table(:id, table_id.to_s)
370
+ elem_table_text = elem_table.text
371
+ elem_table_html = is_firefox? ? elem_table.innerHTML : elem_table.html
372
+ table_source = options[:just_plain_text] ? elem_table_text : elem_table_html
373
+ end
374
+
375
+
376
+ def perform_assertion(&block)
377
+ begin
378
+ yield
379
+ rescue StandardError => e
380
+ # puts "[DEBUG] Assertion error: #{e}"
381
+ take_screenshot if $take_screenshot
382
+ raise e
383
+ end
384
+ end
385
+
386
+ end
387
+ end
388
+ end
@@ -0,0 +1,25 @@
1
+ #***********************************************************
2
+ #* Copyright (c) 2006 - 2009 Zhimin Zhan.
3
+ #* Distributed open-source, see full license in MIT-LICENSE
4
+ #***********************************************************
5
+
6
+ module RWebSpec
7
+ module Mechanize
8
+ ##
9
+ # Store test optionns
10
+ #
11
+ class Context
12
+ attr_accessor :base_url
13
+
14
+ def initialize(base_url)
15
+ set_base_url(base_url)
16
+ end
17
+
18
+ def set_base_url(baseUrl)
19
+ @base_url = baseUrl
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,74 @@
1
+ module FireWatir
2
+ class Firefox
3
+
4
+ @@firefox_started = false
5
+
6
+ def initialize(options = {})
7
+ if(options.kind_of?(Integer))
8
+ options = {:waitTime => options}
9
+ end
10
+
11
+ if(options[:profile])
12
+ profile_opt = "-no-remote -P #{options[:profile]}"
13
+ else
14
+ profile_opt = ""
15
+ end
16
+
17
+ waitTime = options[:waitTime] || 2
18
+
19
+ os = RUBY_PLATFORM
20
+ if RUBY_PLATFORM =~ /java/ then
21
+ require 'rbconfig'
22
+ os = Config::CONFIG['host_os']
23
+ end
24
+
25
+ case os
26
+ when /mswin/ || /mingw/
27
+ begin
28
+ # Get the path to Firefox.exe using Registry.
29
+ require 'win32/registry.rb'
30
+ path_to_bin = ""
31
+ Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Mozilla\Mozilla Firefox') do |reg|
32
+ keys = reg.keys
33
+ reg1 = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{keys[0]}\\Main")
34
+ reg1.each do |subkey, type, data|
35
+ if(subkey =~ /pathtoexe/i)
36
+ path_to_bin = data
37
+ end
38
+ end
39
+ end
40
+ rescue LoadError => e
41
+ path_to_bin = '"C:\Program Files\Mozilla Firefox\firefox.exe"'
42
+ end
43
+
44
+ when /linux/i
45
+ path_to_bin = `which firefox`.strip
46
+ when /darwin/i
47
+ path_to_bin = '/Applications/Firefox.app/Contents/MacOS/firefox'
48
+ when /java/
49
+ raise "Error, should have set using rbconfig: #{os}"
50
+ end
51
+
52
+ @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")} unless @@firefox_started
53
+
54
+ sleep waitTime
55
+ begin
56
+ set_defaults()
57
+ rescue Watir::Exception::UnableToStartJSShException
58
+ if !@t # no new thread starting browser, try again
59
+ puts "Firefox with JSSH not detected after you indicated @@firefox_started"
60
+ @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")}
61
+ sleep waitTime
62
+ set_defaults
63
+ end
64
+ end
65
+ get_window_number()
66
+ set_browser_document()
67
+ end
68
+
69
+ def self.firefox_started=(value)
70
+ @@firefox_started = value
71
+ end
72
+
73
+ end
74
+ end