watir-webdriver 0.0.1.dev6 → 0.0.1.dev7

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 (94) hide show
  1. data/Rakefile +1 -2
  2. data/VERSION +1 -1
  3. data/lib/watir-webdriver.rb +1 -4
  4. data/lib/watir-webdriver/base_element.rb +14 -7
  5. data/lib/watir-webdriver/browser.rb +3 -1
  6. data/lib/watir-webdriver/elements/button.rb +1 -0
  7. data/lib/watir-webdriver/elements/form.rb +1 -1
  8. data/lib/watir-webdriver/elements/frame.rb +77 -0
  9. data/lib/watir-webdriver/elements/generated.rb +536 -536
  10. data/lib/watir-webdriver/elements/option.rb +3 -0
  11. data/lib/watir-webdriver/elements/table_row.rb +1 -0
  12. data/lib/watir-webdriver/elements/text_field.rb +5 -1
  13. data/lib/watir-webdriver/xpath_support.rb +0 -1
  14. data/spec/base_element_spec.rb +16 -0
  15. data/spec/html/keylogger.html +15 -0
  16. data/spec/watirspec/area_spec.rb +78 -0
  17. data/spec/watirspec/areas_spec.rb +31 -0
  18. data/spec/watirspec/browser_spec.rb +274 -0
  19. data/spec/watirspec/button_spec.rb +242 -0
  20. data/spec/watirspec/buttons_spec.rb +48 -0
  21. data/spec/watirspec/checkbox_spec.rb +272 -0
  22. data/spec/watirspec/checkboxes_spec.rb +32 -0
  23. data/spec/watirspec/dd_spec.rb +123 -0
  24. data/spec/watirspec/dds_spec.rb +31 -0
  25. data/spec/watirspec/div_spec.rb +211 -0
  26. data/spec/watirspec/divs_spec.rb +31 -0
  27. data/spec/watirspec/dl_spec.rb +123 -0
  28. data/spec/watirspec/dls_spec.rb +32 -0
  29. data/spec/watirspec/dt_spec.rb +123 -0
  30. data/spec/watirspec/dts_spec.rb +31 -0
  31. data/spec/watirspec/element_spec.rb +89 -0
  32. data/spec/watirspec/em_spec.rb +97 -0
  33. data/spec/watirspec/ems_spec.rb +32 -0
  34. data/spec/watirspec/filefield_spec.rb +119 -0
  35. data/spec/watirspec/filefields_spec.rb +32 -0
  36. data/spec/watirspec/font_spec.rb +26 -0
  37. data/spec/watirspec/form_spec.rb +63 -0
  38. data/spec/watirspec/forms_spec.rb +33 -0
  39. data/spec/watirspec/frame_spec.rb +135 -0
  40. data/spec/watirspec/frames_spec.rb +62 -0
  41. data/spec/watirspec/hidden_spec.rb +102 -0
  42. data/spec/watirspec/hiddens_spec.rb +32 -0
  43. data/spec/watirspec/hn_spec.rb +93 -0
  44. data/spec/watirspec/hns_spec.rb +38 -0
  45. data/spec/watirspec/image_spec.rb +207 -0
  46. data/spec/watirspec/images_spec.rb +31 -0
  47. data/spec/watirspec/label_spec.rb +75 -0
  48. data/spec/watirspec/labels_spec.rb +31 -0
  49. data/spec/watirspec/li_spec.rb +112 -0
  50. data/spec/watirspec/lib/guards.rb +59 -0
  51. data/spec/watirspec/lib/server.rb +136 -0
  52. data/spec/watirspec/lib/spec_helper.rb +79 -0
  53. data/spec/watirspec/lib/watirspec.rb +72 -0
  54. data/spec/watirspec/link_spec.rb +168 -0
  55. data/spec/watirspec/links_spec.rb +35 -0
  56. data/spec/watirspec/lis_spec.rb +31 -0
  57. data/spec/watirspec/map_spec.rb +76 -0
  58. data/spec/watirspec/maps_spec.rb +32 -0
  59. data/spec/watirspec/meta_spec.rb +22 -0
  60. data/spec/watirspec/metas_spec.rb +30 -0
  61. data/spec/watirspec/ol_spec.rb +78 -0
  62. data/spec/watirspec/ols_spec.rb +31 -0
  63. data/spec/watirspec/option_spec.rb +173 -0
  64. data/spec/watirspec/p_spec.rb +128 -0
  65. data/spec/watirspec/pre_spec.rb +112 -0
  66. data/spec/watirspec/pres_spec.rb +31 -0
  67. data/spec/watirspec/ps_spec.rb +31 -0
  68. data/spec/watirspec/radio_spec.rb +255 -0
  69. data/spec/watirspec/radios_spec.rb +32 -0
  70. data/spec/watirspec/select_list_spec.rb +318 -0
  71. data/spec/watirspec/select_lists_spec.rb +35 -0
  72. data/spec/watirspec/span_spec.rb +142 -0
  73. data/spec/watirspec/spans_spec.rb +31 -0
  74. data/spec/watirspec/spec_helper.rb +17 -0
  75. data/spec/watirspec/strong_spec.rb +89 -0
  76. data/spec/watirspec/strongs_spec.rb +32 -0
  77. data/spec/watirspec/table_bodies_spec.rb +45 -0
  78. data/spec/watirspec/table_body_spec.rb +98 -0
  79. data/spec/watirspec/table_cell_spec.rb +68 -0
  80. data/spec/watirspec/table_cells_spec.rb +47 -0
  81. data/spec/watirspec/table_footer_spec.rb +85 -0
  82. data/spec/watirspec/table_footers_spec.rb +47 -0
  83. data/spec/watirspec/table_header_spec.rb +85 -0
  84. data/spec/watirspec/table_headers_spec.rb +45 -0
  85. data/spec/watirspec/table_row_spec.rb +87 -0
  86. data/spec/watirspec/table_rows_spec.rb +50 -0
  87. data/spec/watirspec/table_spec.rb +160 -0
  88. data/spec/watirspec/tables_spec.rb +33 -0
  89. data/spec/watirspec/text_field_spec.rb +276 -0
  90. data/spec/watirspec/text_fields_spec.rb +35 -0
  91. data/spec/watirspec/ul_spec.rb +76 -0
  92. data/spec/watirspec/uls_spec.rb +33 -0
  93. data/support/html5/html5.idl +1 -1
  94. metadata +181 -21
