watir-webdriver 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +48 -0
  3. data/Rakefile +23 -8
  4. data/VERSION +1 -1
  5. data/lib/watir-webdriver.rb +7 -5
  6. data/lib/watir-webdriver/browser.rb +9 -2
  7. data/lib/watir-webdriver/browserbot.js +5 -2
  8. data/lib/watir-webdriver/container.rb +6 -9
  9. data/lib/watir-webdriver/{collections/element_collection.rb → element_collection.rb} +5 -0
  10. data/lib/watir-webdriver/elements/button.rb +5 -4
  11. data/lib/watir-webdriver/{element.rb → elements/element.rb} +29 -5
  12. data/lib/watir-webdriver/elements/file_field.rb +21 -4
  13. data/lib/watir-webdriver/elements/frame.rb +1 -1
  14. data/lib/watir-webdriver/elements/generated.rb +750 -750
  15. data/lib/watir-webdriver/elements/image.rb +6 -0
  16. data/lib/watir-webdriver/elements/link.rb +0 -4
  17. data/lib/watir-webdriver/elements/select.rb +22 -24
  18. data/lib/watir-webdriver/elements/table_row.rb +11 -1
  19. data/lib/watir-webdriver/elements/text_field.rb +5 -15
  20. data/lib/watir-webdriver/extensions/wait.rb +107 -0
  21. data/lib/watir-webdriver/html/generator.rb +1 -1
  22. data/lib/watir-webdriver/html/util.rb +1 -10
  23. data/lib/watir-webdriver/html/visitor.rb +2 -14
  24. data/lib/watir-webdriver/locators/button_locator.rb +22 -3
  25. data/lib/watir-webdriver/locators/element_locator.rb +54 -28
  26. data/lib/watir-webdriver/locators/table_row_locator.rb +3 -1
  27. data/lib/watir-webdriver/locators/text_field_locator.rb +7 -3
  28. data/lib/watir-webdriver/window_switching.rb +78 -0
  29. data/spec/browser_spec.rb +43 -0
  30. data/spec/container_spec.rb +43 -0
  31. data/spec/element_locator_spec.rb +305 -0
  32. data/spec/element_spec.rb +34 -5
  33. data/spec/html/closeable.html +13 -0
  34. data/spec/html/data_attributes.html +9 -0
  35. data/spec/html/wait.html +27 -0
  36. data/spec/html/window_switching.html +12 -0
  37. data/spec/input_spec.rb +14 -2
  38. data/spec/locator_spec_helper.rb +37 -0
  39. data/spec/spec_helper.rb +3 -0
  40. data/spec/wait_spec.rb +98 -0
  41. data/spec/watirspec/area_spec.rb +4 -4
  42. data/spec/watirspec/browser_spec.rb +37 -35
  43. data/spec/watirspec/button_spec.rb +22 -17
  44. data/spec/watirspec/buttons_spec.rb +1 -1
  45. data/spec/watirspec/checkbox_spec.rb +4 -0
  46. data/spec/watirspec/checkboxes_spec.rb +1 -1
  47. data/spec/watirspec/collections_spec.rb +4 -2
  48. data/spec/watirspec/dd_spec.rb +4 -0
  49. data/spec/watirspec/dds_spec.rb +1 -1
  50. data/spec/watirspec/del_spec.rb +4 -0
  51. data/spec/watirspec/dels_spec.rb +1 -1
  52. data/spec/watirspec/div_spec.rb +38 -12
  53. data/spec/watirspec/divs_spec.rb +1 -1
  54. data/spec/watirspec/dl_spec.rb +20 -6
  55. data/spec/watirspec/dls_spec.rb +1 -1
  56. data/spec/watirspec/dt_spec.rb +4 -0
  57. data/spec/watirspec/dts_spec.rb +1 -1
  58. data/spec/watirspec/em_spec.rb +4 -0
  59. data/spec/watirspec/ems_spec.rb +1 -1
  60. data/spec/watirspec/filefield_spec.rb +37 -2
  61. data/spec/watirspec/filefields_spec.rb +1 -1
  62. data/spec/watirspec/font_spec.rb +4 -0
  63. data/spec/watirspec/form_spec.rb +4 -0
  64. data/spec/watirspec/forms_spec.rb +6 -4
  65. data/spec/watirspec/frame_spec.rb +6 -0
  66. data/spec/watirspec/hidden_spec.rb +5 -4
  67. data/spec/watirspec/hiddens_spec.rb +1 -1
  68. data/spec/watirspec/hn_spec.rb +4 -0
  69. data/spec/watirspec/image_spec.rb +4 -0
  70. data/spec/watirspec/images_spec.rb +1 -1
  71. data/spec/watirspec/ins_spec.rb +4 -0
  72. data/spec/watirspec/inses_spec.rb +1 -1
  73. data/spec/watirspec/label_spec.rb +4 -0
  74. data/spec/watirspec/labels_spec.rb +2 -2
  75. data/spec/watirspec/li_spec.rb +4 -0
  76. data/spec/watirspec/link_spec.rb +15 -10
  77. data/spec/watirspec/links_spec.rb +6 -0
  78. data/spec/watirspec/lis_spec.rb +1 -1
  79. data/spec/watirspec/map_spec.rb +4 -0
  80. data/spec/watirspec/maps_spec.rb +1 -1
  81. data/spec/watirspec/meta_spec.rb +4 -0
  82. data/spec/watirspec/metas_spec.rb +1 -1
  83. data/spec/watirspec/ol_spec.rb +23 -9
  84. data/spec/watirspec/option_spec.rb +19 -7
  85. data/spec/watirspec/p_spec.rb +4 -0
  86. data/spec/watirspec/pre_spec.rb +4 -0
  87. data/spec/watirspec/pres_spec.rb +1 -1
  88. data/spec/watirspec/ps_spec.rb +1 -1
  89. data/spec/watirspec/radio_spec.rb +22 -13
  90. data/spec/watirspec/radios_spec.rb +6 -0
  91. data/spec/watirspec/select_list_spec.rb +29 -17
  92. data/spec/watirspec/select_lists_spec.rb +6 -0
  93. data/spec/watirspec/span_spec.rb +10 -2
  94. data/spec/watirspec/spans_spec.rb +1 -1
  95. data/spec/watirspec/strong_spec.rb +14 -4
  96. data/spec/watirspec/table_body_spec.rb +4 -0
  97. data/spec/watirspec/table_cell_spec.rb +9 -3
  98. data/spec/watirspec/table_cells_spec.rb +0 -1
  99. data/spec/watirspec/table_footer_spec.rb +4 -0
  100. data/spec/watirspec/table_header_spec.rb +4 -0
  101. data/spec/watirspec/table_row_spec.rb +15 -7
  102. data/spec/watirspec/table_rows_spec.rb +2 -2
  103. data/spec/watirspec/table_spec.rb +13 -7
  104. data/spec/watirspec/tables_spec.rb +1 -1
  105. data/spec/watirspec/text_field_spec.rb +21 -12
  106. data/spec/watirspec/text_fields_spec.rb +6 -0
  107. data/spec/watirspec/ul_spec.rb +4 -0
  108. data/spec/window_switching_spec.rb +116 -0
  109. data/watir-webdriver.gemspec +38 -16
  110. metadata +51 -27
  111. data/lib/watir-webdriver/collections/table_row_collection.rb +0 -11
@@ -40,7 +40,7 @@ describe "Buttons" do
40
40
  b.id.should == browser.button(:index, index).id
41
41
  b.value.should == browser.button(:index, index).value
42
42
 
43
- count += 1
43
+ count += 1
44
44
  end
45
45
 
46
46
  count.should > 0
@@ -31,6 +31,10 @@ describe "CheckBox" do
31
31
  browser.checkbox(:xpath, "//input[@name='new_user_interests' and @value='cars']").set
32
32
  end
33
33
 
34
+ it "returns the first checkbox if given no args" do
35
+ browser.checkbox.should exist
36
+ end
37
+
34
38
  it "returns false if the checkbox button does not exist" do
35
39
  browser.checkbox(:id, "no_such_id").should_not exist
36
40
  browser.checkbox(:id, /no_such_id/).should_not exist
@@ -28,7 +28,7 @@ describe "CheckBoxes" do
28
28
  c.id.should == browser.checkbox(:index, index).id
29
29
  c.value.should == browser.checkbox(:index, index).value
30
30
 
31
- count += 1
31
+ count += 1
32
32
  end
33
33
 
34
34
  count.should > 0
@@ -11,8 +11,10 @@ describe "Collections" do
11
11
  browser.span(:id => "a_span").divs.size.should == 2
12
12
  end
13
13
 
14
- it "returns inner elements of parent element having same html tag" do
15
- browser.span(:id => "a_span").spans.size.should == 2
14
+ bug "http://code.google.com/p/selenium/issues/detail?id=695", [:webdriver, :ie] do
15
+ it "returns inner elements of parent element having same html tag" do
16
+ browser.span(:id => "a_span").spans.size.should == 2
17
+ end
16
18
  end
17
19
 
18
20
  end
@@ -16,6 +16,10 @@ describe "Dd" do
16
16
  browser.dd(:index, 0).should exist
17
17
  end
18
18
 
19
+ it "returns the first dd if given no args" do
20
+ browser.dd.should exist
21
+ end
22
+
19
23
  it "returns false if the element does not exist" do
20
24
  browser.dd(:id, "no_such_id").should_not exist
21
25
  end
@@ -27,7 +27,7 @@ describe "Dds" do
27
27
  d.id.should == browser.dd(:index, index).id
28
28
  d.class_name.should == browser.dd(:index, index).class_name
29
29
 
30
- count += 1
30
+ count += 1
31
31
  end
32
32
 
33
33
  count.should > 0
@@ -20,6 +20,10 @@ describe "Del" do
20
20
  browser.del(:xpath, "//del[@id='lead']").should exist
21
21
  end
22
22
 
23
+ it "returns the first del if given no args" do
24
+ browser.del.should exist
25
+ end
26
+
23
27
  it "returns false if the element doesn't exist" do
24
28
  browser.del(:id, "no_such_id").should_not exist
25
29
  browser.del(:id, /no_such_id/).should_not exist
@@ -27,7 +27,7 @@ describe "Dels" do
27
27
  s.id.should == browser.del(:index, index).id
28
28
  s.value.should == browser.del(:index, index).value
29
29
 
30
- count += 1
30
+ count += 1
31
31
  end
32
32
 
33
33
  count.should > 0
@@ -22,6 +22,10 @@ describe "Div" do
22
22
  browser.div(:xpath, "//div[@id='header']").should exist
23
23
  end
24
24
 
25
+ it "returns the first div if given no args" do
26
+ browser.div.should exist
27
+ end
28
+
25
29
  it "returns false if the element does not exist" do
26
30
  browser.div(:id, "no_such_id").should_not exist
27
31
  browser.div(:id, /no_such_id/).should_not exist
@@ -48,11 +52,11 @@ describe "Div" do
48
52
  # Attribute methods
49
53
  describe "#class_name" do
50
54
  it "returns the class attribute if the element exists" do
51
- browser.div(:id , "footer").class_name.should == "profile"
55
+ browser.div(:id, "footer").class_name.should == "profile"
52
56
  end
53
57
 
54
58
  it "returns an empty string if the element exists but the attribute doesn't" do
55
- browser.div(:id , "content").class_name.should == ""
59
+ browser.div(:id, "content").class_name.should == ""
56
60
  end
57
61
 
58
62
  it "raises UnknownObjectException if the element does not exist" do
@@ -85,8 +89,16 @@ describe "Div" do
85
89
  end
86
90
 
87
91
  describe "#style" do
88
- it "returns the style attribute if the element exists" do
89
- browser.div(:id, 'best_language').style.should == "color: red; text-decoration: underline; cursor: pointer;"
92
+ not_compliant_on [:webdriver, :ie] do
93
+ it "returns the style attribute if the element exists" do
94
+ browser.div(:id, 'best_language').style.should == "color: red; text-decoration: underline; cursor: pointer;"
95
+ end
96
+ end
97
+
98
+ deviates_on [:webdriver, :ie] do
99
+ it "returns the style attribute if the element exists" do
100
+ browser.div(:id, 'best_language').style.should == "COLOR: red; CURSOR: pointer; TEXT-DECORATION: underline"
101
+ end
90
102
  end
91
103
 
92
104
  it "returns an empty string if the element exists but the attribute doesn't" do
@@ -181,14 +193,28 @@ describe "Div" do
181
193
  end
182
194
 
183
195
  describe "#html" do
184
- it "returns the HTML of the element" do
185
- html = browser.div(:id, 'footer').html.downcase
186
- html.should include('id="footer"')
187
- html.should include('title="closing remarks"')
188
- html.should include('class="profile"')
189
-
190
- html.should_not include('<div id="content">')
191
- html.should_not include('</body>')
196
+ not_compliant_on [:webdriver, :ie] do
197
+ it "returns the HTML of the element" do
198
+ html = browser.div(:id, 'footer').html.downcase
199
+ html.should include('id="footer"')
200
+ html.should include('title="closing remarks"')
201
+ html.should include('class="profile"')
202
+
203
+ html.should_not include('<div id="content">')
204
+ html.should_not include('</body>')
205
+ end
206
+ end
207
+
208
+ deviates_on [:webdriver, :ie] do
209
+ it "returns the HTML of the element" do
210
+ html = browser.div(:id, 'footer').html.downcase
211
+ html.should include('id=footer')
212
+ html.should include('title="closing remarks"')
213
+ html.should include('class=profile')
214
+
215
+ html.should_not include('<div id=content>')
216
+ html.should_not include('</body>')
217
+ end
192
218
  end
193
219
  end
194
220
 
@@ -27,7 +27,7 @@ describe "Divs" do
27
27
  d.id.should == browser.div(:index, index).id
28
28
  d.class_name.should == browser.div(:index, index).class_name
29
29
 
30
- count += 1
30
+ count += 1
31
31
  end
32
32
 
33
33
  count.should > 0
@@ -16,6 +16,10 @@ describe "Dl" do
16
16
  browser.dl(:index, 0).should exist
17
17
  end
18
18
 
19
+ it "returns the first dl if given no args" do
20
+ browser.dl.should exist
21
+ end
22
+
19
23
  it "returns false if the element does not exist" do
20
24
  browser.dl(:id, "no_such_id").should_not exist
21
25
  end
@@ -32,11 +36,11 @@ describe "Dl" do
32
36
  # Attribute methods
33
37
  describe "#class_name" do
34
38
  it "returns the class attribute if the element exists" do
35
- browser.dl(:id , "experience-list").class_name.should == "list"
39
+ browser.dl(:id, "experience-list").class_name.should == "list"
36
40
  end
37
41
 
38
42
  it "returns an empty string if the element exists but the attribute doesn't" do
39
- browser.dl(:id , "noop").class_name.should == ""
43
+ browser.dl(:id, "noop").class_name.should == ""
40
44
  end
41
45
 
42
46
  it "raises UnknownObjectException if the element does not exist" do
@@ -113,10 +117,20 @@ describe "Dl" do
113
117
  end
114
118
 
115
119
  describe "#html" do
116
- it "returns the HTML of the element" do
117
- html = browser.dl(:id, 'experience-list').html.downcase
118
- html.should include('<dt class="current-industry">')
119
- html.should_not include('</body>')
120
+ not_compliant_on [:webdriver, :ie] do
121
+ it "returns the HTML of the element" do
122
+ html = browser.dl(:id, 'experience-list').html.downcase
123
+ html.should include('<dt class="current-industry">')
124
+ html.should_not include('</body>')
125
+ end
126
+ end
127
+
128
+ deviates_on [:webdriver, :ie] do
129
+ it "returns the HTML of the element" do
130
+ html = browser.dl(:id, 'experience-list').html.downcase
131
+ html.should include('<dt class=current-industry>')
132
+ html.should_not include('</body>')
133
+ end
120
134
  end
121
135
  end
122
136
 
@@ -28,7 +28,7 @@ describe "Dls" do
28
28
  d.id.should == browser.dl(:index, index).id
29
29
  d.class_name.should == browser.dl(:index, index).class_name
30
30
 
31
- count += 1
31
+ count += 1
32
32
  end
33
33
 
34
34
  count.should > 0
@@ -16,6 +16,10 @@ describe "Dt" do
16
16
  browser.dt(:index, 0).should exist
17
17
  end
18
18
 
19
+ it "returns the first dt if given no args" do
20
+ browser.dt.should exist
21
+ end
22
+
19
23
  it "returns false if the element does not exist" do
20
24
  browser.dt(:id, "no_such_id").should_not exist
21
25
  end
@@ -27,7 +27,7 @@ describe "Dts" do
27
27
  d.id.should == browser.dt(:index, index).id
28
28
  d.class_name.should == browser.dt(:index, index).class_name
29
29
 
30
- count += 1
30
+ count += 1
31
31
  end
32
32
 
33
33
  count.should > 0
@@ -16,6 +16,10 @@ describe "Em" do
16
16
  browser.em(:index, 0).should exist
17
17
  end
18
18
 
19
+ it "returns the first em if given no args" do
20
+ browser.em.should exist
21
+ end
22
+
19
23
  it "returns false if the element does not exist" do
20
24
  browser.em(:id, "no_such_id").should_not exist
21
25
  end
@@ -28,7 +28,7 @@ describe "Ems" do
28
28
  e.id.should == browser.em(:index, index).id
29
29
  e.class_name.should == browser.em(:index, index).class_name
30
30
 
31
- count += 1
31
+ count += 1
32
32
  end
33
33
 
34
34
  count.should > 0
@@ -19,6 +19,10 @@ describe "FileField" do
19
19
  browser.file_field(:xpath, "//input[@id='new_user_portrait']").should exist
20
20
  end
21
21
 
22
+ it "returns the first file field if given no args" do
23
+ browser.file_field.should exist
24
+ end
25
+
22
26
  it "returns false if the file field doesn't exist" do
23
27
  browser.file_field(:id, 'no_such_id').should_not exist
24
28
  browser.file_field(:id, /no_such_id/).should_not exist
@@ -107,10 +111,41 @@ describe "FileField" do
107
111
  path = File.expand_path(__FILE__)
108
112
 
109
113
  browser.file_field(:name, "new_user_portrait").set path
110
- browser.file_field(:name, "new_user_portrait").value.should == path
111
- messages.first.should include(File.basename(path)) # only some browser will return the full path
114
+ browser.file_field(:name, "new_user_portrait").value.should include(File.basename(path)) # only some browser will return the full path
115
+ messages.first.should include(File.basename(path))
116
+ browser.button(:name, "new_user_submit").click
117
+ end
118
+
119
+ it "raises an error if the file does not exist" do
120
+ lambda {
121
+ browser.file_field.set('/tmp/unlikely-to-exist')
122
+ }.should raise_error(Errno::ENOENT)
123
+ end
124
+ end
125
+
126
+
127
+ describe "#value=" do
128
+ it "is able to set a file path in the field and click the upload button and fire the onchange event" do
129
+ browser.goto("#{WatirSpec.host}/forms_with_input_elements.html")
130
+
131
+ path = File.expand_path(__FILE__)
132
+
133
+ browser.file_field(:name, "new_user_portrait").value = path
134
+ browser.file_field(:name, "new_user_portrait").value.should include(File.basename(path)) # only some browser will return the full path
135
+ messages.first.should include(File.basename(path))
112
136
  browser.button(:name, "new_user_submit").click
113
137
  end
138
+
139
+ it "does not raise an error if the file does not exist" do
140
+ browser.file_field.value = '/tmp/unlikely-to-exist'
141
+ browser.file_field.value.should == '/tmp/unlikely-to-exist'
142
+ end
143
+
144
+ it "does not alter its argument" do
145
+ value = '/foo/bar'
146
+ browser.file_field.value = value
147
+ value.should == '/foo/bar'
148
+ end
114
149
  end
115
150
 
116
151
  end
@@ -28,7 +28,7 @@ describe "FileFields" do
28
28
  f.id.should == browser.file_field(:index, index).id
29
29
  f.value.should == browser.file_field(:index, index).value
30
30
 
31
- count += 1
31
+ count += 1
32
32
  end
33
33
 
34
34
  count.should > 0
@@ -23,4 +23,8 @@ describe "Font" do
23
23
  browser.font(:index, 0).size.should == "12"
24
24
  end
25
25
 
26
+ it "finds all font elements" do
27
+ browser.fonts.size.should == 1
28
+ end
29
+
26
30
  end
@@ -23,6 +23,10 @@ describe "Form" do
23
23
  browser.form(:xpath, "//form[@id='new_user']").should exist
24
24
  end
25
25
 
26
+ it "returns the first form if given no args" do
27
+ browser.form.should exist
28
+ end
29
+
26
30
  it "returns false if the form doesn't exist" do
27
31
  browser.form(:id, 'no_such_id').should_not exist
28
32
  browser.form(:id, /no_such_id/).should_not exist
@@ -14,9 +14,11 @@ describe "Forms" do
14
14
  end
15
15
 
16
16
  describe "#[]n" do
17
- it "provides access to the nth form" do
18
- browser.forms[0].action.should == 'post_to_me'
19
- browser.forms[0].attribute_value('method').should == 'post'
17
+ bug "http://github.com/jarib/watir-webdriver/issues/issue/27", [:webdriver, :firefox], [:webdriver, :ie] do
18
+ it "provides access to the nth form" do
19
+ browser.forms[0].action.should == 'post_to_me'
20
+ browser.forms[0].attribute_value('method').should == 'post'
21
+ end
20
22
  end
21
23
  end
22
24
 
@@ -29,7 +31,7 @@ describe "Forms" do
29
31
  f.id.should == browser.form(:index, index).id
30
32
  f.class_name.should == browser.form(:index, index).class_name
31
33
 
32
- count += 1
34
+ count += 1
33
35
  end
34
36
 
35
37
  count.should > 0
@@ -45,6 +45,12 @@ describe "Frame" do
45
45
  browser.frame(:xpath, "//iframe[@id='frame_1']").should exist
46
46
  end
47
47
 
48
+ bug "http://github.com/jarib/watir-webdriver/issues#issue/17", :webdriver do
49
+ it "returns the first frame if given no args" do
50
+ browser.frame.should exist
51
+ end
52
+ end
53
+
48
54
  it "returns false if the frame doesn't exist" do
49
55
  browser.frame(:id, "no_such_id").should_not exist
50
56
  browser.frame(:name, "no_such_text").should_not exist
@@ -16,14 +16,15 @@ describe "Hidden" do
16
16
  browser.hidden(:name, /new_user_interests/).should exist
17
17
  browser.hidden(:value, 'dolls').should exist
18
18
  browser.hidden(:value, /dolls/).should exist
19
- # TODO: figure out what :text means for Hidden
20
- # browser.hidden(:text, 'dolls').should exist
21
- # browser.hidden(:text, /dolls/).should exist
22
19
  browser.hidden(:class, 'fun').should exist
23
20
  browser.hidden(:class, /fun/).should exist
24
21
  browser.hidden(:index, 0).should exist
25
22
  browser.hidden(:xpath, "//input[@id='new_user_interests_dolls']").should exist
26
- end
23
+ end
24
+
25
+ it "returns the first hidden if given no args" do
26
+ browser.hidden.should exist
27
+ end
27
28
 
28
29
  it "returns false if the element does not exist" do
29
30
  browser.hidden(:id, 'no_such_id').should_not exist
@@ -28,7 +28,7 @@ describe "Hiddens" do
28
28
  h.id.should == browser.hidden(:index, index).id
29
29
  h.value.should == browser.hidden(:index, index).value
30
30
 
31
- count += 1
31
+ count += 1
32
32
  end
33
33
 
34
34
  count.should > 0
@@ -19,6 +19,10 @@ describe "H1", "H2", "H3", "H4", "H5", "H6" do
19
19
  browser.h1(:xpath, "//h1[@id='first_header']").should exist
20
20
  end
21
21
 
22
+ it "returns the first h1 if given no args" do
23
+ browser.h1.should exist
24
+ end
25
+
22
26
  it "returns true if the element exists" do
23
27
  browser.h1(:id, "no_such_id").should_not exist
24
28
  browser.h1(:id, /no_such_id/).should_not exist