watir 6.0.0.beta5 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/CHANGES.md +10 -1
- data/Gemfile +4 -0
- data/README.md +37 -23
- data/Rakefile +6 -10
- data/appveyor.yml +13 -0
- data/lib/watir.rb +20 -21
- data/lib/watir/alert.rb +21 -5
- data/lib/watir/browser.rb +9 -3
- data/lib/watir/elements/checkbox.rb +0 -1
- data/lib/watir/elements/element.rb +92 -50
- data/lib/watir/elements/form.rb +1 -2
- data/lib/watir/elements/iframe.rb +6 -2
- data/lib/watir/elements/image.rb +1 -1
- data/lib/watir/elements/option.rb +0 -1
- data/lib/watir/elements/radio.rb +0 -1
- data/lib/watir/elements/select.rb +1 -10
- data/lib/watir/extensions/select_text.rb +1 -1
- data/lib/watir/legacy_wait.rb +126 -0
- data/lib/watir/locators/text_field/locator.rb +0 -3
- data/lib/watir/locators/text_field/selector_builder.rb +1 -4
- data/lib/watir/locators/text_field/selector_builder/xpath.rb +0 -2
- data/lib/watir/locators/text_field/validator.rb +1 -9
- data/lib/watir/row_container.rb +1 -1
- data/lib/watir/user_editable.rb +7 -5
- data/lib/watir/wait.rb +56 -135
- data/lib/watir/wait/timer.rb +29 -2
- data/lib/watir/window.rb +11 -1
- data/lib/watirspec.rb +81 -0
- data/lib/watirspec/guards.rb +58 -0
- data/lib/watirspec/implementation.rb +33 -0
- data/lib/watirspec/rake_tasks.rb +115 -0
- data/lib/watirspec/runner.rb +53 -0
- data/lib/watirspec/server.rb +99 -0
- data/lib/watirspec/server/app.rb +62 -0
- data/spec/browser_spec.rb +5 -5
- data/spec/click_spec.rb +1 -1
- data/spec/container_spec.rb +1 -1
- data/spec/element_locator_spec.rb +1 -1
- data/spec/element_spec.rb +20 -34
- data/spec/implementation_spec.rb +24 -0
- data/spec/input_spec.rb +1 -1
- data/spec/spec_helper.rb +35 -3
- data/spec/special_chars_spec.rb +1 -1
- data/spec/watirspec/.gitignore +2 -0
- data/spec/watirspec/after_hooks_spec.rb +179 -0
- data/spec/watirspec/alert_spec.rb +101 -0
- data/spec/watirspec/browser_spec.rb +291 -0
- data/spec/watirspec/cookies_spec.rb +147 -0
- data/spec/watirspec/drag_and_drop_spec.rb +49 -0
- data/spec/watirspec/element_hidden_spec.rb +65 -0
- data/spec/watirspec/elements/area_spec.rb +76 -0
- data/spec/watirspec/elements/areas_spec.rb +42 -0
- data/spec/watirspec/elements/button_spec.rb +270 -0
- data/spec/watirspec/elements/buttons_spec.rb +55 -0
- data/spec/watirspec/elements/checkbox_spec.rb +279 -0
- data/spec/watirspec/elements/checkboxes_spec.rb +44 -0
- data/spec/watirspec/elements/collections_spec.rb +16 -0
- data/spec/watirspec/elements/dd_spec.rb +126 -0
- data/spec/watirspec/elements/dds_spec.rb +42 -0
- data/spec/watirspec/elements/del_spec.rb +128 -0
- data/spec/watirspec/elements/dels_spec.rb +40 -0
- data/spec/watirspec/elements/div_spec.rb +199 -0
- data/spec/watirspec/elements/divs_spec.rb +42 -0
- data/spec/watirspec/elements/dl_spec.rb +144 -0
- data/spec/watirspec/elements/dls_spec.rb +43 -0
- data/spec/watirspec/elements/dt_spec.rb +126 -0
- data/spec/watirspec/elements/dts_spec.rb +42 -0
- data/spec/watirspec/elements/element_spec.rb +361 -0
- data/spec/watirspec/elements/elements_spec.rb +15 -0
- data/spec/watirspec/elements/em_spec.rb +100 -0
- data/spec/watirspec/elements/ems_spec.rb +43 -0
- data/spec/watirspec/elements/filefield_spec.rb +181 -0
- data/spec/watirspec/elements/filefields_spec.rb +43 -0
- data/spec/watirspec/elements/font_spec.rb +29 -0
- data/spec/watirspec/elements/form_spec.rb +70 -0
- data/spec/watirspec/elements/forms_spec.rb +44 -0
- data/spec/watirspec/elements/frame_spec.rb +121 -0
- data/spec/watirspec/elements/frames_spec.rb +41 -0
- data/spec/watirspec/elements/hidden_spec.rb +102 -0
- data/spec/watirspec/elements/hiddens_spec.rb +43 -0
- data/spec/watirspec/elements/hn_spec.rb +96 -0
- data/spec/watirspec/elements/hns_spec.rb +38 -0
- data/spec/watirspec/elements/iframe_spec.rb +174 -0
- data/spec/watirspec/elements/iframes_spec.rb +47 -0
- data/spec/watirspec/elements/image_spec.rb +164 -0
- data/spec/watirspec/elements/images_spec.rb +40 -0
- data/spec/watirspec/elements/ins_spec.rb +129 -0
- data/spec/watirspec/elements/inses_spec.rb +40 -0
- data/spec/watirspec/elements/label_spec.rb +79 -0
- data/spec/watirspec/elements/labels_spec.rb +40 -0
- data/spec/watirspec/elements/li_spec.rb +115 -0
- data/spec/watirspec/elements/link_spec.rb +174 -0
- data/spec/watirspec/elements/links_spec.rb +44 -0
- data/spec/watirspec/elements/lis_spec.rb +42 -0
- data/spec/watirspec/elements/map_spec.rb +79 -0
- data/spec/watirspec/elements/maps_spec.rb +41 -0
- data/spec/watirspec/elements/meta_spec.rb +23 -0
- data/spec/watirspec/elements/metas_spec.rb +40 -0
- data/spec/watirspec/elements/ol_spec.rb +89 -0
- data/spec/watirspec/elements/ols_spec.rb +40 -0
- data/spec/watirspec/elements/option_spec.rb +152 -0
- data/spec/watirspec/elements/p_spec.rb +115 -0
- data/spec/watirspec/elements/pre_spec.rb +115 -0
- data/spec/watirspec/elements/pres_spec.rb +40 -0
- data/spec/watirspec/elements/ps_spec.rb +40 -0
- data/spec/watirspec/elements/radio_spec.rb +263 -0
- data/spec/watirspec/elements/radios_spec.rb +43 -0
- data/spec/watirspec/elements/select_list_spec.rb +379 -0
- data/spec/watirspec/elements/select_lists_spec.rb +46 -0
- data/spec/watirspec/elements/span_spec.rb +129 -0
- data/spec/watirspec/elements/spans_spec.rb +40 -0
- data/spec/watirspec/elements/strong_spec.rb +92 -0
- data/spec/watirspec/elements/strongs_spec.rb +43 -0
- data/spec/watirspec/elements/table_nesting_spec.rb +51 -0
- data/spec/watirspec/elements/table_spec.rb +146 -0
- data/spec/watirspec/elements/tables_spec.rb +42 -0
- data/spec/watirspec/elements/tbody_spec.rb +96 -0
- data/spec/watirspec/elements/tbodys_spec.rb +62 -0
- data/spec/watirspec/elements/td_spec.rb +71 -0
- data/spec/watirspec/elements/tds_spec.rb +53 -0
- data/spec/watirspec/elements/text_field_spec.rb +302 -0
- data/spec/watirspec/elements/text_fields_spec.rb +44 -0
- data/spec/watirspec/elements/textarea_spec.rb +26 -0
- data/spec/watirspec/elements/textareas_spec.rb +24 -0
- data/spec/watirspec/elements/tfoot_spec.rb +91 -0
- data/spec/watirspec/elements/tfoots_spec.rb +68 -0
- data/spec/watirspec/elements/thead_spec.rb +91 -0
- data/spec/watirspec/elements/theads_spec.rb +68 -0
- data/spec/watirspec/elements/tr_spec.rb +80 -0
- data/spec/watirspec/elements/trs_spec.rb +61 -0
- data/spec/watirspec/elements/ul_spec.rb +79 -0
- data/spec/watirspec/elements/uls_spec.rb +39 -0
- data/spec/watirspec/html/alerts.html +12 -0
- data/spec/watirspec/html/aria_attributes.html +9 -0
- data/spec/watirspec/html/class_locator.html +8 -0
- data/spec/watirspec/html/clicks.html +19 -0
- data/spec/watirspec/html/closeable.html +13 -0
- data/spec/watirspec/html/collections.html +15 -0
- data/spec/watirspec/html/css/jquery-ui-1.8.17.custom.css +287 -0
- data/spec/watirspec/html/data_attributes.html +9 -0
- data/spec/watirspec/html/definition_lists.html +48 -0
- data/spec/watirspec/html/drag_and_drop.html +106 -0
- data/spec/watirspec/html/font.html +10 -0
- data/spec/watirspec/html/forms_with_input_elements.html +170 -0
- data/spec/watirspec/html/frame_1.html +22 -0
- data/spec/watirspec/html/frame_2.html +16 -0
- data/spec/watirspec/html/frames.html +11 -0
- data/spec/watirspec/html/hover.html +12 -0
- data/spec/watirspec/html/iframe_1.html +22 -0
- data/spec/watirspec/html/iframes.html +12 -0
- data/spec/watirspec/html/images.html +28 -0
- data/spec/watirspec/html/images/1.gif +0 -0
- data/spec/watirspec/html/images/2.gif +0 -0
- data/spec/watirspec/html/images/3.gif +0 -0
- data/spec/watirspec/html/images/button.png +0 -0
- data/spec/watirspec/html/images/circle.png +0 -0
- data/spec/watirspec/html/images/map.gif +0 -0
- data/spec/watirspec/html/images/map2.gif +0 -0
- data/spec/watirspec/html/images/minus.gif +0 -0
- data/spec/watirspec/html/images/originaltriangle.png +0 -0
- data/spec/watirspec/html/images/plus.gif +0 -0
- data/spec/watirspec/html/images/square.png +0 -0
- data/spec/watirspec/html/images/triangle.png +0 -0
- data/spec/watirspec/html/inner_outer.html +5 -0
- data/spec/watirspec/html/javascript/helpers.js +16 -0
- data/spec/watirspec/html/javascript/jquery-1.7.1.min.js +4 -0
- data/spec/watirspec/html/javascript/jquery-ui-1.8.17.custom.min.js +68 -0
- data/spec/watirspec/html/keylogger.html +15 -0
- data/spec/watirspec/html/modal_dialog.html +9 -0
- data/spec/watirspec/html/multiple_ids.html +14 -0
- data/spec/watirspec/html/nested_frame_1.html +1 -0
- data/spec/watirspec/html/nested_frame_2.html +9 -0
- data/spec/watirspec/html/nested_frame_3.html +14 -0
- data/spec/watirspec/html/nested_frames.html +10 -0
- data/spec/watirspec/html/nested_iframe_2.html +12 -0
- data/spec/watirspec/html/nested_iframes.html +9 -0
- data/spec/watirspec/html/nested_tables.html +203 -0
- data/spec/watirspec/html/non_control_elements.html +135 -0
- data/spec/watirspec/html/removed_element.html +24 -0
- data/spec/watirspec/html/right_click.html +11 -0
- data/spec/watirspec/html/special_chars.html +12 -0
- data/spec/watirspec/html/tables.html +121 -0
- data/spec/watirspec/html/timeout_window_location.html +19 -0
- data/spec/watirspec/html/uneven_table.html +20 -0
- data/spec/watirspec/html/wait.html +65 -0
- data/spec/watirspec/html/watirspec.css +0 -0
- data/spec/watirspec/html/window_switching.html +12 -0
- data/spec/watirspec/relaxed_locate_spec.rb +214 -0
- data/spec/watirspec/screenshot_spec.rb +29 -0
- data/spec/watirspec/wait_spec.rb +304 -0
- data/spec/watirspec/window_switching_spec.rb +411 -0
- data/spec/{implementation.rb → watirspec_helper.rb} +13 -13
- data/support/appveyor.cmd +9 -0
- data/support/doctest_helper.rb +5 -1
- data/support/travis.sh +0 -1
- data/watir.gemspec +3 -4
- metadata +323 -30
- data/.gitmodules +0 -3
data/lib/watir/wait/timer.rb
CHANGED
@@ -2,6 +2,10 @@ module Watir
|
|
2
2
|
module Wait
|
3
3
|
class Timer
|
4
4
|
|
5
|
+
def initialize(timeout: nil)
|
6
|
+
@end_time = current_time + timeout if timeout
|
7
|
+
end
|
8
|
+
|
5
9
|
#
|
6
10
|
# Executes given block until it returns true or exceeds timeout.
|
7
11
|
# @param [Fixnum] timeout
|
@@ -10,8 +14,31 @@ module Watir
|
|
10
14
|
#
|
11
15
|
|
12
16
|
def wait(timeout, &block)
|
13
|
-
end_time =
|
14
|
-
|
17
|
+
end_time = @end_time || current_time + timeout
|
18
|
+
loop do
|
19
|
+
yield(block)
|
20
|
+
break if current_time > end_time
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def reset!
|
25
|
+
@end_time = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def locked?
|
29
|
+
!@end_time.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
if defined?(Process::CLOCK_MONOTONIC)
|
35
|
+
def current_time
|
36
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
def current_time
|
40
|
+
Time.now.to_f
|
41
|
+
end
|
15
42
|
end
|
16
43
|
|
17
44
|
end # Timer
|
data/lib/watir/window.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Watir
|
2
2
|
class Window
|
3
3
|
include EventuallyPresent
|
4
|
+
include Waitable
|
4
5
|
|
5
6
|
def initialize(driver, selector)
|
6
7
|
@driver = driver
|
@@ -189,7 +190,7 @@ module Watir
|
|
189
190
|
#
|
190
191
|
|
191
192
|
def use(&blk)
|
192
|
-
|
193
|
+
wait_for_exists
|
193
194
|
@driver.switch_to.window(handle, &blk)
|
194
195
|
self
|
195
196
|
end
|
@@ -240,5 +241,14 @@ module Watir
|
|
240
241
|
false
|
241
242
|
end
|
242
243
|
|
244
|
+
def wait_for_exists
|
245
|
+
return assert_exists unless Watir.relaxed_locate?
|
246
|
+
begin
|
247
|
+
wait_until(&:exists?)
|
248
|
+
rescue Wait::TimeoutError
|
249
|
+
raise Exception::NoMatchingWindowFoundException, @selector.inspect
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
243
253
|
end # Window
|
244
254
|
end # Watir
|
data/lib/watirspec.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "tmpdir"
|
2
|
+
require 'watirspec/guards'
|
3
|
+
require 'watirspec/implementation'
|
4
|
+
require 'watirspec/runner'
|
5
|
+
require 'watirspec/server'
|
6
|
+
|
7
|
+
module WatirSpec
|
8
|
+
class << self
|
9
|
+
attr_accessor :browser_args, :unguarded, :implementation
|
10
|
+
|
11
|
+
def html
|
12
|
+
@html ||= File.expand_path("../../spec/watirspec/html", __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
def run!
|
16
|
+
WatirSpec::Runner.execute_if_necessary
|
17
|
+
end
|
18
|
+
|
19
|
+
def url_for(str)
|
20
|
+
File.join(host, str)
|
21
|
+
end
|
22
|
+
|
23
|
+
def host
|
24
|
+
@host ||= "http://#{Server.bind}:#{Server.port}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def unguarded?
|
28
|
+
@unguarded ||= false
|
29
|
+
end
|
30
|
+
|
31
|
+
def implementation
|
32
|
+
@implementation ||= (
|
33
|
+
imp = WatirSpec::Implementation.new
|
34
|
+
yield imp if block_given?
|
35
|
+
|
36
|
+
imp
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def implementation=(imp)
|
41
|
+
unless imp.is_a?(WatirSpec::Implementation)
|
42
|
+
raise TypeError, "expected WatirSpec::Implementation, got #{imp.class}"
|
43
|
+
end
|
44
|
+
|
45
|
+
@implementation = imp
|
46
|
+
end
|
47
|
+
|
48
|
+
def new_browser
|
49
|
+
klass = WatirSpec.implementation.browser_class
|
50
|
+
args = Array(WatirSpec.implementation.browser_args).map { |e| Hash === e ? e.dup : e }
|
51
|
+
|
52
|
+
instance = klass.new(*args)
|
53
|
+
print_browser_info_once(instance)
|
54
|
+
|
55
|
+
instance
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def print_browser_info_once(instance)
|
61
|
+
return if defined?(@did_print_browser_info) && @did_print_browser_info
|
62
|
+
@did_print_browser_info = true
|
63
|
+
|
64
|
+
info = []
|
65
|
+
info << instance.class.name
|
66
|
+
|
67
|
+
if instance.respond_to?(:driver) && instance.driver.class.name == "Selenium::WebDriver::Driver"
|
68
|
+
info << "(webdriver)"
|
69
|
+
caps = instance.driver.capabilities
|
70
|
+
|
71
|
+
info << "#{caps.browser_name}"
|
72
|
+
info << "#{caps.version}"
|
73
|
+
end
|
74
|
+
|
75
|
+
$stderr.puts "running watirspec against #{info.join ' '} using args #{WatirSpec.implementation.browser_args.inspect}"
|
76
|
+
rescue
|
77
|
+
# ignored
|
78
|
+
end
|
79
|
+
|
80
|
+
end # class << WatirSpec
|
81
|
+
end # WatirSpec
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module WatirSpec
|
2
|
+
module Guards
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def guards
|
6
|
+
@guards ||= Hash.new { |hash, key| hash[key] = [] }
|
7
|
+
end
|
8
|
+
|
9
|
+
def record(guard_name, impls, data)
|
10
|
+
guards[impls] << {name: guard_name, data: data}
|
11
|
+
end
|
12
|
+
|
13
|
+
def report
|
14
|
+
gs = WatirSpec.implementation.matching_guards_in(guards)
|
15
|
+
print "\n\nWatirSpec guards for this implementation: "
|
16
|
+
|
17
|
+
if gs.empty?
|
18
|
+
puts "none."
|
19
|
+
else
|
20
|
+
puts
|
21
|
+
gs.each do |guard|
|
22
|
+
puts "\t#{guard[:name].to_s.ljust(20)}: #{guard[:data].inspect}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end # class << self
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def deviates_on(*impls)
|
31
|
+
Guards.record :deviates, impls, file: caller.first
|
32
|
+
return yield if WatirSpec.unguarded?
|
33
|
+
yield if WatirSpec.implementation.matches_guard?(impls)
|
34
|
+
end
|
35
|
+
|
36
|
+
def not_compliant_on(*impls)
|
37
|
+
Guards.record :not_compliant, impls, file: caller.first
|
38
|
+
return yield if WatirSpec.unguarded?
|
39
|
+
yield unless WatirSpec.implementation.matches_guard?(impls)
|
40
|
+
end
|
41
|
+
|
42
|
+
def compliant_on(*impls)
|
43
|
+
Guards.record :compliant, impls, file: caller.first
|
44
|
+
return yield if WatirSpec.unguarded?
|
45
|
+
yield if WatirSpec.implementation.matches_guard?(impls)
|
46
|
+
end
|
47
|
+
|
48
|
+
def bug(key, *impls)
|
49
|
+
Guards.record :bug, impls, file: caller.first, key: key
|
50
|
+
return yield if WatirSpec.unguarded?
|
51
|
+
yield unless WatirSpec.implementation.matches_guard?(impls)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Object
|
57
|
+
include WatirSpec::Guards
|
58
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module WatirSpec
|
2
|
+
class Implementation
|
3
|
+
|
4
|
+
attr_writer :name, :guard_proc, :browser_class
|
5
|
+
attr_accessor :browser_args
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@guard_proc = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def browser_class
|
12
|
+
@browser_class || raise("browser_class not set")
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
@name || raise("implementation name not set")
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches_guard?(args)
|
20
|
+
return @guard_proc.call(args) if @guard_proc
|
21
|
+
|
22
|
+
args.include? name
|
23
|
+
end
|
24
|
+
|
25
|
+
def matching_guards_in(guards)
|
26
|
+
result = []
|
27
|
+
guards.each { |args, data| data.each { |d| result << d } if matches_guard?(args) }
|
28
|
+
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
end # Implementation
|
33
|
+
end # WatirSpec
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'rake/tasklib'
|
2
|
+
|
3
|
+
module WatirSpec
|
4
|
+
class RakeTasks < Rake::TaskLib
|
5
|
+
def initialize
|
6
|
+
namespace :watirspec do
|
7
|
+
desc 'Initialize WatirSpec'
|
8
|
+
task :init do
|
9
|
+
init_watirspec
|
10
|
+
print_usage
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'List WatirSpec examples'
|
14
|
+
task :list do
|
15
|
+
print_specs
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Run WatirSpec examples'
|
19
|
+
task :run, %i(spec line) do |_, args|
|
20
|
+
run(args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def init_watirspec
|
28
|
+
Dir.mkdir('spec') unless Dir.exist?('spec')
|
29
|
+
return if File.exist?('spec/watirspec_helper.rb')
|
30
|
+
|
31
|
+
File.open('spec/watirspec_helper.rb', 'w') do |file|
|
32
|
+
file.write(watirspec_helper_template)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_specs
|
37
|
+
puts "The following spec files are present:\n\n"
|
38
|
+
spec_files.each do |file|
|
39
|
+
filename = file.sub("#{watirspec_path}/", '')
|
40
|
+
puts " #{filename}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def run(**args)
|
45
|
+
return if system(rspec_command(args))
|
46
|
+
exit $?.exitstatus || 1
|
47
|
+
end
|
48
|
+
|
49
|
+
def rspec_command(**args)
|
50
|
+
cmd = [rspec_binary]
|
51
|
+
if args[:spec]
|
52
|
+
spec_file = spec_files.find { |file| file == "#{watirspec_path}/#{args[:spec]}_spec.rb" }
|
53
|
+
spec_file << ":#{args[:line]}" if args[:line]
|
54
|
+
cmd << spec_file
|
55
|
+
else
|
56
|
+
cmd << spec_files
|
57
|
+
end
|
58
|
+
|
59
|
+
cmd.join(' ')
|
60
|
+
end
|
61
|
+
|
62
|
+
def spec_files
|
63
|
+
Dir.glob("#{watirspec_path}/**/*_spec.rb")
|
64
|
+
end
|
65
|
+
|
66
|
+
def rspec_binary
|
67
|
+
rspec_path = Bundler.rubygems.find_name('rspec-core').first.full_gem_path
|
68
|
+
"#{rspec_path}/exe/rspec"
|
69
|
+
end
|
70
|
+
|
71
|
+
def watirspec_path
|
72
|
+
watir_path = Bundler.rubygems.find_name('watir').first.full_gem_path
|
73
|
+
"#{watir_path}/spec/watirspec"
|
74
|
+
end
|
75
|
+
|
76
|
+
def watirspec_helper_template
|
77
|
+
<<-RUBY
|
78
|
+
require 'watirspec'
|
79
|
+
# require your gems
|
80
|
+
|
81
|
+
WatirSpec.implementation do |watirspec|
|
82
|
+
# add WatirSpec implementation (see example below)
|
83
|
+
#
|
84
|
+
# watirspec.name = :watizzle
|
85
|
+
# watirspec.browser_class = Watir::Browser
|
86
|
+
# watirspec.browser_args = [:phantomjs, {}]
|
87
|
+
# watirspec.guard_proc = lambda do |args|
|
88
|
+
# args.include?(:phantomjs)
|
89
|
+
# end
|
90
|
+
end
|
91
|
+
|
92
|
+
WatirSpec.run!
|
93
|
+
RUBY
|
94
|
+
end
|
95
|
+
|
96
|
+
def print_usage
|
97
|
+
p <<-EOS
|
98
|
+
File spec/watirspec_helper.rb is successfully created!
|
99
|
+
Please, check it and customize for your needs. Once done, you can start using WatirSpec.
|
100
|
+
|
101
|
+
Run all WatirSpec examples:
|
102
|
+
$ bundle exec rake watirspec:run
|
103
|
+
|
104
|
+
Run specific WatirSpec example:
|
105
|
+
$ bundle exec rake watirspec:run[elements/div]
|
106
|
+
|
107
|
+
Run WatirSpec example on a custom line:
|
108
|
+
$ bundle exec rake watirspec:run[elements/div, 50]
|
109
|
+
|
110
|
+
List all WatirSpec examples:
|
111
|
+
$ bundle exec rake watirspec:list
|
112
|
+
EOS
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module WatirSpec
|
2
|
+
module Runner
|
3
|
+
|
4
|
+
module BrowserHelper
|
5
|
+
def browser
|
6
|
+
$browser
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module MessagesHelper
|
11
|
+
def messages
|
12
|
+
browser.div(id: 'messages').divs.map(&:text)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module_function
|
17
|
+
|
18
|
+
def execute
|
19
|
+
start_server
|
20
|
+
configure
|
21
|
+
add_guard_hook
|
22
|
+
|
23
|
+
@executed = true
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute_if_necessary
|
27
|
+
execute unless @executed
|
28
|
+
end
|
29
|
+
|
30
|
+
def configure
|
31
|
+
Thread.abort_on_exception = true
|
32
|
+
return unless defined?(RSpec)
|
33
|
+
|
34
|
+
RSpec.configure do |config|
|
35
|
+
config.include(BrowserHelper)
|
36
|
+
config.include(MessagesHelper)
|
37
|
+
|
38
|
+
$browser = WatirSpec.new_browser
|
39
|
+
at_exit { $browser.close }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def start_server
|
44
|
+
WatirSpec::Server.run!
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_guard_hook
|
48
|
+
return if WatirSpec.unguarded?
|
49
|
+
at_exit { WatirSpec::Guards.report }
|
50
|
+
end
|
51
|
+
|
52
|
+
end # SpecHelper
|
53
|
+
end # WatirSpec
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'watirspec/server/app'
|
3
|
+
|
4
|
+
module WatirSpec
|
5
|
+
class Server
|
6
|
+
class << self
|
7
|
+
def run!
|
8
|
+
return if running?
|
9
|
+
Thread.new do
|
10
|
+
run_server
|
11
|
+
wait_for_connection
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def port
|
16
|
+
@port ||= Selenium::WebDriver::PortProber.above(8180)
|
17
|
+
end
|
18
|
+
|
19
|
+
def bind
|
20
|
+
@bind ||= Selenium::WebDriver::Platform.windows? ? '127.0.0.1' : '0.0.0.0'
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def running?
|
26
|
+
@running
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_server
|
30
|
+
server = TCPServer.new(bind, port)
|
31
|
+
@running = true
|
32
|
+
loop do
|
33
|
+
Thread.start(server.accept) { |client| accept_client(client) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def wait_for_connection
|
38
|
+
socket_poller = Selenium::WebDriver::SocketPoller.new(bind, port, 30)
|
39
|
+
return if socket_poller.connected?
|
40
|
+
raise 'Cannot start WatirSpec server.'
|
41
|
+
end
|
42
|
+
|
43
|
+
def app
|
44
|
+
@app ||= App.new
|
45
|
+
end
|
46
|
+
|
47
|
+
def accept_client(client)
|
48
|
+
start_line = client.gets
|
49
|
+
return unless start_line
|
50
|
+
|
51
|
+
_, path = start_line.split
|
52
|
+
status, headers, body = app.response(path, read_body(client))
|
53
|
+
headers = prepare_headers(headers, body)
|
54
|
+
|
55
|
+
client.write(response(status, headers, body))
|
56
|
+
rescue Errno::ECONNRESET
|
57
|
+
STDERR.puts 'Client reset connection, skipping.'
|
58
|
+
ensure
|
59
|
+
client.close
|
60
|
+
end
|
61
|
+
|
62
|
+
def read_body(client)
|
63
|
+
request_headers = read_headers(client)
|
64
|
+
client.read(request_headers['Content-Length'].to_i)
|
65
|
+
end
|
66
|
+
|
67
|
+
def read_headers(client)
|
68
|
+
headers = {}
|
69
|
+
while (line = client.gets.split(' ', 2))
|
70
|
+
break if line[0] == ''
|
71
|
+
headers[line[0].chop] = line[1].strip
|
72
|
+
end
|
73
|
+
|
74
|
+
headers
|
75
|
+
end
|
76
|
+
|
77
|
+
def prepare_headers(headers, body)
|
78
|
+
headers = default_headers.merge(headers)
|
79
|
+
headers['Content-Length'] = body.size.to_s
|
80
|
+
headers.to_a.map { |array| array.join(': ') }
|
81
|
+
end
|
82
|
+
|
83
|
+
def default_headers
|
84
|
+
{
|
85
|
+
'Cache-Control' => 'no-cache',
|
86
|
+
'Connection' => 'close',
|
87
|
+
'Content-Type' => 'text/html; charset=UTF-8',
|
88
|
+
'Server' => 'watirspec'
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def response(status, headers, body)
|
93
|
+
response = ["HTTP/1.1 #{status}"] + headers
|
94
|
+
response = response.join("\r\n")
|
95
|
+
response << "\r\n\r\n#{body}\r\n"
|
96
|
+
end
|
97
|
+
end # class << Server
|
98
|
+
end # Server
|
99
|
+
end # WatirSpec
|