watir-webdriver 0.0.1.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/.gitmodules +3 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +32 -0
  6. data/Rakefile +107 -0
  7. data/TODO +15 -0
  8. data/VERSION +1 -0
  9. data/lib/watir-webdriver.rb +74 -0
  10. data/lib/watir-webdriver/base_element.rb +347 -0
  11. data/lib/watir-webdriver/browser.rb +130 -0
  12. data/lib/watir-webdriver/browserbot.js +34 -0
  13. data/lib/watir-webdriver/collections/buttons_collection.rb +13 -0
  14. data/lib/watir-webdriver/collections/element_collection.rb +45 -0
  15. data/lib/watir-webdriver/collections/table_rows_collection.rb +14 -0
  16. data/lib/watir-webdriver/collections/text_fields_collection.rb +13 -0
  17. data/lib/watir-webdriver/container.rb +24 -0
  18. data/lib/watir-webdriver/core_ext/string.rb +22 -0
  19. data/lib/watir-webdriver/elements/button.rb +27 -0
  20. data/lib/watir-webdriver/elements/checkbox.rb +23 -0
  21. data/lib/watir-webdriver/elements/file_field.rb +20 -0
  22. data/lib/watir-webdriver/elements/form.rb +11 -0
  23. data/lib/watir-webdriver/elements/generated.rb +941 -0
  24. data/lib/watir-webdriver/elements/headings.rb +48 -0
  25. data/lib/watir-webdriver/elements/hidden.rb +18 -0
  26. data/lib/watir-webdriver/elements/image.rb +33 -0
  27. data/lib/watir-webdriver/elements/input.rb +39 -0
  28. data/lib/watir-webdriver/elements/link.rb +13 -0
  29. data/lib/watir-webdriver/elements/option.rb +36 -0
  30. data/lib/watir-webdriver/elements/radio.rb +23 -0
  31. data/lib/watir-webdriver/elements/select_list.rb +73 -0
  32. data/lib/watir-webdriver/elements/shared_radio_checkbox.rb +13 -0
  33. data/lib/watir-webdriver/elements/table.rb +18 -0
  34. data/lib/watir-webdriver/elements/table_row.rb +17 -0
  35. data/lib/watir-webdriver/elements/text_field.rb +60 -0
  36. data/lib/watir-webdriver/exception.rb +20 -0
  37. data/lib/watir-webdriver/locators/button_locator.rb +57 -0
  38. data/lib/watir-webdriver/locators/element_locator.rb +269 -0
  39. data/lib/watir-webdriver/locators/table_row_locator.rb +25 -0
  40. data/lib/watir-webdriver/locators/text_field_locator.rb +61 -0
  41. data/lib/watir-webdriver/xpath_support.rb +23 -0
  42. data/spec/element_locator_spec.rb +11 -0
  43. data/spec/spec_helper.rb +16 -0
  44. data/spec/watirspec/area_spec.rb +78 -0
  45. data/spec/watirspec/areas_spec.rb +31 -0
  46. data/spec/watirspec/browser_spec.rb +262 -0
  47. data/spec/watirspec/button_spec.rb +242 -0
  48. data/spec/watirspec/buttons_spec.rb +48 -0
  49. data/spec/watirspec/checkbox_spec.rb +272 -0
  50. data/spec/watirspec/checkboxes_spec.rb +32 -0
  51. data/spec/watirspec/dd_spec.rb +136 -0
  52. data/spec/watirspec/dds_spec.rb +31 -0
  53. data/spec/watirspec/div_spec.rb +222 -0
  54. data/spec/watirspec/divs_spec.rb +31 -0
  55. data/spec/watirspec/dl_spec.rb +136 -0
  56. data/spec/watirspec/dls_spec.rb +32 -0
  57. data/spec/watirspec/dt_spec.rb +136 -0
  58. data/spec/watirspec/dts_spec.rb +31 -0
  59. data/spec/watirspec/element_spec.rb +87 -0
  60. data/spec/watirspec/em_spec.rb +110 -0
  61. data/spec/watirspec/ems_spec.rb +32 -0
  62. data/spec/watirspec/filefield_spec.rb +119 -0
  63. data/spec/watirspec/filefields_spec.rb +32 -0
  64. data/spec/watirspec/form_spec.rb +63 -0
  65. data/spec/watirspec/forms_spec.rb +33 -0
  66. data/spec/watirspec/frame_spec.rb +140 -0
  67. data/spec/watirspec/frames_spec.rb +62 -0
  68. data/spec/watirspec/hidden_spec.rb +102 -0
  69. data/spec/watirspec/hiddens_spec.rb +32 -0
  70. data/spec/watirspec/hn_spec.rb +93 -0
  71. data/spec/watirspec/hns_spec.rb +38 -0
  72. data/spec/watirspec/image_spec.rb +207 -0
  73. data/spec/watirspec/images_spec.rb +31 -0
  74. data/spec/watirspec/label_spec.rb +75 -0
  75. data/spec/watirspec/labels_spec.rb +31 -0
  76. data/spec/watirspec/li_spec.rb +127 -0
  77. data/spec/watirspec/lib/guards.rb +59 -0
  78. data/spec/watirspec/lib/server.rb +127 -0
  79. data/spec/watirspec/lib/spec_helper.rb +79 -0
  80. data/spec/watirspec/lib/watirspec.rb +72 -0
  81. data/spec/watirspec/link_spec.rb +165 -0
  82. data/spec/watirspec/links_spec.rb +35 -0
  83. data/spec/watirspec/lis_spec.rb +31 -0
  84. data/spec/watirspec/map_spec.rb +92 -0
  85. data/spec/watirspec/maps_spec.rb +32 -0
  86. data/spec/watirspec/meta_spec.rb +22 -0
  87. data/spec/watirspec/metas_spec.rb +30 -0
  88. data/spec/watirspec/ol_spec.rb +78 -0
  89. data/spec/watirspec/ols_spec.rb +31 -0
  90. data/spec/watirspec/option_spec.rb +173 -0
  91. data/spec/watirspec/p_spec.rb +143 -0
  92. data/spec/watirspec/pre_spec.rb +125 -0
  93. data/spec/watirspec/pres_spec.rb +31 -0
  94. data/spec/watirspec/ps_spec.rb +31 -0
  95. data/spec/watirspec/radio_spec.rb +278 -0
  96. data/spec/watirspec/radios_spec.rb +32 -0
  97. data/spec/watirspec/select_list_spec.rb +318 -0
  98. data/spec/watirspec/select_lists_spec.rb +35 -0
  99. data/spec/watirspec/span_spec.rb +157 -0
  100. data/spec/watirspec/spans_spec.rb +57 -0
  101. data/spec/watirspec/spec_helper.rb +17 -0
  102. data/spec/watirspec/strong_spec.rb +89 -0
  103. data/spec/watirspec/strongs_spec.rb +32 -0
  104. data/spec/watirspec/table_bodies_spec.rb +45 -0
  105. data/spec/watirspec/table_body_spec.rb +98 -0
  106. data/spec/watirspec/table_cell_spec.rb +68 -0
  107. data/spec/watirspec/table_cells_spec.rb +47 -0
  108. data/spec/watirspec/table_footer_spec.rb +85 -0
  109. data/spec/watirspec/table_footers_spec.rb +47 -0
  110. data/spec/watirspec/table_header_spec.rb +85 -0
  111. data/spec/watirspec/table_headers_spec.rb +45 -0
  112. data/spec/watirspec/table_row_spec.rb +87 -0
  113. data/spec/watirspec/table_rows_spec.rb +50 -0
  114. data/spec/watirspec/table_spec.rb +166 -0
  115. data/spec/watirspec/tables_spec.rb +33 -0
  116. data/spec/watirspec/text_field_spec.rb +276 -0
  117. data/spec/watirspec/text_fields_spec.rb +35 -0
  118. data/spec/watirspec/ul_spec.rb +76 -0
  119. data/spec/watirspec/uls_spec.rb +33 -0
  120. data/spec/xpath_builder_spec.rb +49 -0
  121. data/support/html5/html5.idl +815 -0
  122. data/support/html5/html5_extras.idl +147 -0
  123. data/support/html5/idl_extractor.rb +73 -0
  124. data/support/html5/watir_visitor.rb +169 -0
  125. metadata +220 -0
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "TableCell" 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 when the table cell exists" do
13
+ browser.cell(:id, 't1_r2_c1').should exist
14
+ browser.cell(:id, /t1_r2_c1/).should exist
15
+ browser.cell(:text, 'Table 1, Row 3, Cell 1').should exist
16
+ browser.cell(:text, /Table 1/).should exist
17
+ browser.cell(:index, 0).should exist
18
+ browser.cell(:xpath, "//td[@id='t1_r2_c1']").should exist
19
+ end
20
+
21
+ it "returns false when the table cell does not exist" do
22
+ browser.cell(:id, 'no_such_id').should_not exist
23
+ browser.cell(:id, /no_such_id/).should_not exist
24
+ browser.cell(:text, 'no_such_text').should_not exist
25
+ browser.cell(:text, /no_such_text/).should_not exist
26
+ browser.cell(:index, 1337).should_not exist
27
+ browser.cell(:xpath, "//td[@id='no_such_id']").should_not exist
28
+ end
29
+
30
+ it "raises TypeError when 'what' argument is invalid" do
31
+ lambda { browser.cell(:id, 3.14).exists? }.should raise_error(TypeError)
32
+ end
33
+
34
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
35
+ lambda { browser.cell(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
36
+ end
37
+ end
38
+
39
+ describe "#click" do
40
+ it "fires the table's onclick event" do
41
+ browser.cell(:id, 't2_r1_c1').click
42
+ messages.should include('td')
43
+ end
44
+ end
45
+
46
+ # Attribute methods
47
+ describe "#text" do
48
+ it "returns the text inside the table cell" do
49
+ browser.cell(:id, 't1_r2_c1').text.should == 'Table 1, Row 2, Cell 1'
50
+ browser.cell(:id, 't2_r1_c1').text.should == 'Table 2, Row 1, Cell 1'
51
+ end
52
+ end
53
+
54
+ describe "#colspan" do
55
+ it "gets the colspan attribute" do
56
+ browser.cell(:id, 'colspan_2').colspan.should == 2
57
+ browser.cell(:id, 'no_colspan').colspan.should == 1
58
+ end
59
+ end
60
+
61
+ describe "#respond_to?" do
62
+ it "returns true for all attribute methods" do
63
+ browser.cell(:index, 0).should respond_to(:text)
64
+ browser.cell(:index, 0).should respond_to(:colspan)
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "TableCells" 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 cells" do
12
+ # browser.table(:id, 'outer').cells.length.should == 6
13
+ # browser.table(:id, 'inner').cells.length.should == 2
14
+ # end
15
+ # end
16
+ #
17
+ # describe "#[]" do
18
+ # it "returns the row at the given index" do
19
+ # browser.table(:id, 'outer').cells[0].text.should == "Table 1, Row 1, Cell 1"
20
+ # browser.table(:id, 'inner').cells[0].text.should == "Table 2, Row 1, Cell 1"
21
+ # browser.table(:id, 'outer').cells[6].text.should == "Table 1, Row 3, Cell 2"
22
+ # end
23
+ # end
24
+
25
+ describe "#each" do
26
+ it "iterates through cells correctly" do
27
+ # All cells on the page
28
+ browser.cells.each_with_index do |c, index|
29
+ c.id.should == browser.cell(:index, index).id
30
+ c.value.should == browser.cell(:index, index).value
31
+ end
32
+ # Cells inside a table
33
+ inner_table = browser.table(:id, 'inner')
34
+ inner_table.cells.each_with_index do |c, index|
35
+ c.id.should == inner_table.cell(:index, index).id
36
+ c.value.should == inner_table.cell(:index, index).value
37
+ end
38
+ # Cells inside a table (should not include cells inside a table inside a table)
39
+ outer_table = browser.table(:id, 'outer')
40
+ outer_table.cells.each_with_index do |c, index|
41
+ c.id.should == outer_table.cell(:index, index).id
42
+ c.value.should == outer_table.cell(:index, index).value
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ bug "WTR-358", :watir do
5
+
6
+ describe "TableFooter" do
7
+ before :each do
8
+ browser.goto(WatirSpec.files + "/tables.html")
9
+ end
10
+
11
+ describe "#exists?" do
12
+ it "returns true if the table tfoot exists (page context)" do
13
+ browser.tfoot(:id, 'tax_totals').should exist
14
+ browser.tfoot(:id, /tax_totals/).should exist
15
+ browser.tfoot(:index, 0).should exist
16
+ browser.tfoot(:xpath, "//tfoot[@id='tax_totals']").should exist
17
+ end
18
+
19
+ it "returns true if the table tfoot exists (table context)" do
20
+ browser.table(:index, 0).tfoot(:id, 'tax_totals').should exist
21
+ browser.table(:index, 0).tfoot(:id, /tax_totals/).should exist
22
+ browser.table(:index, 0).tfoot(:index, 0).should exist
23
+ browser.table(:index, 0).tfoot(:xpath, "//tfoot[@id='tax_totals']").should exist
24
+ end
25
+
26
+ it "returns false if the table tfoot doesn't exist (page context)" do
27
+ browser.tfoot(:id, 'no_such_id').should_not exist
28
+ browser.tfoot(:id, /no_such_id/).should_not exist
29
+ browser.tfoot(:index, 1337).should_not exist
30
+ browser.tfoot(:xpath, "//tfoot[@id='no_such_id']").should_not exist
31
+ end
32
+
33
+ it "returns false if the table tfoot doesn't exist (table context)" do
34
+ browser.table(:index, 0).tfoot(:id, 'no_such_id').should_not exist
35
+ browser.table(:index, 0).tfoot(:id, /no_such_id/).should_not exist
36
+ browser.table(:index, 0).tfoot(:index, 1337).should_not exist
37
+ browser.table(:index, 0).tfoot(:xpath, "//tfoot[@id='no_such_id']").should_not exist
38
+ end
39
+
40
+ it "raises TypeError when 'what' argument is invalid" do
41
+ lambda { browser.tfoot(:id, 3.14).exists? }.should raise_error(TypeError)
42
+ lambda { browser.table(:index, 0).tfoot(:id, 3.14).exists? }.should raise_error(TypeError)
43
+ end
44
+
45
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
46
+ lambda { browser.tfoot(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
47
+ lambda { browser.table(:index, 0).tfoot(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
48
+ end
49
+ end
50
+
51
+ describe "#length" do
52
+ it "returns the correct number of table footers (page context)" do
53
+ browser.tfoot(:id, 'tax_totals').length.should == 1
54
+ end
55
+
56
+ it "returns the correct number of table footers (table context)" do
57
+ browser.table(:index, 0).tfoot(:id, 'tax_totals').length.should == 1
58
+ end
59
+ end
60
+
61
+ describe "#[]" do
62
+ it "returns the row at the given index (page context)" do
63
+ browser.tfoot(:id, 'tax_totals')[0].id.should == 'tfoot_row_1'
64
+ browser.tfoot(:id, 'tax_totals')[0][1].text.should == '24 349'
65
+ browser.tfoot(:id, 'tax_totals')[0][2].text.should == '5 577'
66
+ end
67
+
68
+ it "returns the row at the given index (table context)" do
69
+ browser.table(:index, 0).tfoot(:id, 'tax_totals')[0].id.should == "tfoot_row_1"
70
+ browser.table(:index, 0).tfoot(:id, 'tax_totals')[0][1].text.should == '24 349'
71
+ browser.table(:index, 0).tfoot(:id, 'tax_totals')[0][2].text.should == '5 577'
72
+ end
73
+ end
74
+
75
+ describe "#each" do
76
+ it "iterates through rows correctly" do
77
+ tfoot = browser.table(:index, 0).tfoot(:id, 'tax_totals')
78
+ tfoot.each_with_index do |r, idx|
79
+ r.id.should == "tfoot_row_#{idx + 1}"
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ bug "WTR-358", :watir do
5
+
6
+ describe "TableFooters" do
7
+ before :each do
8
+ browser.goto(WatirSpec.files + "/tables.html")
9
+ end
10
+
11
+ describe "#length" do
12
+ it "returns the correct number of table tfoots (page context)" do
13
+ browser.tfoots.length.should == 1
14
+ end
15
+
16
+ it "returns the correct number of table tfoots (table context)" do
17
+ browser.table(:index, 0).tfoots.length.should == 1
18
+ end
19
+ end
20
+
21
+ describe "#[]" do
22
+ it "returns the row at the given index (page context)" do
23
+ browser.tfoots[0].id.should == "tax_totals"
24
+ end
25
+
26
+ it "returns the row at the given index (table context)" do
27
+ browser.table(:index, 0).tfoots[0].id.should == "tax_totals"
28
+ end
29
+ end
30
+
31
+ describe "#each" do
32
+ it "iterates through table tfoots correctly (page context)" do
33
+ browser.tfoots.each_with_index do |tfoot, index|
34
+ tfoot.id.should == browser.tfoot(:index, index).id
35
+ end
36
+ end
37
+
38
+ it "iterates through table tfoots correctly (table context)" do
39
+ table = browser.table(:index, 0)
40
+ table.tfoots.each_with_index do |tfoot, index|
41
+ tfoot.id.should == table.tfoot(:index, index).id
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ bug "WTR-357", :watir do
5
+ describe "TableHeader" do
6
+
7
+ before :each do
8
+ browser.goto(WatirSpec.files + "/tables.html")
9
+ end
10
+
11
+ describe "#exists?" do
12
+ it "returns true if the table theader exists (page context)" do
13
+ browser.thead(:id, 'tax_headers').should exist
14
+ browser.thead(:id, /tax_headers/).should exist
15
+ browser.thead(:index, 0).should exist
16
+ browser.thead(:xpath, "//thead[@id='tax_headers']").should exist
17
+ end
18
+
19
+ it "returns true if the table theader exists (table context)" do
20
+ browser.table(:index, 0).thead(:id, 'tax_headers').should exist
21
+ browser.table(:index, 0).thead(:id, /tax_headers/).should exist
22
+ browser.table(:index, 0).thead(:index, 0).should exist
23
+ browser.table(:index, 0).thead(:xpath, "//thead[@id='tax_headers']").should exist
24
+ end
25
+
26
+ it "returns false if the table theader doesn't exist (page context)" do
27
+ browser.thead(:id, 'no_such_id').should_not exist
28
+ browser.thead(:id, /no_such_id/).should_not exist
29
+ browser.thead(:index, 1337).should_not exist
30
+ browser.thead(:xpath, "//thead[@id='no_such_id']").should_not exist
31
+ end
32
+
33
+ it "returns false if the table theader doesn't exist (table context)" do
34
+ browser.table(:index, 0).thead(:id, 'no_such_id').should_not exist
35
+ browser.table(:index, 0).thead(:id, /no_such_id/).should_not exist
36
+ browser.table(:index, 0).thead(:index, 1337).should_not exist
37
+ browser.table(:index, 0).thead(:xpath, "//thead[@id='no_such_id']").should_not exist
38
+ end
39
+
40
+ it "raises TypeError when 'what' argument is invalid" do
41
+ lambda { browser.thead(:id, 3.14).exists? }.should raise_error(TypeError)
42
+ lambda { browser.table(:index, 0).thead(:id, 3.14).exists? }.should raise_error(TypeError)
43
+ end
44
+
45
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
46
+ lambda { browser.thead(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
47
+ lambda { browser.table(:index, 0).thead(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
48
+ end
49
+ end
50
+
51
+ describe "#length" do
52
+ it "returns the correct number of table bodies (page context)" do
53
+ browser.thead(:id, 'tax_headers').length.should == 1
54
+ end
55
+
56
+ it "returns the correct number of table bodies (table context)" do
57
+ browser.table(:index, 0).thead(:id, 'tax_headers').length.should == 1
58
+ end
59
+ end
60
+
61
+ describe "#[]" do
62
+ it "returns the row at the given index (page context)" do
63
+ browser.thead(:id, 'tax_headers')[0].id.should == 'thead_row_1'
64
+ browser.thead(:id, 'tax_headers')[0][1].text.should == 'Before income tax'
65
+ browser.thead(:id, 'tax_headers')[0][2].text.should == 'Income tax'
66
+ end
67
+
68
+ it "returns the row at the given index (table context)" do
69
+ browser.table(:index, 0).thead(:id, 'tax_headers')[0].id.should == 'thead_row_1'
70
+ browser.table(:index, 0).thead(:id, 'tax_headers')[0][1].text.should == 'Before income tax'
71
+ browser.table(:index, 0).thead(:id, 'tax_headers')[0][2].text.should == 'Income tax'
72
+ end
73
+ end
74
+
75
+ describe "#each" do
76
+ it "iterates through rows correctly" do
77
+ theader = browser.table(:index, 0).thead(:id, 'tax_headers')
78
+ theader.each_with_index do |r, index|
79
+ r.id.should == browser.row(:index, index).id
80
+ r.value.should == browser.row(:index, index).value
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
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, 0).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[0].id.should == "tax_headers"
23
+ end
24
+
25
+ it "returns the row at the given index (table context)" do
26
+ browser.table(:index, 0).theads[0].id.should == "tax_headers"
27
+ end
28
+ end
29
+
30
+ describe "#each" do
31
+ it "iterates through table theads correctly (page context)" do
32
+ browser.theads.each_with_index do |thead, index|
33
+ thead.id.should == browser.thead(:index, index).id
34
+ end
35
+ end
36
+
37
+ it "iterates through table theads correctly (table context)" do
38
+ table = browser.table(:index, 0)
39
+ table.theads.each_with_index do |thead, index|
40
+ thead.id.should == table.thead(:index, index).id
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
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, 0).should exist
15
+ browser.row(:xpath, "//tr[@id='outer_first']")
16
+ end
17
+
18
+ it "returns false if the table row doesn't exist" do
19
+ browser.row(:id, "no_such_id").should_not exist
20
+ browser.row(:id, /no_such_id/).should_not exist
21
+ browser.row(:index, 1337).should_not exist
22
+ browser.row(:xpath, "//tr[@id='no_such_id']")
23
+ end
24
+
25
+ it "raises TypeError when 'what' argument is invalid" do
26
+ lambda { browser.row(:id, 3.14).exists? }.should raise_error(TypeError)
27
+ end
28
+
29
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
30
+ lambda { browser.row(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
31
+ end
32
+ end
33
+
34
+ describe "#click" do
35
+ it "fires the rows's onclick event" do
36
+ browser.row(:id, 'inner_first').click
37
+ messages.should include('tr')
38
+ end
39
+ end
40
+
41
+ describe "#column_count" do
42
+ it "returns the number of columns (cells) in the row" do
43
+ browser.table(:id, 'outer').rows[0].column_count.should == 2
44
+ browser.table(:id, 'outer')[1].column_count.should == 2
45
+ browser.table(:id, 'colspan')[0].column_count.should == 1
46
+ browser.table(:id, 'colspan').rows[1].column_count.should == 2
47
+ browser.rows[0].column_count.should == 4
48
+ end
49
+ end
50
+
51
+ describe "#[]" do
52
+ it "returns the nth cell of the parent row" do
53
+ browser.table(:id, 'outer').row(:index, 0)[0].text.should == "Table 1, Row 1, Cell 1"
54
+ browser.table(:id, 'outer')[0][0].text.should == "Table 1, Row 1, Cell 1"
55
+ browser.table(:id, 'outer')[2][0].text.should == "Table 1, Row 3, Cell 1"
56
+ end
57
+
58
+ it "raises UnknownCellException if the index is out of bounds" do
59
+ lambda { browser.table(:id, 'outer').row(:index, 0)[1337] }.should raise_error(UnknownCellException)
60
+ lambda { browser.table(:id, 'outer')[0][1337] }.should raise_error(UnknownCellException)
61
+ end
62
+ end
63
+
64
+ bug "WTR-359", :watir do
65
+ describe "#child_cell" do
66
+ it "returns the nth cell of the parent row" do
67
+ browser.table(:id, 'outer').row(:index, 0).child_cell(0).text.should == "Table 1, Row 1, Cell 1"
68
+ browser.table(:id, 'outer')[0].child_cell(0).text.should == "Table 1, Row 1, Cell 1"
69
+ browser.table(:id, 'outer')[2].child_cell(0).text.should == "Table 1, Row 3, Cell 1"
70
+ end
71
+
72
+ it "raises UnknownCellException if the index is out of bounds" do
73
+ lambda { browser.table(:id, 'outer').row(:index, 0).child_cell(1337) }.should raise_error(UnknownCellException)
74
+ lambda { browser.table(:id, 'outer')[0].child_cell(1337) }.should raise_error(UnknownCellException)
75
+ end
76
+ end
77
+
78
+ describe "#each" do
79
+ it "iterates correctly through the cells of the row" do
80
+ browser.table(:id, 'outer')[1].each_with_index do |cell,idx|
81
+ cell.id.should == "t1_r2_c#{idx + 1}"
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ end