operawatir 0.3-jruby

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 (171) hide show
  1. data/.gitmodules +3 -0
  2. data/.yardopts +5 -0
  3. data/AUTHORS +7 -0
  4. data/Gemfile +9 -0
  5. data/LICENSE +30 -0
  6. data/README.md +158 -0
  7. data/Rakefile +59 -0
  8. data/VERSION +1 -0
  9. data/bin/desktopwatir +106 -0
  10. data/bin/operawatir +95 -0
  11. data/lib/operadriver/APACHE_2.0_LICENSE.txt +204 -0
  12. data/lib/operadriver/NEW_BSD_LICENSE.txt +36 -0
  13. data/lib/operadriver/commons-jxpath-1.3.jar +0 -0
  14. data/lib/operadriver/protobuf-java-2.3.0.jar +0 -0
  15. data/lib/operadriver/selenium-common.jar +0 -0
  16. data/lib/operadriver/webdriver-opera.jar +0 -0
  17. data/lib/operawatir.rb +46 -0
  18. data/lib/operawatir/browser.rb +181 -0
  19. data/lib/operawatir/collection.rb +133 -0
  20. data/lib/operawatir/compat.rb +25 -0
  21. data/lib/operawatir/compat/browser.rb +20 -0
  22. data/lib/operawatir/compat/collection.rb +99 -0
  23. data/lib/operawatir/compat/deprecation.rb +46 -0
  24. data/lib/operawatir/compat/element.rb +165 -0
  25. data/lib/operawatir/compat/element_finders.rb +159 -0
  26. data/lib/operawatir/compat/window.rb +27 -0
  27. data/lib/operawatir/element.rb +228 -0
  28. data/lib/operawatir/exceptions.rb +38 -0
  29. data/lib/operawatir/helper.rb +53 -0
  30. data/lib/operawatir/selector.rb +111 -0
  31. data/lib/operawatir/version.rb +15 -0
  32. data/lib/operawatir/window.rb +174 -0
  33. data/spec/fire_event/fire_event.rb +268 -0
  34. data/spec/fire_event/interactive/onBlur.html +45 -0
  35. data/spec/fire_event/interactive/onChange.html +47 -0
  36. data/spec/fire_event/interactive/onClick.html +45 -0
  37. data/spec/fire_event/interactive/onDblClick.html +45 -0
  38. data/spec/fire_event/interactive/onFocus.html +45 -0
  39. data/spec/fire_event/interactive/onMouseDown.html +45 -0
  40. data/spec/fire_event/interactive/onMouseMove.html +45 -0
  41. data/spec/fire_event/interactive/onMouseOut.html +45 -0
  42. data/spec/fire_event/interactive/onMouseOver.html +45 -0
  43. data/spec/fire_event/interactive/onMouseUp.html +45 -0
  44. data/spec/fire_event/interactive/onScroll.html +14 -0
  45. data/spec/legacy_watirspec/area_spec.rb +106 -0
  46. data/spec/legacy_watirspec/areas_spec.rb +38 -0
  47. data/spec/legacy_watirspec/browser_spec.rb +297 -0
  48. data/spec/legacy_watirspec/button_spec.rb +260 -0
  49. data/spec/legacy_watirspec/buttons_spec.rb +54 -0
  50. data/spec/legacy_watirspec/checkbox_spec.rb +280 -0
  51. data/spec/legacy_watirspec/checkboxes_spec.rb +38 -0
  52. data/spec/legacy_watirspec/collections_spec.rb +18 -0
  53. data/spec/legacy_watirspec/dd_spec.rb +140 -0
  54. data/spec/legacy_watirspec/dds_spec.rb +38 -0
  55. data/spec/legacy_watirspec/del_spec.rb +181 -0
  56. data/spec/legacy_watirspec/dels_spec.rb +62 -0
  57. data/spec/legacy_watirspec/div_spec.rb +244 -0
  58. data/spec/legacy_watirspec/divs_spec.rb +38 -0
  59. data/spec/legacy_watirspec/dl_spec.rb +140 -0
  60. data/spec/legacy_watirspec/dls_spec.rb +38 -0
  61. data/spec/legacy_watirspec/dt_spec.rb +140 -0
  62. data/spec/legacy_watirspec/dts_spec.rb +38 -0
  63. data/spec/legacy_watirspec/element_spec.rb +86 -0
  64. data/spec/legacy_watirspec/em_spec.rb +114 -0
  65. data/spec/legacy_watirspec/ems_spec.rb +38 -0
  66. data/spec/legacy_watirspec/filefield_spec.rb +127 -0
  67. data/spec/legacy_watirspec/filefields_spec.rb +38 -0
  68. data/spec/legacy_watirspec/fixtures/2000_spans.html +2009 -0
  69. data/spec/legacy_watirspec/fixtures/bug_duplicate_attributes.html +14 -0
  70. data/spec/legacy_watirspec/fixtures/bug_javascript_001.html +11 -0
  71. data/spec/legacy_watirspec/fixtures/buttons_with_duplicate_ids.html +18 -0
  72. data/spec/legacy_watirspec/fixtures/collections.html +15 -0
  73. data/spec/legacy_watirspec/fixtures/definition_lists.html +48 -0
  74. data/spec/legacy_watirspec/fixtures/euc-jp_text.html +17 -0
  75. data/spec/legacy_watirspec/fixtures/forms_with_input_elements.html +126 -0
  76. data/spec/legacy_watirspec/fixtures/frame_1.html +18 -0
  77. data/spec/legacy_watirspec/fixtures/frame_2.html +16 -0
  78. data/spec/legacy_watirspec/fixtures/frames.html +11 -0
  79. data/spec/legacy_watirspec/fixtures/iframes.html +12 -0
  80. data/spec/legacy_watirspec/fixtures/images.html +27 -0
  81. data/spec/legacy_watirspec/fixtures/images/1.gif +0 -0
  82. data/spec/legacy_watirspec/fixtures/images/2.gif +0 -0
  83. data/spec/legacy_watirspec/fixtures/images/3.gif +0 -0
  84. data/spec/legacy_watirspec/fixtures/images/button.jpg +0 -0
  85. data/spec/legacy_watirspec/fixtures/images/circle.jpg +0 -0
  86. data/spec/legacy_watirspec/fixtures/images/map.gif +0 -0
  87. data/spec/legacy_watirspec/fixtures/images/map2.gif +0 -0
  88. data/spec/legacy_watirspec/fixtures/images/minus.gif +0 -0
  89. data/spec/legacy_watirspec/fixtures/images/originaltriangle.jpg +0 -0
  90. data/spec/legacy_watirspec/fixtures/images/plus.gif +0 -0
  91. data/spec/legacy_watirspec/fixtures/images/square.jpg +0 -0
  92. data/spec/legacy_watirspec/fixtures/images/triangle.jpg +0 -0
  93. data/spec/legacy_watirspec/fixtures/iso-2022-jp_text.html +17 -0
  94. data/spec/legacy_watirspec/fixtures/javascript/helpers.js +16 -0
  95. data/spec/legacy_watirspec/fixtures/jquery.html +28 -0
  96. data/spec/legacy_watirspec/fixtures/latin1_text.html +17 -0
  97. data/spec/legacy_watirspec/fixtures/multiple_ids.html +14 -0
  98. data/spec/legacy_watirspec/fixtures/non_control_elements.html +135 -0
  99. data/spec/legacy_watirspec/fixtures/parser_bug_001.html +12 -0
  100. data/spec/legacy_watirspec/fixtures/prevent_form_submit.html +20 -0
  101. data/spec/legacy_watirspec/fixtures/right_click.html +11 -0
  102. data/spec/legacy_watirspec/fixtures/shift_jis_text.html +17 -0
  103. data/spec/legacy_watirspec/fixtures/tables.html +121 -0
  104. data/spec/legacy_watirspec/fixtures/timeout.html +16 -0
  105. data/spec/legacy_watirspec/fixtures/timeout_window_location.html +19 -0
  106. data/spec/legacy_watirspec/fixtures/tiny_mce.html +27 -0
  107. data/spec/legacy_watirspec/fixtures/utf8_text.html +15 -0
  108. data/spec/legacy_watirspec/fixtures/watirspec.css +0 -0
  109. data/spec/legacy_watirspec/form_spec.rb +73 -0
  110. data/spec/legacy_watirspec/forms_spec.rb +39 -0
  111. data/spec/legacy_watirspec/frame_spec.rb +161 -0
  112. data/spec/legacy_watirspec/frames_spec.rb +75 -0
  113. data/spec/legacy_watirspec/guards.rb +38 -0
  114. data/spec/legacy_watirspec/hidden_spec.rb +120 -0
  115. data/spec/legacy_watirspec/hiddens_spec.rb +38 -0
  116. data/spec/legacy_watirspec/hn_spec.rb +101 -0
  117. data/spec/legacy_watirspec/hns_spec.rb +39 -0
  118. data/spec/legacy_watirspec/image_spec.rb +237 -0
  119. data/spec/legacy_watirspec/images_spec.rb +38 -0
  120. data/spec/legacy_watirspec/ins_spec.rb +181 -0
  121. data/spec/legacy_watirspec/inses_spec.rb +62 -0
  122. data/spec/legacy_watirspec/label_spec.rb +85 -0
  123. data/spec/legacy_watirspec/labels_spec.rb +38 -0
  124. data/spec/legacy_watirspec/li_spec.rb +135 -0
  125. data/spec/legacy_watirspec/link_spec.rb +194 -0
  126. data/spec/legacy_watirspec/links_spec.rb +39 -0
  127. data/spec/legacy_watirspec/lis_spec.rb +38 -0
  128. data/spec/legacy_watirspec/map_spec.rb +100 -0
  129. data/spec/legacy_watirspec/maps_spec.rb +38 -0
  130. data/spec/legacy_watirspec/meta_spec.rb +26 -0
  131. data/spec/legacy_watirspec/metas_spec.rb +36 -0
  132. data/spec/legacy_watirspec/ol_spec.rb +86 -0
  133. data/spec/legacy_watirspec/ols_spec.rb +38 -0
  134. data/spec/legacy_watirspec/option_spec.rb +187 -0
  135. data/spec/legacy_watirspec/p_spec.rb +167 -0
  136. data/spec/legacy_watirspec/pre_spec.rb +133 -0
  137. data/spec/legacy_watirspec/pres_spec.rb +38 -0
  138. data/spec/legacy_watirspec/ps_spec.rb +38 -0
  139. data/spec/legacy_watirspec/radio_spec.rb +286 -0
  140. data/spec/legacy_watirspec/radios_spec.rb +35 -0
  141. data/spec/legacy_watirspec/select_list_spec.rb +326 -0
  142. data/spec/legacy_watirspec/select_lists_spec.rb +39 -0
  143. data/spec/legacy_watirspec/server.rb +91 -0
  144. data/spec/legacy_watirspec/span_spec.rb +181 -0
  145. data/spec/legacy_watirspec/spans_spec.rb +64 -0
  146. data/spec/legacy_watirspec/spec_helper.rb +12 -0
  147. data/spec/legacy_watirspec/strong_spec.rb +97 -0
  148. data/spec/legacy_watirspec/strongs_spec.rb +39 -0
  149. data/spec/legacy_watirspec/table_bodies_spec.rb +61 -0
  150. data/spec/legacy_watirspec/table_body_spec.rb +119 -0
  151. data/spec/legacy_watirspec/table_cell_spec.rb +76 -0
  152. data/spec/legacy_watirspec/table_cells_spec.rb +71 -0
  153. data/spec/legacy_watirspec/table_footer_spec.rb +94 -0
  154. data/spec/legacy_watirspec/table_footers_spec.rb +61 -0
  155. data/spec/legacy_watirspec/table_header_spec.rb +98 -0
  156. data/spec/legacy_watirspec/table_headers_spec.rb +59 -0
  157. data/spec/legacy_watirspec/table_row_spec.rb +104 -0
  158. data/spec/legacy_watirspec/table_rows_spec.rb +64 -0
  159. data/spec/legacy_watirspec/table_spec.rb +170 -0
  160. data/spec/legacy_watirspec/tables_spec.rb +40 -0
  161. data/spec/legacy_watirspec/text_field_spec.rb +315 -0
  162. data/spec/legacy_watirspec/text_fields_spec.rb +38 -0
  163. data/spec/legacy_watirspec/ul_spec.rb +84 -0
  164. data/spec/legacy_watirspec/uls_spec.rb +40 -0
  165. data/spec/legacy_watirspec/watir_compatibility_spec.rb +176 -0
  166. data/spec/legacy_watirspec/watirspec_helper.rb +57 -0
  167. data/utils/Rakefile +79 -0
  168. data/utils/launchers/launcher-linux-i686 +0 -0
  169. data/utils/launchers/launcher-linux-x86_64 +0 -0
  170. data/utils/launchers/launcher-win32-i86pc.exe +0 -0
  171. metadata +404 -0
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Dt" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/definition_lists.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exists?" do
12
+ it "returns true if the element exists" do
13
+ browser.dt(:id, "experience").should exist
14
+ browser.dt(:class, "current-industry").should exist
15
+ browser.dt(:xpath, "//dt[@id='experience']").should exist
16
+ browser.dt(:index, 1).should exist
17
+ end
18
+
19
+ it "returns the first dt if given no args" do
20
+ browser.dt.should exist
21
+ end
22
+
23
+ it "returns false if the element does not exist" do
24
+ browser.dt(:id, "no_such_id").should_not exist
25
+ end
26
+
27
+ it "raises TypeError when 'what' argument is invalid" do
28
+ lambda { browser.dt(:id, 3.14).exists? }.should raise_error(TypeError)
29
+ end
30
+
31
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
32
+ lambda { browser.dt(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
33
+ end
34
+ end
35
+
36
+ # Attribute methods
37
+ describe "#class_name" do
38
+ it "returns the class attribute if the element exists" do
39
+ browser.dt(:id , "experience").class_name.should == "industry"
40
+ end
41
+
42
+ it "returns an empty string if the element exists but the attribute doesn't" do
43
+ browser.dt(:id , "education").class_name.should == ""
44
+ end
45
+
46
+ it "raises UnknownObjectException if the element does not exist" do
47
+ lambda { browser.dt(:id, "no_such_id").class_name }.should raise_error(UnknownObjectException)
48
+ lambda { browser.dt(:title, "no_such_title").class_name }.should raise_error(UnknownObjectException)
49
+ lambda { browser.dt(:index, 1337).class_name }.should raise_error(UnknownObjectException)
50
+ lambda { browser.dt(:xpath, "//dt[@id='no_such_id']").class_name }.should raise_error(UnknownObjectException)
51
+ end
52
+ end
53
+
54
+ describe "#id" do
55
+ it "returns the id attribute if the element exists" do
56
+ browser.dt(:class, 'industry').id.should == "experience"
57
+ end
58
+
59
+ it "returns an empty string if the element exists, but the attribute doesn't" do
60
+ browser.dt(:class, 'current-industry').id.should == ""
61
+ end
62
+
63
+ it "raises UnknownObjectException if the element does not exist" do
64
+ lambda {browser.dt(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
65
+ lambda {browser.dt(:title, "no_such_id").id }.should raise_error(UnknownObjectException)
66
+ lambda {browser.dt(:index, 1337).id }.should raise_error(UnknownObjectException)
67
+ end
68
+ end
69
+
70
+ describe "#title" do
71
+ it "returns the title of the element" do
72
+ browser.dt(:id, "experience").title.should == "experience"
73
+ end
74
+ end
75
+
76
+ describe "#text" do
77
+ it "returns the text of the element" do
78
+ browser.dt(:id, "experience").text.should == "Experience"
79
+ end
80
+
81
+ it "returns an empty string if the element exists but contains no text" do
82
+ browser.dt(:class, 'noop').text.should == ""
83
+ end
84
+
85
+ it "raises UnknownObjectException if the element does not exist" do
86
+ lambda { browser.dt(:id, "no_such_id").text }.should raise_error(UnknownObjectException)
87
+ lambda { browser.dt(:title, "no_such_title").text }.should raise_error(UnknownObjectException)
88
+ lambda { browser.dt(:index, 1337).text }.should raise_error(UnknownObjectException)
89
+ lambda { browser.dt(:xpath, "//dt[@id='no_such_id']").text }.should raise_error(UnknownObjectException)
90
+ end
91
+ end
92
+
93
+ describe "#respond_to?" do
94
+ it "returns true for all attribute methods" do
95
+ browser.dt(:index, 1).should respond_to(:id)
96
+ browser.dt(:index, 1).should respond_to(:class_name)
97
+ browser.dt(:index, 1).should respond_to(:style)
98
+ browser.dt(:index, 1).should respond_to(:text)
99
+ browser.dt(:index, 1).should respond_to(:title)
100
+ end
101
+ end
102
+
103
+ # Manipulation methods
104
+ describe "#click" do
105
+ it "fires events when clicked" do
106
+ browser.dt(:id, 'education').text.should_not == 'changed'
107
+ browser.dt(:id, 'education').click
108
+ browser.dt(:id, 'education').text.should == 'changed'
109
+ end
110
+
111
+ it "raises UnknownObjectException if the element does not exist" do
112
+ lambda { browser.dt(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
113
+ lambda { browser.dt(:title, "no_such_title").click }.should raise_error(UnknownObjectException)
114
+ lambda { browser.dt(:index, 1337).click }.should raise_error(UnknownObjectException)
115
+ lambda { browser.dt(:xpath, "//dt[@id='no_such_id']").click }.should raise_error(UnknownObjectException)
116
+ end
117
+ end
118
+
119
+ describe "#html" do
120
+ it "returns the HTML of the element" do
121
+ html = browser.dt(:id, 'name').html
122
+ html.should match(%r"<div>.*Name.*</div>"m)
123
+ html.should_not include('</body>')
124
+ end
125
+ end
126
+
127
+ describe "#to_s" do
128
+ bug "WTR-350", :watir do
129
+ it "returns a human readable representation of the element" do
130
+ browser.dt(:id, 'experience').to_s.should ==
131
+ %q{tag: dt
132
+ id: experience
133
+ class: industry
134
+ title: experience
135
+ text: Experience}
136
+ end
137
+ end
138
+ end
139
+
140
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Dts" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/definition_lists.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of dts" do
12
+ browser.dts.length.should == 11
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the dt at the given index" do
18
+ browser.dts[1].id.should == "experience"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through dts correctly" do
24
+ count = 0
25
+
26
+ browser.dts.each_with_index do |d, index|
27
+ d.name.should == browser.dt(:index, index+1).name
28
+ d.id.should == browser.dt(:index, index+1).id
29
+ d.class_name.should == browser.dt(:index, index+1).class_name
30
+
31
+ count += 1
32
+ end
33
+
34
+ count.should > 0
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Element" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe ".new" do
11
+ it "finds elements matching the conditions when given a hash of :how => 'what' arguments" do
12
+ browser.checkbox(:name => 'new_user_interests', :title => 'Dancing is fun!').value.should == 'dancing'
13
+ #browser.text_field(:class_name => 'name', :index => 2).id.should == 'new_user_last_name'
14
+ end
15
+
16
+ it "raises UnknownObjectException with a sane error message when given a hash of :how => 'what' arguments (non-existing object)" do
17
+ conditions = {:index => 100, :name => "foo"}
18
+ lambda { browser.text_field(conditions).id }.should raise_error(UnknownObjectException, /Unable to locate TextField, using (\{:name=>"foo", :index=>100\}|\{:index=>100, :name=>"foo"\})/)
19
+ end
20
+
21
+ bug "WTR-351", :watir do
22
+ it "raises ArgumentError if given the wrong number of arguments" do
23
+ container = mock("container").as_null_object
24
+
25
+ lambda { Element.new(container, 1,2,3,4) }.should raise_error(ArgumentError, "wrong number of arguments (4 for 2)")
26
+ lambda { Element.new(container, "foo") }.should raise_error(ArgumentError, "wrong number of arguments (1 for 2)")
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#focus" do
32
+ it "fires the onfocus event for the given element" do
33
+ tf = browser.text_field(:id, "new_user_occupation")
34
+ tf.value.should == "Developer"
35
+ tf.focus
36
+ browser.div(:id, "onfocus_test").text.should == "changed by onfocus event"
37
+ end
38
+ end
39
+
40
+ describe "#fire_event" do
41
+ it "should fire the given event" do
42
+ browser.div(:id, "onfocus_test").text.should be_empty
43
+ browser.text_field(:id, "new_user_occupation").fire_event('onfocus')
44
+ browser.div(:id, "onfocus_test").text.should == "changed by onfocus event"
45
+ end
46
+ end
47
+
48
+ describe "#parent" do
49
+ bug "WTR-352", :watir do
50
+ it "gets the parent of this element" do
51
+ browser.text_field(:id, "new_user_email").parent.should be_instance_of(Form)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "#visible?" do
57
+ it "returns true if the element is visible" do
58
+ browser.text_field(:id, "new_user_email").should be_visible
59
+ end
60
+
61
+ it "returns false if the element is input element where type == 'hidden'" do
62
+ browser.text_field(:id, "new_user_interests_dolls").should_not be_visible
63
+ end
64
+
65
+ bug "WTR-336", :watir do
66
+ it "returns false if the element has style='display: none;'" do
67
+ browser.div(:id, 'changed_language').should_not be_visible
68
+ end
69
+ end
70
+
71
+ it "returns false if the element has style='visibility: hidden;" do
72
+ browser.div(:id, 'wants_newsletter').should_not be_visible
73
+ end
74
+
75
+ it "returns false if one of the parent elements is hidden" do
76
+ browser.div(:id, 'hidden_parent').should_not be_visible
77
+ end
78
+ end
79
+
80
+ describe "#exist?" do
81
+ it "doesn't raise when called on nested elements" do
82
+ browser.div(:id, 'no_such_div').link(:id, 'no_such_id').should_not exist
83
+ end
84
+ end
85
+
86
+ end
@@ -0,0 +1,114 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Em" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exists?" do
12
+ it "returns true if the element exists" do
13
+ browser.em(:id, "important-id").should exist
14
+ browser.em(:class, "important-class").should exist
15
+ browser.em(:xpath, "//em[@id='important-id']").should exist
16
+ browser.em(:index, 1).should exist
17
+ end
18
+
19
+ it "returns the first em if given no args" do
20
+ browser.em.should exist
21
+ end
22
+
23
+ it "returns false if the element does not exist" do
24
+ browser.em(:id, "no_such_id").should_not exist
25
+ end
26
+
27
+ it "raises TypeError when 'what' argument is invalid" do
28
+ lambda { browser.em(:id, 3.14).exists? }.should raise_error(TypeError)
29
+ end
30
+
31
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
32
+ lambda { browser.em(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
33
+ end
34
+ end
35
+
36
+ # Attribute methods
37
+ describe "#class_name" do
38
+ it "returns the class attribute if the element exists" do
39
+ browser.em(:id, "important-id").class_name.should == "important-class"
40
+ end
41
+
42
+ it "raises UnknownObjectException if the element does not exist" do
43
+ lambda { browser.em(:id, "no_such_id").class_name }.should raise_error(UnknownObjectException)
44
+ lambda { browser.em(:title, "no_such_title").class_name }.should raise_error(UnknownObjectException)
45
+ lambda { browser.em(:index, 1337).class_name }.should raise_error(UnknownObjectException)
46
+ lambda { browser.em(:xpath, "//em[@id='no_such_id']").class_name }.should raise_error(UnknownObjectException)
47
+ end
48
+ end
49
+
50
+ describe "#id" do
51
+ it "returns the id attribute if the element exists" do
52
+ browser.em(:class, 'important-class').id.should == "important-id"
53
+ end
54
+
55
+ it "raises UnknownObjectException if the element does not exist" do
56
+ lambda {browser.em(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
57
+ lambda {browser.em(:title, "no_such_id").id }.should raise_error(UnknownObjectException)
58
+ lambda {browser.em(:index, 1337).id }.should raise_error(UnknownObjectException)
59
+ end
60
+ end
61
+
62
+ describe "#title" do
63
+ it "returns the title of the element" do
64
+ browser.em(:class, "important-class").title.should == "ergo cogito"
65
+ end
66
+ end
67
+
68
+ describe "#text" do
69
+ it "returns the text of the element" do
70
+ browser.em(:id, "important-id").text.should == "ergo cogito"
71
+ end
72
+
73
+ it "raises UnknownObjectException if the element does not exist" do
74
+ lambda { browser.em(:id, "no_such_id").text }.should raise_error(UnknownObjectException)
75
+ lambda { browser.em(:title, "no_such_title").text }.should raise_error(UnknownObjectException)
76
+ lambda { browser.em(:index, 1337).text }.should raise_error(UnknownObjectException)
77
+ lambda { browser.em(:xpath, "//em[@id='no_such_id']").text }.should raise_error(UnknownObjectException)
78
+ end
79
+ end
80
+
81
+ describe "#respond_to?" do
82
+ it "returns true for all attribute methods" do
83
+ browser.em(:index, 1).should respond_to(:id)
84
+ browser.em(:index, 1).should respond_to(:class_name)
85
+ browser.em(:index, 1).should respond_to(:style)
86
+ browser.em(:index, 1).should respond_to(:text)
87
+ browser.em(:index, 1).should respond_to(:title)
88
+ end
89
+ end
90
+
91
+ # Manipulation methods
92
+ describe "#click" do
93
+ it "raises UnknownObjectException if the element does not exist" do
94
+ lambda { browser.em(:id, "no_such_id").click }.should raise_error(UnknownObjectException)
95
+ lambda { browser.em(:title, "no_such_title").click }.should raise_error(UnknownObjectException)
96
+ lambda { browser.em(:index, 1337).click }.should raise_error(UnknownObjectException)
97
+ lambda { browser.em(:xpath, "//em[@id='no_such_id']").click }.should raise_error(UnknownObjectException)
98
+ end
99
+ end
100
+
101
+ describe "#to_s" do
102
+ bug "WTR-350", :watir do
103
+ it "returns a human readable representation of the element" do
104
+ browser.em(:id, 'important-id').to_s.should ==
105
+ %q{tag: em
106
+ class: important-class
107
+ id: important-id
108
+ title: ergo cogito
109
+ text: ergo cogito}
110
+ end
111
+ end
112
+ end
113
+
114
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Ems" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of ems" do
12
+ browser.ems.length.should == 1
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the em at the given index" do
18
+ browser.ems[1].id.should == "important-id"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through ems correctly" do
24
+ count = 0
25
+
26
+ browser.ems.each_with_index do |e, index|
27
+ e.text.should == browser.em(:index, index+1).text
28
+ e.id.should == browser.em(:index, index+1).id
29
+ e.class_name.should == browser.em(:index, index+1).class_name
30
+
31
+ count += 1
32
+ end
33
+
34
+ count.should > 0
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,127 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "FileField" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe "#exist?" do
11
+ it "returns true if the file field exists" do
12
+ browser.file_field(:id, 'new_user_portrait').should exist
13
+ browser.file_field(:id, /new_user_portrait/).should exist
14
+ browser.file_field(:name, 'new_user_portrait').should exist
15
+ browser.file_field(:name, /new_user_portrait/).should exist
16
+ browser.file_field(:class, 'portrait').should exist
17
+ browser.file_field(:class, /portrait/).should exist
18
+ browser.file_field(:index, 1).should exist
19
+ browser.file_field(:xpath, "//input[@id='new_user_portrait']").should exist
20
+ end
21
+
22
+ it "returns the first file field if given no args" do
23
+ browser.file_field.should exist
24
+ end
25
+
26
+ it "returns true if the element exists (default how = :name)" do
27
+ browser.file_field("new_user_portrait").should exist
28
+ end
29
+
30
+ it "returns false if the file field doesn't exist" do
31
+ browser.file_field(:id, 'no_such_id').should_not exist
32
+ browser.file_field(:id, /no_such_id/).should_not exist
33
+ browser.file_field(:name, 'no_such_name').should_not exist
34
+ browser.file_field(:name, /no_such_name/).should_not exist
35
+ browser.file_field(:class, 'no_such_class').should_not exist
36
+ browser.file_field(:class, /no_such_class/).should_not exist
37
+ browser.file_field(:index, 1337).should_not exist
38
+ browser.file_field(:xpath, "//input[@id='no_such_id']").should_not exist
39
+ end
40
+
41
+ it "raises TypeError when 'what' argument is invalid" do
42
+ lambda { browser.file_field(:id, 3.14).exists? }.should raise_error(TypeError)
43
+ end
44
+
45
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
46
+ lambda { browser.file_field(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
47
+ end
48
+ end
49
+
50
+ # Attribute methods
51
+
52
+ describe "#class_name" do
53
+ it "returns the class attribute if the text field exists" do
54
+ browser.file_field(:index, 1).class_name.should == "portrait"
55
+ end
56
+
57
+ it "raises UnknownObjectException if the text field doesn't exist" do
58
+ lambda { browser.file_field(:index, 1337).class_name }.should raise_error(UnknownObjectException)
59
+ end
60
+ end
61
+
62
+ describe "#id" do
63
+ it "returns the id attribute if the text field exists" do
64
+ browser.file_field(:index, 1).id.should == "new_user_portrait"
65
+ end
66
+
67
+ it "raises UnknownObjectException if the text field doesn't exist" do
68
+ lambda { browser.file_field(:index, 1337).id }.should raise_error(UnknownObjectException)
69
+ end
70
+ end
71
+
72
+ describe "#name" do
73
+ it "returns the name attribute if the text field exists" do
74
+ browser.file_field(:index, 1).name.should == "new_user_portrait"
75
+ end
76
+
77
+ it "raises UnknownObjectException if the text field doesn't exist" do
78
+ lambda { browser.file_field(:index, 1337).name }.should raise_error(UnknownObjectException)
79
+ end
80
+ end
81
+
82
+ describe "#title" do
83
+ it "returns the title attribute if the text field exists" do
84
+ browser.file_field(:id, "new_user_portrait").title.should == "Smile!"
85
+ end
86
+ end
87
+
88
+ describe "#type" do
89
+ it "returns the type attribute if the text field exists" do
90
+ browser.file_field(:index, 1).type.should == "file"
91
+ end
92
+
93
+ it "raises UnknownObjectException if the text field doesn't exist" do
94
+ lambda { browser.file_field(:index, 1337).type }.should raise_error(UnknownObjectException)
95
+ end
96
+ end
97
+
98
+ describe "#respond_to?" do
99
+ it "returns true for all attribute methods" do
100
+ browser.file_field(:index, 1).should respond_to(:class_name)
101
+ browser.file_field(:index, 1).should respond_to(:id)
102
+ browser.file_field(:index, 1).should respond_to(:name)
103
+ browser.file_field(:index, 1).should respond_to(:title)
104
+ browser.file_field(:index, 1).should respond_to(:type)
105
+ browser.file_field(:index, 1).should respond_to(:value)
106
+ end
107
+ end
108
+
109
+ # Manipulation methods
110
+
111
+ describe "#set" do
112
+ bug "WTR-336", :watir do
113
+ it "is able to set a file path in the field and click the upload button and fire the onchange event" do
114
+ browser.goto("#{WatirSpec.host}/forms_with_input_elements.html")
115
+
116
+ path = File.expand_path(__FILE__)
117
+
118
+ browser.file_field(:name, "new_user_portrait").set path
119
+ browser.file_field(:name, "new_user_portrait").value.should == path
120
+ messages.first.should == path
121
+ browser.button(:name, "new_user_submit").click
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ end