watir-webdriver 0.1.4 → 0.1.5
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/.gitignore +9 -0
- data/Gemfile +3 -3
- data/Rakefile +3 -28
- data/lib/watir-webdriver.rb +1 -0
- data/lib/watir-webdriver/version.rb +3 -0
- data/watir-webdriver.gemspec +23 -247
- metadata +34 -326
- data/VERSION +0 -1
- data/spec/watirspec/area_spec.rb +0 -77
- data/spec/watirspec/areas_spec.rb +0 -45
- data/spec/watirspec/browser_spec.rb +0 -274
- data/spec/watirspec/button_spec.rb +0 -255
- data/spec/watirspec/buttons_spec.rb +0 -58
- data/spec/watirspec/checkbox_spec.rb +0 -276
- data/spec/watirspec/checkboxes_spec.rb +0 -47
- data/spec/watirspec/collections_spec.rb +0 -20
- data/spec/watirspec/dd_spec.rb +0 -127
- data/spec/watirspec/dds_spec.rb +0 -45
- data/spec/watirspec/del_spec.rb +0 -145
- data/spec/watirspec/dels_spec.rb +0 -45
- data/spec/watirspec/div_spec.rb +0 -221
- data/spec/watirspec/divs_spec.rb +0 -45
- data/spec/watirspec/dl_spec.rb +0 -137
- data/spec/watirspec/dls_spec.rb +0 -46
- data/spec/watirspec/dt_spec.rb +0 -127
- data/spec/watirspec/dts_spec.rb +0 -45
- data/spec/watirspec/element_spec.rb +0 -149
- data/spec/watirspec/em_spec.rb +0 -101
- data/spec/watirspec/ems_spec.rb +0 -46
- data/spec/watirspec/filefield_spec.rb +0 -156
- data/spec/watirspec/filefields_spec.rb +0 -46
- data/spec/watirspec/font_spec.rb +0 -32
- data/spec/watirspec/form_spec.rb +0 -63
- data/spec/watirspec/forms_spec.rb +0 -47
- data/spec/watirspec/frame_spec.rb +0 -144
- data/spec/watirspec/frames_spec.rb +0 -83
- data/spec/watirspec/hidden_spec.rb +0 -103
- data/spec/watirspec/hiddens_spec.rb +0 -46
- data/spec/watirspec/hn_spec.rb +0 -97
- data/spec/watirspec/hns_spec.rb +0 -42
- data/spec/watirspec/image_spec.rb +0 -208
- data/spec/watirspec/images_spec.rb +0 -45
- data/spec/watirspec/ins_spec.rb +0 -146
- data/spec/watirspec/inses_spec.rb +0 -45
- data/spec/watirspec/label_spec.rb +0 -81
- data/spec/watirspec/labels_spec.rb +0 -45
- data/spec/watirspec/li_spec.rb +0 -116
- data/spec/watirspec/lib/guards.rb +0 -59
- data/spec/watirspec/lib/implementation.rb +0 -48
- data/spec/watirspec/lib/runner.rb +0 -83
- data/spec/watirspec/lib/server.rb +0 -194
- data/spec/watirspec/lib/watirspec.rb +0 -75
- data/spec/watirspec/link_spec.rb +0 -174
- data/spec/watirspec/links_spec.rb +0 -49
- data/spec/watirspec/lis_spec.rb +0 -45
- data/spec/watirspec/map_spec.rb +0 -80
- data/spec/watirspec/maps_spec.rb +0 -46
- data/spec/watirspec/meta_spec.rb +0 -24
- data/spec/watirspec/metas_spec.rb +0 -43
- data/spec/watirspec/ol_spec.rb +0 -90
- data/spec/watirspec/ols_spec.rb +0 -45
- data/spec/watirspec/option_spec.rb +0 -152
- data/spec/watirspec/p_spec.rb +0 -132
- data/spec/watirspec/pre_spec.rb +0 -116
- data/spec/watirspec/pres_spec.rb +0 -45
- data/spec/watirspec/ps_spec.rb +0 -45
- data/spec/watirspec/radio_spec.rb +0 -262
- data/spec/watirspec/radios_spec.rb +0 -46
- data/spec/watirspec/select_list_spec.rb +0 -335
- data/spec/watirspec/select_lists_spec.rb +0 -49
- data/spec/watirspec/span_spec.rb +0 -146
- data/spec/watirspec/spans_spec.rb +0 -45
- data/spec/watirspec/spec_helper.rb +0 -20
- data/spec/watirspec/strong_spec.rb +0 -93
- data/spec/watirspec/strongs_spec.rb +0 -46
- data/spec/watirspec/table_nesting_spec.rb +0 -50
- data/spec/watirspec/table_spec.rb +0 -150
- data/spec/watirspec/tables_spec.rb +0 -47
- data/spec/watirspec/tbody_spec.rb +0 -97
- data/spec/watirspec/tbodys_spec.rb +0 -65
- data/spec/watirspec/td_spec.rb +0 -72
- data/spec/watirspec/tds_spec.rb +0 -60
- data/spec/watirspec/text_field_spec.rb +0 -283
- data/spec/watirspec/text_fields_spec.rb +0 -49
- data/spec/watirspec/tfoot_spec.rb +0 -92
- data/spec/watirspec/tfoots_spec.rb +0 -71
- data/spec/watirspec/thead_spec.rb +0 -92
- data/spec/watirspec/theads_spec.rb +0 -71
- data/spec/watirspec/tr_spec.rb +0 -88
- data/spec/watirspec/trs_spec.rb +0 -68
- data/spec/watirspec/ul_spec.rb +0 -80
- data/spec/watirspec/uls_spec.rb +0 -44
- data/spec/watirspec/window_switching_spec.rb +0 -164
@@ -1,81 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path("../spec_helper", __FILE__)
|
3
|
-
|
4
|
-
describe "Label" do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
8
|
-
end
|
9
|
-
|
10
|
-
# Exists method
|
11
|
-
describe "#exists?" do
|
12
|
-
it "returns true if the element exists" do
|
13
|
-
browser.label(:id, 'first_label').should exist
|
14
|
-
browser.label(:id, /first_label/).should exist
|
15
|
-
browser.label(:for, "new_user_first_name").should exist
|
16
|
-
browser.label(:for, /new_user_first_name/).should exist
|
17
|
-
browser.label(:text, 'First name').should exist
|
18
|
-
browser.label(:text, /First name/).should exist
|
19
|
-
browser.label(:index, 0).should exist
|
20
|
-
browser.label(:xpath, "//label[@id='first_label']").should exist
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns the first label if given no args" do
|
24
|
-
browser.label.should exist
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns false if the element does not exist" do
|
28
|
-
browser.label(:id, 'no_such_id').should_not exist
|
29
|
-
browser.label(:id, /no_such_id/).should_not exist
|
30
|
-
browser.label(:text, 'no_such_text').should_not exist
|
31
|
-
browser.label(:text, /no_such_text/).should_not exist
|
32
|
-
browser.label(:index, 1337).should_not exist
|
33
|
-
browser.label(:xpath, "//input[@id='no_such_id']").should_not exist
|
34
|
-
end
|
35
|
-
|
36
|
-
it "raises TypeError when 'what' argument is invalid" do
|
37
|
-
lambda { browser.label(:id, 3.14).exists? }.should raise_error(TypeError)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
41
|
-
lambda { browser.label(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "click" do
|
46
|
-
it "fires the onclick event" do
|
47
|
-
browser.label(:id, 'first_label').click
|
48
|
-
messages.first.should == 'label'
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Attribute methods
|
53
|
-
describe "#id" do
|
54
|
-
it "returns the id attribute if the label exists" do
|
55
|
-
browser.label(:index, 0).id.should == "first_label"
|
56
|
-
end
|
57
|
-
|
58
|
-
it "raises UnknownObjectException if the label doesn't exist" do
|
59
|
-
lambda { browser.label(:index, 1337).id }.should raise_error(UnknownObjectException)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#for" do
|
64
|
-
it "returns the 'for' attribute if the label exists" do
|
65
|
-
browser.label(:index, 0).for.should == "new_user_first_name"
|
66
|
-
end
|
67
|
-
|
68
|
-
it "raises UnknownObjectException if the label doesn't exist" do
|
69
|
-
lambda { browser.label(:index, 1337).for }.should raise_error(UnknownObjectException)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#respond_to?" do
|
74
|
-
it "returns true for all attribute methods" do
|
75
|
-
browser.label(:index, 0).should respond_to(:id)
|
76
|
-
browser.label(:index, 0).should respond_to(:for)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path("../spec_helper", __FILE__)
|
3
|
-
|
4
|
-
describe "Labels" do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
8
|
-
end
|
9
|
-
|
10
|
-
bug "http://github.com/jarib/celerity/issues#issue/25", :celerity do
|
11
|
-
describe "with selectors" do
|
12
|
-
it "returns the matching elements" do
|
13
|
-
browser.labels(:for => "new_user_first_name").to_a.should == [browser.label(:for => "new_user_first_name")]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#length" do
|
19
|
-
it "returns the number of labels" do
|
20
|
-
browser.labels.length.should == 26 # changed this from 25 - Jari
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#[]" do
|
25
|
-
it "returns the label at the given index" do
|
26
|
-
browser.labels[0].id.should == "first_label"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#each" do
|
31
|
-
it "iterates through labels correctly" do
|
32
|
-
count = 0
|
33
|
-
|
34
|
-
browser.labels.each_with_index do |l, index|
|
35
|
-
l.id.should == browser.label(:index, index).id
|
36
|
-
l.value.should == browser.label(:index, index).value
|
37
|
-
|
38
|
-
count += 1
|
39
|
-
end
|
40
|
-
|
41
|
-
count.should > 0
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/spec/watirspec/li_spec.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path("../spec_helper", __FILE__)
|
3
|
-
|
4
|
-
describe "Li" do
|
5
|
-
|
6
|
-
before :each do
|
7
|
-
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
8
|
-
end
|
9
|
-
|
10
|
-
# Exists method
|
11
|
-
describe "#exist?" do
|
12
|
-
it "returns true if the 'li' exists" do
|
13
|
-
browser.li(:id, "non_link_1").should exist
|
14
|
-
browser.li(:id, /non_link_1/).should exist
|
15
|
-
browser.li(:text, "Non-link 3").should exist
|
16
|
-
browser.li(:text, /Non-link 3/).should exist
|
17
|
-
browser.li(:class, "nonlink").should exist
|
18
|
-
browser.li(:class, /nonlink/).should exist
|
19
|
-
browser.li(:index, 0).should exist
|
20
|
-
browser.li(:xpath, "//li[@id='non_link_1']").should exist
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns the first element if given no args" do
|
24
|
-
browser.li.should exist
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns false if the 'li' doesn't exist" do
|
28
|
-
browser.li(:id, "no_such_id").should_not exist
|
29
|
-
browser.li(:id, /no_such_id/).should_not exist
|
30
|
-
browser.li(:text, "no_such_text").should_not exist
|
31
|
-
browser.li(:text, /no_such_text/).should_not exist
|
32
|
-
browser.li(:class, "no_such_class").should_not exist
|
33
|
-
browser.li(:class, /no_such_class/).should_not exist
|
34
|
-
browser.li(:index, 1337).should_not exist
|
35
|
-
browser.li(:xpath, "//li[@id='no_such_id']").should_not exist
|
36
|
-
end
|
37
|
-
|
38
|
-
it "raises TypeError when 'what' argument is invalid" do
|
39
|
-
lambda { browser.li(:id, 3.14).exists? }.should raise_error(TypeError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
43
|
-
lambda { browser.li(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Attribute methods
|
48
|
-
describe "#class_name" do
|
49
|
-
it "returns the class attribute" do
|
50
|
-
browser.li(:id, 'non_link_1').class_name.should == 'nonlink'
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns an empty string if the element exists and the attribute doesn't" do
|
54
|
-
browser.li(:index, 0).class_name.should == ''
|
55
|
-
end
|
56
|
-
|
57
|
-
it "raises UnknownObjectException if the li doesn't exist" do
|
58
|
-
lambda { browser.li(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "#id" do
|
63
|
-
it "returns the id attribute" do
|
64
|
-
browser.li(:class, 'nonlink').id.should == "non_link_1"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "returns an empty string if the element exists and the attribute doesn't" do
|
68
|
-
browser.li(:index, 0).id.should == ''
|
69
|
-
end
|
70
|
-
|
71
|
-
it "raises UnknownObjectException if the li doesn't exist" do
|
72
|
-
lambda { browser.li(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
|
73
|
-
lambda { browser.li(:index, 1337).id }.should raise_error(UnknownObjectException)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#title" do
|
78
|
-
it "returns the title attribute" do
|
79
|
-
browser.li(:id, 'non_link_1').title.should == 'This is not a link!'
|
80
|
-
end
|
81
|
-
|
82
|
-
it "returns an empty string if the element exists and the attribute doesn't" do
|
83
|
-
browser.li(:index, 0).title.should == ''
|
84
|
-
end
|
85
|
-
|
86
|
-
it "raises UnknownObjectException if the li doesn't exist" do
|
87
|
-
lambda { browser.li(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
|
88
|
-
lambda { browser.li(:xpath, "//li[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "#text" do
|
93
|
-
it "returns the text of the li" do
|
94
|
-
browser.li(:id, 'non_link_1').text.should == 'Non-link 1'
|
95
|
-
end
|
96
|
-
|
97
|
-
it "returns an empty string if the element doesn't contain any text" do
|
98
|
-
browser.li(:index, 0).text.should == ''
|
99
|
-
end
|
100
|
-
|
101
|
-
it "raises UnknownObjectException if the li doesn't exist" do
|
102
|
-
lambda { browser.li(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
|
103
|
-
lambda { browser.li(:xpath , "//li[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe "#respond_to?" do
|
108
|
-
it "returns true for all attribute methods" do
|
109
|
-
browser.li(:index, 0).should respond_to(:class_name)
|
110
|
-
browser.li(:index, 0).should respond_to(:id)
|
111
|
-
browser.li(:index, 0).should respond_to(:text)
|
112
|
-
browser.li(:index, 0).should respond_to(:title)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module WatirSpec
|
3
|
-
module Guards
|
4
|
-
|
5
|
-
class << self
|
6
|
-
def guards
|
7
|
-
@guards ||= Hash.new { |hash, key| hash[key] = [] }
|
8
|
-
end
|
9
|
-
|
10
|
-
def record(guard_name, impls, data)
|
11
|
-
guards[impls] << {:name => guard_name, :data => data}
|
12
|
-
end
|
13
|
-
|
14
|
-
def report
|
15
|
-
gs = WatirSpec.implementation.matching_guards_in(guards)
|
16
|
-
print "\n\nWatirSpec guards for this implementation: "
|
17
|
-
|
18
|
-
if gs.empty?
|
19
|
-
puts "none."
|
20
|
-
else
|
21
|
-
puts
|
22
|
-
gs.each do |guard|
|
23
|
-
puts "\t#{guard[:name].to_s.ljust(20)}: #{guard[:data].inspect}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end # class << self
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def deviates_on(*impls)
|
32
|
-
Guards.record :deviates, impls, :file => caller.first
|
33
|
-
return yield if WatirSpec.unguarded?
|
34
|
-
yield if WatirSpec.implementation.matches_guard?(impls)
|
35
|
-
end
|
36
|
-
|
37
|
-
def not_compliant_on(*impls)
|
38
|
-
Guards.record :not_compliant, impls, :file => caller.first
|
39
|
-
return yield if WatirSpec.unguarded?
|
40
|
-
yield unless WatirSpec.implementation.matches_guard?(impls)
|
41
|
-
end
|
42
|
-
|
43
|
-
def compliant_on(*impls)
|
44
|
-
Guards.record :compliant, impls, :file => caller.first
|
45
|
-
return yield if WatirSpec.unguarded?
|
46
|
-
yield if WatirSpec.implementation.matches_guard?(impls)
|
47
|
-
end
|
48
|
-
|
49
|
-
def bug(key, *impls)
|
50
|
-
Guards.record :bug, impls, :file => caller.first, :key => key
|
51
|
-
return yield if WatirSpec.unguarded?
|
52
|
-
yield unless WatirSpec.implementation.matches_guard?(impls)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class Object
|
58
|
-
include WatirSpec::Guards
|
59
|
-
end
|
@@ -1,48 +0,0 @@
|
|
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
|
34
|
-
|
35
|
-
if __FILE__ == $0
|
36
|
-
require "rubygems"
|
37
|
-
require 'spec/autorun'
|
38
|
-
|
39
|
-
describe WatirSpec::Implementation do
|
40
|
-
before { @impl = WatirSpec::Implementation.new }
|
41
|
-
|
42
|
-
it "finds matching guards" do
|
43
|
-
guards = {[:watir]=>[{:name=>:not_compliant, :data=>{:file=>"./spec/watirspec/div_spec.rb:108"}}, {:name=>:deviates, :data=>{:file=>"./spec/watirspec/div_spec.rb:114"}}, {:name=>:not_compliant, :data=>{:file=>"./spec/watirspec/div_spec.rb:200"}}, {:name=>:bug, :data=>{:file=>"./spec/watirspec/div_spec.rb:228", :key=>"WTR-350"}}], [:celerity]=>[{:name=>:deviates, :data=>{:file=>"./spec/watirspec/div_spec.rb:143"}}]}
|
44
|
-
@impl.name = :celerity
|
45
|
-
@impl.matching_guards_in(guards).should == [{:name => :deviates, :data => {:file=>"./spec/watirspec/div_spec.rb:143"}}]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module WatirSpec
|
3
|
-
module Runner
|
4
|
-
|
5
|
-
module BrowserHelper
|
6
|
-
def browser; @browser; end
|
7
|
-
end
|
8
|
-
|
9
|
-
module PersistentBrowserHelper
|
10
|
-
def browser; $browser; end
|
11
|
-
end
|
12
|
-
|
13
|
-
module MessagesHelper
|
14
|
-
def messages
|
15
|
-
browser.div(:id, 'messages').divs.map { |d| d.text }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module_function
|
20
|
-
|
21
|
-
def execute
|
22
|
-
load_requires
|
23
|
-
start_server
|
24
|
-
configure
|
25
|
-
add_guard_hook
|
26
|
-
|
27
|
-
@executed = true
|
28
|
-
end
|
29
|
-
|
30
|
-
def execute_if_necessary
|
31
|
-
execute unless @exectued
|
32
|
-
end
|
33
|
-
|
34
|
-
def configure
|
35
|
-
Thread.abort_on_exception = true
|
36
|
-
|
37
|
-
RSpec.configure do |config|
|
38
|
-
config.include(MessagesHelper)
|
39
|
-
|
40
|
-
if WatirSpec.persistent_browser == false
|
41
|
-
config.include(BrowserHelper)
|
42
|
-
|
43
|
-
config.before(:all) { @browser = WatirSpec.new_browser }
|
44
|
-
config.after(:all) { @browser.close if @browser }
|
45
|
-
else
|
46
|
-
config.include(PersistentBrowserHelper)
|
47
|
-
$browser = WatirSpec.new_browser
|
48
|
-
at_exit { $browser.close }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def load_requires
|
54
|
-
require "rspec"
|
55
|
-
require "fileutils"
|
56
|
-
|
57
|
-
implementation = File.expand_path("../../../implementation.rb", __FILE__)
|
58
|
-
load implementation
|
59
|
-
|
60
|
-
begin
|
61
|
-
require "ruby-debug"
|
62
|
-
Debugger.start
|
63
|
-
Debugger.settings[:autoeval] = true
|
64
|
-
Debugger.settings[:autolist] = 1
|
65
|
-
rescue LoadError
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def start_server
|
70
|
-
if WatirSpec::Server.should_run?
|
71
|
-
WatirSpec::Server.run_async
|
72
|
-
else
|
73
|
-
$stderr.puts "not running WatirSpec::Server"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def add_guard_hook
|
78
|
-
return if WatirSpec.unguarded?
|
79
|
-
at_exit { WatirSpec::Guards.report }
|
80
|
-
end
|
81
|
-
|
82
|
-
end # SpecHelper
|
83
|
-
end # WatirSpec
|
@@ -1,194 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "socket"
|
4
|
-
|
5
|
-
module WatirSpec
|
6
|
-
class Server < Sinatra::Base
|
7
|
-
class << self
|
8
|
-
attr_accessor :autorun
|
9
|
-
|
10
|
-
def run_async
|
11
|
-
case WatirSpec.platform
|
12
|
-
when :java
|
13
|
-
Thread.new { run! }
|
14
|
-
sleep 0.1 until WatirSpec::Server.running?
|
15
|
-
when :windows
|
16
|
-
run_in_child_process
|
17
|
-
else
|
18
|
-
pid = fork { run! }
|
19
|
-
sleep 0.5 until listening?
|
20
|
-
end
|
21
|
-
|
22
|
-
if pid
|
23
|
-
# is this really necessary?
|
24
|
-
at_exit {
|
25
|
-
begin
|
26
|
-
Process.kill 0, pid
|
27
|
-
alive = true
|
28
|
-
rescue Errno::ESRCH
|
29
|
-
alive = false
|
30
|
-
end
|
31
|
-
|
32
|
-
Process.kill(9, pid) if alive
|
33
|
-
}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def run!
|
38
|
-
handler = detect_rack_handler
|
39
|
-
handler.run(self, :Host => bind, :Port => port) { @running = true }
|
40
|
-
end
|
41
|
-
|
42
|
-
def listening?
|
43
|
-
$stderr.puts "trying #{bind}:#{port}..."
|
44
|
-
|
45
|
-
TCPSocket.new(bind, port).close
|
46
|
-
true
|
47
|
-
rescue
|
48
|
-
false
|
49
|
-
end
|
50
|
-
|
51
|
-
def find_free_port_above(int)
|
52
|
-
port = int
|
53
|
-
|
54
|
-
until free_port?(port)
|
55
|
-
port += 1
|
56
|
-
end
|
57
|
-
|
58
|
-
port
|
59
|
-
end
|
60
|
-
|
61
|
-
def autorun
|
62
|
-
@autorun ||= true
|
63
|
-
end
|
64
|
-
|
65
|
-
def should_run?
|
66
|
-
autorun && !running?
|
67
|
-
end
|
68
|
-
|
69
|
-
def running?
|
70
|
-
defined?(@running) && @running
|
71
|
-
end
|
72
|
-
|
73
|
-
SOCKET_ERRORS = [Errno::EADDRINUSE]
|
74
|
-
SOCKET_ERRORS << SocketError if defined?(SocketError) # ruby versions...
|
75
|
-
|
76
|
-
def free_port?(port)
|
77
|
-
s = TCPServer.new(@host, port)
|
78
|
-
s.close
|
79
|
-
true
|
80
|
-
rescue *SOCKET_ERRORS
|
81
|
-
false
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def run_in_child_process
|
87
|
-
begin
|
88
|
-
require "childprocess"
|
89
|
-
rescue LoadError => ex
|
90
|
-
raise "please run `gem install childprocess` for WatirSpec on Windows + MRI\n\t(caught: #{ex.message})"
|
91
|
-
end
|
92
|
-
|
93
|
-
path = File.expand_path("../../spec_helper.rb", __FILE__)
|
94
|
-
|
95
|
-
process = ChildProcess.build(WatirSpec.ruby, path)
|
96
|
-
process.io.inherit! if $DEBUG
|
97
|
-
process.start
|
98
|
-
|
99
|
-
at_exit { process.stop }
|
100
|
-
end
|
101
|
-
end # class << Server
|
102
|
-
|
103
|
-
set :public, WatirSpec.html
|
104
|
-
set :static, true
|
105
|
-
set :run, false
|
106
|
-
set :environment, :production
|
107
|
-
set :bind, "localhost" if WatirSpec.platform == :windows
|
108
|
-
set :port, find_free_port_above(2000)
|
109
|
-
set :server, %w[mongrel webrick]
|
110
|
-
|
111
|
-
get '/' do
|
112
|
-
self.class.name
|
113
|
-
end
|
114
|
-
|
115
|
-
class BigContent
|
116
|
-
def each(&blk)
|
117
|
-
yield "<html><head><title>Big Content</title></head><body>"
|
118
|
-
|
119
|
-
string = "hello"*205
|
120
|
-
|
121
|
-
300.times do
|
122
|
-
yield string
|
123
|
-
end
|
124
|
-
|
125
|
-
yield "</body></html>"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
get '/big' do
|
130
|
-
BigContent.new
|
131
|
-
end
|
132
|
-
|
133
|
-
post '/post_to_me' do
|
134
|
-
"You posted the following content:\n#{ env['rack.input'].read }"
|
135
|
-
end
|
136
|
-
|
137
|
-
get '/plain_text' do
|
138
|
-
content_type 'text/plain'
|
139
|
-
'This is text/plain'
|
140
|
-
end
|
141
|
-
|
142
|
-
get '/ajax' do
|
143
|
-
sleep 10
|
144
|
-
"A slooow ajax response"
|
145
|
-
end
|
146
|
-
|
147
|
-
get '/charset_mismatch' do
|
148
|
-
content_type 'text/html; charset=UTF-8'
|
149
|
-
%{
|
150
|
-
<html>
|
151
|
-
<head>
|
152
|
-
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
|
153
|
-
</head>
|
154
|
-
<body>
|
155
|
-
<h1>ø</h1>
|
156
|
-
</body>
|
157
|
-
</html>
|
158
|
-
}
|
159
|
-
end
|
160
|
-
|
161
|
-
get '/octet_stream' do
|
162
|
-
content_type 'application/octet-stream'
|
163
|
-
'This is application/octet-stream'
|
164
|
-
end
|
165
|
-
|
166
|
-
get '/set_cookie' do
|
167
|
-
content_type 'text/plain'
|
168
|
-
headers 'Set-Cookie' => "monster=/"
|
169
|
-
|
170
|
-
"C is for cookie, it's good enough for me"
|
171
|
-
end
|
172
|
-
|
173
|
-
get '/header_echo' do
|
174
|
-
content_type 'text/plain'
|
175
|
-
env.inspect
|
176
|
-
end
|
177
|
-
|
178
|
-
get '/authentication' do
|
179
|
-
auth = Rack::Auth::Basic::Request.new(env)
|
180
|
-
|
181
|
-
unless auth.provided? && auth.credentials == %w[foo bar]
|
182
|
-
headers 'WWW-Authenticate' => %(Basic realm="localhost")
|
183
|
-
halt 401, 'Authorization Required'
|
184
|
-
end
|
185
|
-
|
186
|
-
"ok"
|
187
|
-
end
|
188
|
-
|
189
|
-
get '/encodable_<stuff>' do
|
190
|
-
'page with characters in URI that need encoding'
|
191
|
-
end
|
192
|
-
|
193
|
-
end # Server
|
194
|
-
end # WatirSpec
|