operawatir 0.3-jruby

Sign up to get free protection for your applications and to get access to all the features.
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,59 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ bug "WTR-357", :watir do
5
+ describe "TableHeaders" do
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/tables.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the correct number of table theads (page context)" do
12
+ browser.theads.length.should == 1
13
+ end
14
+
15
+ it "returns the correct number of table theads (table context)" do
16
+ browser.table(:index, 1).theads.length.should == 1
17
+ end
18
+ end
19
+
20
+ describe "#[]" do
21
+ it "returns the row at the given index (page context)" do
22
+ browser.theads[1].id.should == "tax_headers"
23
+ end
24
+
25
+ it "returns the row at the given index (table context)" do
26
+ browser.table(:index, 1).theads[1].id.should == "tax_headers"
27
+ end
28
+ end
29
+
30
+ describe "#each" do
31
+ it "iterates through table theads correctly (page context)" do
32
+ count = 0
33
+
34
+ browser.theads.each_with_index do |thead, index|
35
+ thead.name.should == browser.thead(:index, index+1).name
36
+ thead.id.should == browser.thead(:index, index+1).id
37
+
38
+ count += 1
39
+ end
40
+
41
+ count.should > 0
42
+ end
43
+
44
+ it "iterates through table theads correctly (table context)" do
45
+ table = browser.table(:index, 1)
46
+ count = 0
47
+
48
+ table.theads.each_with_index do |thead, index|
49
+ thead.name.should == table.thead(:index, index+1).name
50
+ thead.id.should == table.thead(:index, index+1).id
51
+
52
+ count += 1
53
+ end
54
+
55
+ count.should > 0
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "TableRow" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/tables.html")
8
+ end
9
+
10
+ describe "#exists?" do
11
+ it "returns true if the table row exists" do
12
+ browser.row(:id, "outer_first").should exist
13
+ browser.row(:id, /outer_first/).should exist
14
+ browser.row(:index, 1).should exist
15
+ browser.row(:xpath, "//tr[@id='outer_first']")
16
+ end
17
+
18
+ it "returns the first row if given no args" do
19
+ browser.row.should exist
20
+ end
21
+
22
+ it "returns true if the element exists (default how = :id)" do
23
+ browser.row("outer_last").should exist
24
+ end
25
+
26
+ it "returns false if the table row doesn't exist" do
27
+ browser.row(:id, "no_such_id").should_not exist
28
+ browser.row(:id, /no_such_id/).should_not exist
29
+ browser.row(:index, 1337).should_not exist
30
+ browser.row(:xpath, "//tr[@id='no_such_id']")
31
+ end
32
+
33
+ it "raises TypeError when 'what' argument is invalid" do
34
+ lambda { browser.row(:id, 3.14).exists? }.should raise_error(TypeError)
35
+ end
36
+
37
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
38
+ lambda { browser.row(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
39
+ end
40
+ end
41
+
42
+ describe "#click" do
43
+ it "fires the rows's onclick event" do
44
+ browser.row(:id, 'inner_first').click
45
+ messages.should include('tr')
46
+ end
47
+ end
48
+
49
+ describe "#column_count" do
50
+ it "returns the number of columns (cells) in the row" do
51
+ browser.table(:id, 'outer').rows[1].column_count.should == 2
52
+ browser.table(:id, 'outer')[2].column_count.should == 2
53
+ browser.table(:id, 'colspan')[1].column_count.should == 1
54
+ browser.table(:id, 'colspan').rows[2].column_count.should == 2
55
+ browser.rows[1].column_count.should == 4
56
+ end
57
+ end
58
+
59
+ describe "#length" do
60
+ bug "WTR-354", :watir do
61
+ it "returns the number of rows" do
62
+ browser.table(:id, 'outer').rows.length.should == 3
63
+ browser.table(:id, 'inner').rows.length.should == 1
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#[]" do
69
+ it "returns the nth cell of the parent row" do
70
+ browser.table(:id, 'outer').row(:index, 1)[1].text.should == "Table 1, Row 1, Cell 1"
71
+ browser.table(:id, 'outer')[1][1].text.should == "Table 1, Row 1, Cell 1"
72
+ browser.table(:id, 'outer')[3][1].text.should == "Table 1, Row 3, Cell 1"
73
+ end
74
+
75
+ it "raises UnknownCellException if the index is out of bounds" do
76
+ lambda { browser.table(:id, 'outer').row(:index, 1)[1337] }.should raise_error(UnknownCellException)
77
+ lambda { browser.table(:id, 'outer')[1][1337] }.should raise_error(UnknownCellException)
78
+ end
79
+ end
80
+
81
+ bug "WTR-359", :watir do
82
+ describe "#child_cell" do
83
+ it "returns the nth cell of the parent row" do
84
+ browser.table(:id, 'outer').row(:index, 1).child_cell(1).text.should == "Table 1, Row 1, Cell 1"
85
+ browser.table(:id, 'outer')[1].child_cell(1).text.should == "Table 1, Row 1, Cell 1"
86
+ browser.table(:id, 'outer')[3].child_cell(1).text.should == "Table 1, Row 3, Cell 1"
87
+ end
88
+
89
+ it "raises UnknownCellException if the index is out of bounds" do
90
+ lambda { browser.table(:id, 'outer').row(:index, 1).child_cell(1337) }.should raise_error(UnknownCellException)
91
+ lambda { browser.table(:id, 'outer')[1].child_cell(1337) }.should raise_error(UnknownCellException)
92
+ end
93
+ end
94
+
95
+ describe "#each" do
96
+ it "iterates correctly through the cells of the row" do
97
+ browser.table(:id, 'outer')[2].each_with_index do |cell,idx|
98
+ cell.id.should == "t1_r2_c#{idx + 1}"
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "TableRows" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/tables.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ bug "WTR-354", :watir do
12
+ it "returns the correct number of cells (table context)" do
13
+ browser.table(:id, 'inner').rows.length.should == 1
14
+ browser.table(:id, 'outer').rows.length.should == 3
15
+ end
16
+ end
17
+
18
+ it "returns the correct number of cells (page context)" do
19
+ browser.rows.length.should == 14
20
+ end
21
+ end
22
+
23
+ describe "#[]" do
24
+ it "returns the row at the given index (table context)" do
25
+ browser.table(:id, 'outer').rows[1].id.should == "outer_first"
26
+ end
27
+
28
+ it "returns the row at the given index (page context)" do
29
+ browser.rows[1].id.should == "thead_row_1"
30
+ end
31
+ end
32
+
33
+ describe "#each" do
34
+ it "iterates through rows correctly" do
35
+ # rows inside a table
36
+ inner_table = browser.table(:id, 'inner')
37
+ count = 0
38
+
39
+ inner_table.rows.each_with_index do |r, index|
40
+ r.name.should == inner_table.row(:index, index+1).name
41
+ r.id.should == inner_table.row(:index, index+1).id
42
+ r.value.should == inner_table.row(:index, index+1).value
43
+
44
+ count += 1
45
+ end
46
+
47
+ count.should > 0
48
+ # rows inside a table (should not include rows inside a table inside a table)
49
+ outer_table = browser.table(:id, 'outer')
50
+ count = 0
51
+
52
+ outer_table.rows.each_with_index do |r, index|
53
+ r.name.should == outer_table.row(:index, index+1).name
54
+ r.id.should == outer_table.row(:index, index+1).id
55
+ r.value.should == outer_table.row(:index, index+1).value
56
+
57
+ count += 1
58
+ end
59
+
60
+ count.should > 0
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,170 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Table" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/tables.html")
8
+ end
9
+
10
+ # Exists
11
+ describe "#exists?" do
12
+ it "returns true if the table exists" do
13
+ browser.table(:id, 'axis_example').should exist
14
+ browser.table(:id, /axis_example/).should exist
15
+ browser.table(:index, 1).should exist
16
+ browser.table(:xpath, "//table[@id='axis_example']").should exist
17
+ end
18
+
19
+ it "returns the first table if given no args" do
20
+ browser.table.should exist
21
+ end
22
+
23
+ it "returns true if the element exists (default how = :id)" do
24
+ browser.table("axis_example").should exist
25
+ end
26
+
27
+ it "returns false if the table does not exist" do
28
+ browser.table(:id, 'no_such_id').should_not exist
29
+ browser.table(:id, /no_such_id/).should_not exist
30
+ browser.table(:index, 1337).should_not exist
31
+ browser.table(:xpath, "//table[@id='no_such_id']").should_not exist
32
+ end
33
+
34
+ it "checks the tag name when locating by xpath" do
35
+ browser.table(:xpath, "//table//td").should_not exist
36
+ browser.table(:xpath, "//table").should exist
37
+ end
38
+
39
+ it "raises TypeError when 'what' argument is invalid" do
40
+ lambda { browser.table(:id, 3.14).exists? }.should raise_error(TypeError)
41
+ end
42
+
43
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
44
+ lambda { browser.table(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
45
+ end
46
+ end
47
+
48
+ describe "#locate" do
49
+ it "is not nil for existing tables" do
50
+ browser.table(:id, 'axis_example').locate.should_not be_nil
51
+ end
52
+ end
53
+
54
+ # Other
55
+ describe "#to_a" do
56
+ it "returns a two-dimensional array representation of the table" do
57
+ browser.table(:id, 'inner').to_a.should == [["Table 2, Row 1, Cell 1", "Table 2, Row 1, Cell 2"]]
58
+ end
59
+ end
60
+
61
+ describe "#click" do
62
+ it "fires the table's onclick event" do
63
+ browser.table(:id, 'inner').click
64
+ messages.first.should == 'table'
65
+ end
66
+ end
67
+
68
+ describe "#row_count" do
69
+ bug "WTR-354", :watir do
70
+ it "counts the number of rows correctly" do
71
+ browser.table(:id, 'inner').row_count.should == 1
72
+ browser.table(:id, 'outer').row_count.should == 3
73
+ end
74
+ end
75
+
76
+ it "raises an UnknownObjectException if the table doesn't exist" do
77
+ lambda { browser.table(:id, 'no_such_id').row_count }.should raise_error(UnknownObjectException)
78
+ lambda { browser.table(:index, 1337).row_count }.should raise_error(UnknownObjectException)
79
+ end
80
+ end
81
+
82
+ describe "#row_values" do
83
+ it "gets row values" do
84
+ browser.table(:id, 'outer').row_values(1).should == ["Table 1, Row 1, Cell 1", "Table 1, Row 1, Cell 2"]
85
+ browser.table(:id, 'inner').row_values(1).should == ["Table 2, Row 1, Cell 1", "Table 2, Row 1, Cell 2"]
86
+ browser.table(:id, 'outer').row_values(3).should == ["Table 1, Row 3, Cell 1", "Table 1, Row 3, Cell 2"]
87
+ end
88
+ end
89
+
90
+ describe "#column_count" do
91
+ it "counts the number of columns correctly" do
92
+ browser.table(:id, 'inner').column_count.should == 2
93
+ browser.table(:id, 'outer').column_count.should == 2
94
+ end
95
+
96
+ it "raises an UnknownObjectException if the table doesn't exist" do
97
+ lambda { browser.table(:id, 'no_such_id').column_count }.should raise_error(UnknownObjectException)
98
+ lambda { browser.table(:index, 1337).column_count }.should raise_error(UnknownObjectException)
99
+ end
100
+ end
101
+
102
+ describe "#column_values" do
103
+ it "gets column values" do
104
+ browser.table(:id, 'inner').column_values(1).should == ["Table 2, Row 1, Cell 1"]
105
+ browser.table(:id, 'outer').column_values(1).should == ["Table 1, Row 1, Cell 1", "Table 1, Row 2, Cell 1", "Table 1, Row 3, Cell 1"]
106
+ end
107
+
108
+ it "raises UnknownCellException when trying to locate non-existing cell" do
109
+ lambda { browser.table(:id, 'inner').column_values(1337) }.should raise_error(UnknownCellException)
110
+ end
111
+ end
112
+
113
+ describe "#[]" do
114
+ it "returns the nth child row" do
115
+ browser.table(:id, 'outer')[1].id.should == "outer_first"
116
+ browser.table(:id, 'inner')[1].id.should == "inner_first"
117
+ browser.table(:id, 'outer')[3].id.should == "outer_last"
118
+ end
119
+ it "raises UnknownRowException if the index is out of bounds" do
120
+ lambda { browser.table(:id, 'outer')[1337] }.should raise_error(UnknownRowException)
121
+ end
122
+ end
123
+
124
+ describe "#child_row" do
125
+ it "returns the nth child row" do
126
+ browser.table(:id, 'outer').child_row(1).id.should == "outer_first"
127
+ browser.table(:id, 'inner').child_row(1).id.should == "inner_first"
128
+ browser.table(:id, 'outer').child_row(3).id.should == "outer_last"
129
+ end
130
+ it "raises UnknownRowException if the index is out of bounds" do
131
+ lambda { browser.table(:id, 'outer').child_row(1337) }.should raise_error(UnknownRowException)
132
+ end
133
+ end
134
+
135
+ describe "#child_cell" do
136
+ it "returns the nth child row" do
137
+ browser.table(:id, 'outer').child_cell(5).text.should == "Table 1, Row 3, Cell 1"
138
+ end
139
+ it "raises UnknownCellException if the index is out of bounds" do
140
+ lambda { browser.table(:id, 'outer').child_cell(1337) }.should raise_error(UnknownCellException)
141
+ end
142
+ end
143
+
144
+ describe "#each" do
145
+ it "iterates through the table's rows" do
146
+ ids = ["outer_first", "outer_second", "outer_last"]
147
+ browser.table(:id, 'outer').each_with_index do |r, idx|
148
+ r.id.should == ids[idx]
149
+ end
150
+ end
151
+ end
152
+
153
+ describe "#body" do
154
+ it "returns the correct instance of TableBody" do
155
+ body = browser.table(:index, 1).body(:id, 'first')
156
+ body.should be_instance_of(TableBody)
157
+ body[1][1].text.should == "March 2008"
158
+ end
159
+ end
160
+
161
+ describe "#bodies" do
162
+ it "returns the correct instance of TableBodies" do
163
+ bodies = browser.table(:index, 1).bodies
164
+ bodies.should be_instance_of(TableBodies)
165
+ bodies[1].id.should == "first"
166
+ bodies[2].id.should == "second"
167
+ end
168
+ end
169
+
170
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "Tables" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/tables.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of tables" do
12
+ browser.tables.length.should == 4
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the p at the given index" do
18
+ browser.tables[1].id.should == "axis_example"
19
+ browser.tables[2].id.should == "outer"
20
+ browser.tables[3].id.should == "inner"
21
+ end
22
+ end
23
+
24
+ describe "#each" do
25
+ it "iterates through tables correctly" do
26
+ count = 0
27
+
28
+ browser.tables.each_with_index do |t, index|
29
+ t.name.should == browser.table(:index, index+1).name
30
+ t.id.should == browser.table(:index, index+1).id
31
+ t.value.should == browser.table(:index, index+1).value
32
+
33
+ count += 1
34
+ end
35
+
36
+ count.should > 0
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,315 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../spec_helper", __FILE__)
3
+
4
+ describe "TextField" 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.text_field(:id, 'new_user_email').should exist
14
+ browser.text_field(:id, /new_user_email/).should exist
15
+ browser.text_field(:name, 'new_user_email').should exist
16
+ browser.text_field(:name, /new_user_email/).should exist
17
+ browser.text_field(:value, 'Developer').should exist
18
+ browser.text_field(:value, /Developer/).should exist
19
+ browser.text_field(:text, 'Developer').should exist
20
+ browser.text_field(:text, /Developer/).should exist
21
+ browser.text_field(:class, 'name').should exist
22
+ browser.text_field(:class, /name/).should exist
23
+ browser.text_field(:index, 1).should exist
24
+ browser.text_field(:xpath, "//input[@id='new_user_email']").should exist
25
+ browser.text_field(:label, "First name").should exist
26
+ browser.text_field(:label, /(Last|First) name/).should exist
27
+ end
28
+
29
+ it "returns true if the element exists (default how = :name)" do
30
+ browser.text_field("new_user_email").should exist
31
+ end
32
+
33
+ it "returns the first text field if given no args" do
34
+ browser.text_field.should exist
35
+ end
36
+
37
+ it "returns true if the element exists (no type attribute)" do
38
+ browser.text_field(:id, 'new_user_first_name').should exist
39
+ end
40
+
41
+ it "returns true if the element exists (invalid type attribute)" do
42
+ browser.text_field(:id, 'new_user_last_name').should exist
43
+ end
44
+
45
+ it "returns false if the element does not exist" do
46
+ browser.text_field(:id, 'no_such_id').should_not exist
47
+ browser.text_field(:id, /no_such_id/).should_not exist
48
+ browser.text_field(:name, 'no_such_name').should_not exist
49
+ browser.text_field(:name, /no_such_name/).should_not exist
50
+ browser.text_field(:value, 'no_such_value').should_not exist
51
+ browser.text_field(:value, /no_such_value/).should_not exist
52
+ browser.text_field(:text, 'no_such_text').should_not exist
53
+ browser.text_field(:text, /no_such_text/).should_not exist
54
+ browser.text_field(:class, 'no_such_class').should_not exist
55
+ browser.text_field(:class, /no_such_class/).should_not exist
56
+ browser.text_field(:index, 1337).should_not exist
57
+ browser.text_field(:xpath, "//input[@id='no_such_id']").should_not exist
58
+ browser.text_field(:label, "bad label").should_not exist
59
+ browser.text_field(:label, /bad label/).should_not exist
60
+ end
61
+
62
+ it "raises TypeError when 'what' argument is invalid" do
63
+ lambda { browser.text_field(:id, 3.14).exists? }.should raise_error(TypeError)
64
+ end
65
+
66
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
67
+ lambda { browser.text_field(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
68
+ end
69
+ end
70
+
71
+ # Attribute methods
72
+ describe "#id" do
73
+ it "returns the id attribute if the text field exists" do
74
+ browser.text_field(:index, 4).id.should == "new_user_occupation"
75
+ end
76
+
77
+ it "raises UnknownObjectException if the text field doesn't exist" do
78
+ lambda { browser.text_field(:index, 1337).id }.should raise_error(UnknownObjectException)
79
+ end
80
+ end
81
+
82
+ describe "#name" do
83
+ it "returns the name attribute if the text field exists" do
84
+ browser.text_field(:index, 4).name.should == "new_user_occupation"
85
+ end
86
+
87
+ it "raises UnknownObjectException if the text field doesn't exist" do
88
+ lambda { browser.text_field(:index, 1337).name }.should raise_error(UnknownObjectException)
89
+ end
90
+ end
91
+
92
+ describe "#title" do
93
+ it "returns the title attribute if the text field exists" do
94
+ browser.text_field(:id, "new_user_code").title.should == "Your personal code"
95
+ end
96
+
97
+ it "raises UnknownObjectException if the text field doesn't exist" do
98
+ lambda { browser.text_field(:index, 1337).title }.should raise_error(UnknownObjectException)
99
+ end
100
+ end
101
+
102
+ describe "#type" do
103
+ it "returns the type attribute if the text field exists" do
104
+ browser.text_field(:index, 4).type.should == "text"
105
+ end
106
+
107
+ it "returns 'text' if the type attribute is invalid" do
108
+ browser.text_field(:id, 'new_user_last_name').type.should == "text"
109
+ end
110
+
111
+ it "returns 'text' if the type attribute does not exist" do
112
+ browser.text_field(:id, 'new_user_first_name').type.should == "text"
113
+ end
114
+
115
+ it "raises UnknownObjectException if the text field doesn't exist" do
116
+ lambda { browser.text_field(:index, 1337).type }.should raise_error(UnknownObjectException)
117
+ end
118
+ end
119
+
120
+ describe "#value" do
121
+ it "returns the value attribute if the text field exists" do
122
+ browser.text_field(:name, "new_user_occupation").value.should == "Developer"
123
+ browser.text_field(:index, 4).value.should == "Developer"
124
+ browser.text_field(:name, /new_user_occupation/i).value.should == "Developer"
125
+ end
126
+
127
+ it "raises UnknownObjectException if the text field doesn't exist" do
128
+ lambda { browser.text_field(:index, 1337).value }.should raise_error(UnknownObjectException)
129
+ end
130
+ end
131
+
132
+ describe "#respond_to?" do
133
+ it "returns true for all attribute methods" do
134
+ browser.text_field(:index, 1).should respond_to(:class_name)
135
+ browser.text_field(:index, 1).should respond_to(:id)
136
+ browser.text_field(:index, 1).should respond_to(:name)
137
+ browser.text_field(:index, 1).should respond_to(:title)
138
+ browser.text_field(:index, 1).should respond_to(:type)
139
+ browser.text_field(:index, 1).should respond_to(:value)
140
+ end
141
+ end
142
+
143
+ # Access methods
144
+ describe "#enabled?" do
145
+ it "returns true for enabled text fields" do
146
+ browser.text_field(:name, "new_user_occupation").should be_enabled
147
+ browser.text_field(:id, "new_user_email").should be_enabled
148
+ end
149
+
150
+ it "returns false for disabled text fields" do
151
+ browser.text_field(:name, "new_user_species").should_not be_enabled
152
+ end
153
+
154
+ it "raises UnknownObjectException if the text field doesn't exist" do
155
+ lambda { browser.text_field(:id, "no_such_id").enabled? }.should raise_error(UnknownObjectException)
156
+ end
157
+ end
158
+
159
+ describe "#disabled?" do
160
+ it "returns true if the text field is disabled" do
161
+ browser.text_field(:id, 'new_user_species').should be_disabled
162
+ end
163
+
164
+ it "returns false if the text field is enabled" do
165
+ browser.text_field(:index, 1).should_not be_disabled
166
+ end
167
+
168
+ it "raises UnknownObjectException if the text field doesn't exist" do
169
+ lambda { browser.text_field(:index, 1337).disabled? }.should raise_error(UnknownObjectException)
170
+ end
171
+ end
172
+
173
+ describe "#readonly?" do
174
+ it "returns true for read-only text fields" do
175
+ browser.text_field(:name, "new_user_code").should be_readonly
176
+ browser.text_field(:id, "new_user_code").should be_readonly
177
+ end
178
+
179
+ it "returns false for writeable text fields" do
180
+ browser.text_field(:name, "new_user_email").should_not be_readonly
181
+ end
182
+
183
+ it "raises UnknownObjectException if the text field doesn't exist" do
184
+ lambda { browser.text_field(:id, 'no_such_id').readonly? }.should raise_error(UnknownObjectException)
185
+ end
186
+ end
187
+
188
+ # Manipulation methods
189
+ describe "#append" do
190
+ it "appends the text to the text field" do
191
+ browser.text_field(:name, "new_user_occupation").append(" Append This")
192
+ browser.text_field(:name, "new_user_occupation").value.should == "Developer Append This"
193
+ end
194
+
195
+ it "appends multi-byte characters" do
196
+ browser.text_field(:name, "new_user_occupation").append(" ijij")
197
+ browser.text_field(:name, "new_user_occupation").value.should == "Developer ijij"
198
+ end
199
+
200
+ it "raises ObjectReadOnlyException if the object is read only" do
201
+ lambda { browser.text_field(:id, "new_user_code").append("Append This") }.should raise_error(ObjectReadOnlyException)
202
+ end
203
+
204
+ it "raises ObjectDisabledException if the object is disabled" do
205
+ lambda { browser.text_field(:name, "new_user_species").append("Append This") }.should raise_error(ObjectDisabledException)
206
+ end
207
+
208
+ it "raises UnknownObjectException if the object doesn't exist" do
209
+ lambda { browser.text_field(:name, "no_such_name").append("Append This") }.should raise_error(UnknownObjectException)
210
+ end
211
+ end
212
+
213
+ describe "#clear" do
214
+ it "removes all text from the text field" do
215
+ browser.text_field(:name, "new_user_occupation").clear
216
+ browser.text_field(:name, "new_user_occupation").value.should be_empty
217
+ browser.text_field(:id, "delete_user_comment").clear
218
+ browser.text_field(:id, "delete_user_comment").value.should be_empty
219
+ end
220
+
221
+ it "raises UnknownObjectException if the text field doesn't exist" do
222
+ lambda { browser.text_field(:id, "no_such_id").clear }.should raise_error(UnknownObjectException)
223
+ end
224
+ end
225
+
226
+ describe "#drag_contents_to" do
227
+ it "drags contents to another text field" do
228
+ browser.text_field(:name, "new_user_first_name").set("Smith")
229
+ browser.text_field(:name, "new_user_first_name").drag_contents_to(:name, "new_user_last_name")
230
+ browser.text_field(:name, "new_user_first_name").value.should be_empty
231
+ browser.text_field(:id, "new_user_last_name").value.should == "Smith"
232
+ end
233
+
234
+ it "raises UnknownObjectException if either of the text fields doesn't exist" do
235
+ lambda { browser.text_field(:id, "no_such_id").drag_contents_to(:name, "new_user_last_name") }.should raise_error(UnknownObjectException)
236
+ lambda { browser.text_field(:name, "new_user_first_name").drag_contents_to(:id, "no_such_id") }.should raise_error(UnknownObjectException)
237
+ end
238
+ end
239
+
240
+ describe "#value=" do
241
+ it "sets the value of the element" do
242
+ browser.text_field(:id, 'new_user_email').value = 'Hello Cruel World'
243
+ browser.text_field(:id, "new_user_email").value.should == 'Hello Cruel World'
244
+ end
245
+
246
+ it "is able to set multi-byte characters" do
247
+ browser.text_field(:name, "new_user_occupation").value = "ijij"
248
+ browser.text_field(:name, "new_user_occupation").value.should == "ijij"
249
+ end
250
+
251
+ it "sets the value of a textarea element" do
252
+ browser.text_field(:id, 'delete_user_comment').value = 'Hello Cruel World'
253
+ browser.text_field(:id, "delete_user_comment").value.should == 'Hello Cruel World'
254
+ end
255
+
256
+ it "raises UnknownObjectException if the text field doesn't exist" do
257
+ lambda { browser.text_field(:name, "no_such_name").value = 'yo' }.should raise_error(UnknownObjectException)
258
+ end
259
+ end
260
+
261
+ describe "#set" do
262
+ it "sets the value of the element" do
263
+ browser.text_field(:id, 'new_user_email').set('Bye Cruel World')
264
+ browser.text_field(:id, "new_user_email").value.should == 'Bye Cruel World'
265
+ end
266
+
267
+ it "sets the value of a textarea element" do
268
+ browser.text_field(:id, 'delete_user_comment').set('Hello Cruel World')
269
+ browser.text_field(:id, "delete_user_comment").value.should == 'Hello Cruel World'
270
+ end
271
+
272
+ bug "WTR-341", :watir do
273
+ it "fires events" do
274
+ browser.text_field(:id, "new_user_username").set("Hello World")
275
+ browser.span(:id, "current_length").text.should == "11"
276
+ end
277
+ end
278
+
279
+ it "sets the value of a password field" do
280
+ browser.text_field(:name , 'new_user_password').set('secret')
281
+ browser.text_field(:name , 'new_user_password').value.should == 'secret'
282
+ end
283
+
284
+ it "sets the value when accessed through the enclosing Form" do
285
+ browser.form(:id, 'new_user').text_field(:name , 'new_user_password').set('secret')
286
+ browser.form(:id, 'new_user').text_field(:name , 'new_user_password').value.should == 'secret'
287
+ end
288
+
289
+ it "is able to set multi-byte characters" do
290
+ browser.text_field(:name, "new_user_occupation").set("ijij")
291
+ browser.text_field(:name, "new_user_occupation").value.should == "ijij"
292
+ end
293
+
294
+ it "raises UnknownObjectException if the text field doesn't exist" do
295
+ lambda { browser.text_field(:id, "no_such_id").set('secret') }.should raise_error(UnknownObjectException)
296
+ end
297
+ end
298
+
299
+ describe "#verify_contains" do
300
+ it "verifys that a text field contains its value" do
301
+ browser.text_field(:name, "new_user_occupation").verify_contains("Developer").should be_true
302
+ browser.text_field(:name, "new_user_occupation").verify_contains(/Developer/).should be_true
303
+ end
304
+
305
+ it "doesn't verify that a text field contains a non-existing value" do
306
+ browser.text_field(:name, "new_user_email").verify_contains("no_such_text").should be_false
307
+ browser.text_field(:name, "new_user_email").verify_contains(/no_such_text/).should be_false
308
+ end
309
+
310
+ it "raises UnknownObjectException if the text field doesn't exist" do
311
+ lambda { browser.text_field(:id, "no_such_id").verify_contains("Developer") }.should raise_error(UnknownObjectException)
312
+ end
313
+ end
314
+
315
+ end