@@ -13,6 +13,9 @@ module Watir
13
13
 
14
14
  def select
15
15
  assert_exists
16
+
17
+ # not sure why both is needed
18
+ @element.click
16
19
  @element.select
17
20
  end
18
21
 
@@ -15,6 +15,7 @@ module Watir
15
15
 
16
16
  def locate
17
17
  if @parent.kind_of?(Watir::Table)
18
+ @parent.assert_exists
18
19
  TableRowLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
19
20
  else
20
21
  super
@@ -3,7 +3,10 @@ module Watir
3
3
  class TextField < Input
4
4
 
5
5
  attributes Watir::TextArea.typed_attributes
6
- def type; super; end # hacky, but we want Input#type here, which was overriden by TextArea's attributes
6
+
7
+ # hacky, but we want Input#type here, which was overriden by TextArea's attributes
8
+ # so we're *overwriting* that method definition here
9
+ def type; super; end
7
10
 
8
11
  container_method :text_field
9
12
  collection_method :text_fields
@@ -58,6 +61,7 @@ module Watir
58
61
  private
59
62
 
60
63
  def locate
64
+ @parent.assert_exists
61
65
  TextFieldLocator.new(@parent.wd, @selector, self.class.attribute_list).locate
62
66
  end
63
67
 
@@ -19,7 +19,6 @@ module Watir
19
19
  #
20
20
 
21
21
  def elements_by_xpath(xpath)
22
- # TODO: find the correct element class
23
22
  wd.find_elements(:xpath, xpath).map do |e|
24
23
  Watir.element_class_for(e.tag_name).new(self, :element, e)
25
24
  end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/watirspec/spec_helper'
2
+
3
+ describe Watir::BaseElement do
4
+
5
+ before :each do
6
+ browser.goto("file://" + File.expand_path("html/keylogger.html", File.dirname(__FILE__)))
7
+ end
8
+
9
+ describe "#send_keys" do
10
+ it "sends keystrokes to the element" do
11
+ browser.div(:id, 'receiver').send_keys("hello world")
12
+ browser.div(:id, 'output').ps.size.should == 11
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
4
+ <title>Keylogger</title>
5
+ <script type="text/javascript" charset="utf-8">
6
+ function log (e) {
7
+ document.getElementById('output').innerHTML += "<p>" + e.toString() + "</p>";
8
+ }
9
+ </script>
10
+ </head>
11
+ <body>
12
+ <div id="receiver" onkeypress="log(this)">Receiver</div>
13
+ <div id="output"></div>
14
+ </body>
15
+ </html>
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Area" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/images.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exist?" do
12
+ it "returns true if the area exists" do
13
+ browser.area(:id, "NCE").should exist
14
+ browser.area(:id, /NCE/).should exist
15
+ browser.area(:title, "Tables").should exist
16
+ browser.area(:title, /Tables/).should exist
17
+
18
+ bug "WTR-342", :watir do
19
+ browser.area(:url, "tables.html").should exist
20
+ browser.area(:url, /tables/).should exist
21
+ browser.area(:href, "tables.html").should exist
22
+ browser.area(:href, /tables/).should exist
23
+ end
24
+
25
+ browser.area(:index, 0).should exist
26
+ browser.area(:xpath, "//area[@id='NCE']").should exist
27
+ end
28
+
29
+ it "returns false if the area doesn't exist" do
30
+ browser.area(:id, "no_such_id").should_not exist
31
+ browser.area(:id, /no_such_id/).should_not exist
32
+ browser.area(:title, "no_such_title").should_not exist
33
+ browser.area(:title, /no_such_title/).should_not exist
34
+
35
+ bug "WTR-342", :watir do
36
+ browser.area(:url, "no_such_href").should_not exist
37
+ browser.area(:url, /no_such_href/).should_not exist
38
+ browser.area(:href, "tables.html").should exist
39
+ browser.area(:href, /tables/).should exist
40
+ end
41
+
42
+ browser.area(:index, 1337).should_not exist
43
+ browser.area(:xpath, "//area[@id='no_such_id']").should_not exist
44
+ end
45
+
46
+ it "raises TypeError when 'what' argument is invalid" do
47
+ lambda { browser.area(:id, 3.14).exists? }.should raise_error(TypeError)
48
+ end
49
+
50
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
51
+ lambda { browser.area(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
52
+ end
53
+ end
54
+
55
+ # Attribute methods
56
+ describe "#id" do
57
+ it "returns the id attribute" do
58
+ browser.area(:index, 0).id.should == "NCE"
59
+ end
60
+
61
+ it "returns an empty string if the element exists and the attribute doesn't" do
62
+ browser.area(:index, 2).id.should == ''
63
+ end
64
+
65
+ it "raises UnknownObjectException if the area doesn't exist" do
66
+ lambda { browser.area(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
67
+ lambda { browser.area(:index, 1337).id }.should raise_error(UnknownObjectException)
68
+ end
69
+
70
+ end
71
+
72
+ describe "#respond_to?" do
73
+ it "returns true for all attribute methods" do
74
+ browser.area(:index, 0).should respond_to(:id)
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Areas" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/images.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of areas" do
12
+ browser.areas.length.should == 3
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the area at the given index" do
18
+ browser.areas[0].id.should == "NCE"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through areas correctly" do
24
+ browser.areas.each_with_index do |a, index|
25
+ a.id.should == browser.area(:index, index).id
26
+ a.title.should == browser.area(:index, index).title
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,274 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Browser" do
5
+
6
+ describe "#exists?" do
7
+ it "returns true if we are at a page" do
8
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
9
+ browser.should exist
10
+ end
11
+
12
+ not_compliant_on :webdriver do
13
+ it "returns false after IE#close" do
14
+ b = WatirSpec.new_browser
15
+ b.close
16
+ b.should_not exist
17
+ end
18
+ end
19
+ end
20
+
21
+ # this should be rewritten - the actual string returned varies alot between implementations
22
+ describe "#html" do
23
+ deviates_on :celerity do
24
+ it "returns the downloaded HTML of the page" do
25
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
26
+ browser.html.should == File.read(File.dirname(__FILE__) + "/html/non_control_elements.html")
27
+ end
28
+ end
29
+
30
+ deviates_on :watir do
31
+ it "returns the DOM of the page as an HTML string" do
32
+ browser.goto(WatirSpec.files + "/right_click.html")
33
+ browser.html.should == "<HTML><HEAD><TITLE>Right Click Test</TITLE>\r\n<META http-equiv=Content-type content=\"text/html; charset=utf-8\">\r\n<SCRIPT src=\"javascript/helpers.js\" type=text/javascript charset=utf-8></SCRIPT>\r\n</HEAD>\r\n<BODY>\r\n<DIV id=messages></DIV>\r\n<DIV oncontextmenu='WatirSpec.addMessage(\"right-clicked\")' id=click>Right click!</DIV></BODY></HTML>"
34
+ end
35
+ end
36
+
37
+ deviates_on :webdriver do
38
+ it "returns the DOM of the page as an HTML string" do
39
+ browser.goto(WatirSpec.files + "/right_click.html")
40
+ html = browser.html.downcase # varies between browsers
41
+
42
+ html.should =~ /^<html/
43
+ html.should include("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">")
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#title" do
49
+ it "returns the current page title" do
50
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
51
+ browser.title.should == "Non-control elements"
52
+ end
53
+ end
54
+
55
+ describe "#status" do
56
+ not_compliant_on :webdriver do # need to set Firefox preference, might do this when selenium-webdriver exposes the profile used
57
+ bug "WTR-348", :watir do
58
+ it "returns the current value of window.status" do
59
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
60
+
61
+ # for firefox, this needs to be enabled in
62
+ # Preferences -> Content -> Advanced -> Change status bar text
63
+ browser.execute_script "window.status = 'All done!';"
64
+ browser.status.should == "All done!"
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "#text" do
71
+ it "returns the text of the page" do
72
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
73
+ browser.text.should include("Dubito, ergo cogito, ergo sum.")
74
+ end
75
+
76
+ it "returns the text also if the content-type is text/plain" do
77
+ # more specs for text/plain? what happens if we call other methods?
78
+ browser.goto(WatirSpec.host + "/plain_text")
79
+ browser.text.strip.should == 'This is text/plain'
80
+ end
81
+ end
82
+
83
+ describe "#url" do
84
+ it "returns the current url" do
85
+ browser.goto(WatirSpec.host + "/non_control_elements.html")
86
+ browser.url.should == WatirSpec.host + "/non_control_elements.html"
87
+ end
88
+ end
89
+
90
+ not_compliant_on :webdriver do
91
+ # just hangs with watir-webdriver + IE
92
+ describe ".start" do
93
+ it "goes to the given URL and return an instance of itself" do
94
+ browser = Browser.start("#{WatirSpec.files}/non_control_elements.html")
95
+ browser.should be_instance_of(Browser)
96
+ browser.title.should == "Non-control elements"
97
+ browser.quit
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "#goto" do
103
+ it "adds http:// to URLs with no URL scheme specified" do
104
+ url = WatirSpec.host[%r{http://(.*)}, 1]
105
+ url.should_not be_nil
106
+ browser.goto(url)
107
+ browser.url.should =~ %r[http://#{url}/?]
108
+ end
109
+
110
+ it "goes to the given url without raising errors" do
111
+ lambda { browser.goto(WatirSpec.files + "/non_control_elements.html") }.should_not raise_error
112
+ end
113
+
114
+ it "updates the page when location is changed with setTimeout + window.location" do
115
+ browser.goto(WatirSpec.files + "/timeout_window_location.html")
116
+ sleep 1
117
+ browser.url.should include("non_control_elements.html")
118
+ end
119
+ end
120
+
121
+ describe "#refresh" do
122
+ it "refreshes the page" do
123
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
124
+ browser.span(:class, 'footer').click
125
+ browser.span(:class, 'footer').text.should include('Javascript')
126
+ browser.refresh
127
+ browser.span(:class, 'footer').text.should_not include('Javascript')
128
+ end
129
+ end
130
+
131
+ describe "#execute_script" do
132
+ it "executes the given JavaScript on the current page" do
133
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
134
+ browser.pre(:id, 'rspec').text.should_not == "javascript text"
135
+ browser.execute_script("document.getElementById('rspec').innerHTML = 'javascript text'")
136
+ browser.pre(:id, 'rspec').text.should == "javascript text"
137
+ end
138
+ end
139
+
140
+ describe "#back and #forward" do
141
+ it "goes to the previous page" do
142
+ browser.goto("#{WatirSpec.host}/non_control_elements.html")
143
+ orig_url = browser.url
144
+ browser.goto("#{WatirSpec.host}/tables.html")
145
+ new_url = browser.url
146
+ orig_url.should_not == new_url
147
+ browser.back
148
+ orig_url.should == browser.url
149
+ end
150
+
151
+ it "goes to the next page" do
152
+ urls = []
153
+ browser.goto(WatirSpec.host + "/non_control_elements.html")
154
+ urls << browser.url
155
+ browser.goto(WatirSpec.host + "/tables.html")
156
+ urls << browser.url
157
+
158
+ browser.back
159
+ browser.url.should == urls.first
160
+ browser.forward
161
+ browser.url.should == urls.last
162
+ end
163
+
164
+ it "navigates between several history items" do
165
+ urls = [ "#{WatirSpec.host}/non_control_elements.html",
166
+ "#{WatirSpec.host}/tables.html",
167
+ "#{WatirSpec.host}/forms_with_input_elements.html",
168
+ "#{WatirSpec.host}/definition_lists.html"
169
+ ].map do |page|
170
+ browser.goto page
171
+ browser.url
172
+ end
173
+
174
+ 3.times { browser.back }
175
+ browser.url.should == urls.first
176
+ 2.times { browser.forward }
177
+ browser.url.should == urls[2]
178
+ end
179
+ end
180
+
181
+ describe "#element_by_xpath" do
182
+ before :each do
183
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
184
+ end
185
+
186
+ bug "WTR-343", :watir do
187
+ it "finds submit buttons matching the given xpath" do
188
+ browser.element_by_xpath("//input[@type='submit']").should exist
189
+ end
190
+
191
+ it "finds reset buttons matching the given xpath" do
192
+ browser.element_by_xpath("//input[@type='reset']").should exist
193
+ end
194
+
195
+ it "finds image buttons matching the given xpath" do
196
+ browser.element_by_xpath("//input[@type='image']").should exist
197
+ end
198
+
199
+ it "finds the element matching the given xpath" do
200
+ browser.element_by_xpath("//input[@type='password']").should exist
201
+ end
202
+ end
203
+
204
+ bug "WTR-327", :watir do
205
+ it "will not find elements that doesn't exist" do
206
+ e = browser.element_by_xpath("//input[@type='foobar']")
207
+ e.should_not exist
208
+ lambda { e.text }.should raise_error(UnknownObjectException)
209
+ end
210
+ end
211
+ end
212
+
213
+ describe "#elements_by_xpath" do
214
+ before :each do
215
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
216
+ end
217
+
218
+ bug "WTR-344", :watir do
219
+ it "returns an Array of matching elements" do
220
+ objects = browser.elements_by_xpath("//*[@type='text']")
221
+ objects.should be_kind_of(Array)
222
+ objects.size.should == 5
223
+ end
224
+ end
225
+
226
+ bug "WTR-328", :watir do
227
+ it "returns an empty Array if there are no matching elements" do
228
+ objects = browser.elements_by_xpath("//*[@type='foobar']")
229
+ objects.should be_kind_of(Array)
230
+ objects.size.should == 0
231
+ end
232
+ end
233
+ end
234
+
235
+ describe "#add_checker" do
236
+ it "raises ArgumentError when not given any arguments" do
237
+ lambda { browser.add_checker }.should raise_error(ArgumentError)
238
+ end
239
+
240
+ not_compliant_on :webdriver do
241
+ # if on IE, this slows the rest of the suite way down for some reason
242
+ it "runs the given proc on each page load" do
243
+ output = ''
244
+ proc = Proc.new { |browser| output << browser.text }
245
+
246
+ browser.add_checker(proc)
247
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
248
+
249
+ output.should include('Dubito, ergo cogito, ergo sum')
250
+ end
251
+ end
252
+ end
253
+
254
+ describe "#disable_checker" do
255
+ it "removes a previously added checker" do
256
+ output = ''
257
+ checker = lambda { |browser| output << browser.text }
258
+
259
+ browser.add_checker(checker)
260
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
261
+ output.should include('Dubito, ergo cogito, ergo sum')
262
+
263
+ browser.disable_checker(checker)
264
+ browser.goto(WatirSpec.files + "/definition_lists.html")
265
+ output.should_not include('definition_lists')
266
+ end
267
+ end
268
+
269
+ it "raises UnknownObjectException when trying to access DOM elements on plain/text-page" do
270
+ browser.goto(WatirSpec.host + "/plain_text")
271
+ lambda { browser.div(:id, 'foo').id }.should raise_error(UnknownObjectException)
272
+ end
273
+
274
+ end