watir-webdriver 0.0.1.dev

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