watir-webdriver 0.0.7 → 0.0.8

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 (111) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +48 -0
  3. data/Rakefile +23 -8
  4. data/VERSION +1 -1
  5. data/lib/watir-webdriver.rb +7 -5
  6. data/lib/watir-webdriver/browser.rb +9 -2
  7. data/lib/watir-webdriver/browserbot.js +5 -2
  8. data/lib/watir-webdriver/container.rb +6 -9
  9. data/lib/watir-webdriver/{collections/element_collection.rb → element_collection.rb} +5 -0
  10. data/lib/watir-webdriver/elements/button.rb +5 -4
  11. data/lib/watir-webdriver/{element.rb → elements/element.rb} +29 -5
  12. data/lib/watir-webdriver/elements/file_field.rb +21 -4
  13. data/lib/watir-webdriver/elements/frame.rb +1 -1
  14. data/lib/watir-webdriver/elements/generated.rb +750 -750
  15. data/lib/watir-webdriver/elements/image.rb +6 -0
  16. data/lib/watir-webdriver/elements/link.rb +0 -4
  17. data/lib/watir-webdriver/elements/select.rb +22 -24
  18. data/lib/watir-webdriver/elements/table_row.rb +11 -1
  19. data/lib/watir-webdriver/elements/text_field.rb +5 -15
  20. data/lib/watir-webdriver/extensions/wait.rb +107 -0
  21. data/lib/watir-webdriver/html/generator.rb +1 -1
  22. data/lib/watir-webdriver/html/util.rb +1 -10
  23. data/lib/watir-webdriver/html/visitor.rb +2 -14
  24. data/lib/watir-webdriver/locators/button_locator.rb +22 -3
  25. data/lib/watir-webdriver/locators/element_locator.rb +54 -28
  26. data/lib/watir-webdriver/locators/table_row_locator.rb +3 -1
  27. data/lib/watir-webdriver/locators/text_field_locator.rb +7 -3
  28. data/lib/watir-webdriver/window_switching.rb +78 -0
  29. data/spec/browser_spec.rb +43 -0
  30. data/spec/container_spec.rb +43 -0
  31. data/spec/element_locator_spec.rb +305 -0
  32. data/spec/element_spec.rb +34 -5
  33. data/spec/html/closeable.html +13 -0
  34. data/spec/html/data_attributes.html +9 -0
  35. data/spec/html/wait.html +27 -0
  36. data/spec/html/window_switching.html +12 -0
  37. data/spec/input_spec.rb +14 -2
  38. data/spec/locator_spec_helper.rb +37 -0
  39. data/spec/spec_helper.rb +3 -0
  40. data/spec/wait_spec.rb +98 -0
  41. data/spec/watirspec/area_spec.rb +4 -4
  42. data/spec/watirspec/browser_spec.rb +37 -35
  43. data/spec/watirspec/button_spec.rb +22 -17
  44. data/spec/watirspec/buttons_spec.rb +1 -1
  45. data/spec/watirspec/checkbox_spec.rb +4 -0
  46. data/spec/watirspec/checkboxes_spec.rb +1 -1
  47. data/spec/watirspec/collections_spec.rb +4 -2
  48. data/spec/watirspec/dd_spec.rb +4 -0
  49. data/spec/watirspec/dds_spec.rb +1 -1
  50. data/spec/watirspec/del_spec.rb +4 -0
  51. data/spec/watirspec/dels_spec.rb +1 -1
  52. data/spec/watirspec/div_spec.rb +38 -12
  53. data/spec/watirspec/divs_spec.rb +1 -1
  54. data/spec/watirspec/dl_spec.rb +20 -6
  55. data/spec/watirspec/dls_spec.rb +1 -1
  56. data/spec/watirspec/dt_spec.rb +4 -0
  57. data/spec/watirspec/dts_spec.rb +1 -1
  58. data/spec/watirspec/em_spec.rb +4 -0
  59. data/spec/watirspec/ems_spec.rb +1 -1
  60. data/spec/watirspec/filefield_spec.rb +37 -2
  61. data/spec/watirspec/filefields_spec.rb +1 -1
  62. data/spec/watirspec/font_spec.rb +4 -0
  63. data/spec/watirspec/form_spec.rb +4 -0
  64. data/spec/watirspec/forms_spec.rb +6 -4
  65. data/spec/watirspec/frame_spec.rb +6 -0
  66. data/spec/watirspec/hidden_spec.rb +5 -4
  67. data/spec/watirspec/hiddens_spec.rb +1 -1
  68. data/spec/watirspec/hn_spec.rb +4 -0
  69. data/spec/watirspec/image_spec.rb +4 -0
  70. data/spec/watirspec/images_spec.rb +1 -1
  71. data/spec/watirspec/ins_spec.rb +4 -0
  72. data/spec/watirspec/inses_spec.rb +1 -1
  73. data/spec/watirspec/label_spec.rb +4 -0
  74. data/spec/watirspec/labels_spec.rb +2 -2
  75. data/spec/watirspec/li_spec.rb +4 -0
  76. data/spec/watirspec/link_spec.rb +15 -10
  77. data/spec/watirspec/links_spec.rb +6 -0
  78. data/spec/watirspec/lis_spec.rb +1 -1
  79. data/spec/watirspec/map_spec.rb +4 -0
  80. data/spec/watirspec/maps_spec.rb +1 -1
  81. data/spec/watirspec/meta_spec.rb +4 -0
  82. data/spec/watirspec/metas_spec.rb +1 -1
  83. data/spec/watirspec/ol_spec.rb +23 -9
  84. data/spec/watirspec/option_spec.rb +19 -7
  85. data/spec/watirspec/p_spec.rb +4 -0
  86. data/spec/watirspec/pre_spec.rb +4 -0
  87. data/spec/watirspec/pres_spec.rb +1 -1
  88. data/spec/watirspec/ps_spec.rb +1 -1
  89. data/spec/watirspec/radio_spec.rb +22 -13
  90. data/spec/watirspec/radios_spec.rb +6 -0
  91. data/spec/watirspec/select_list_spec.rb +29 -17
  92. data/spec/watirspec/select_lists_spec.rb +6 -0
  93. data/spec/watirspec/span_spec.rb +10 -2
  94. data/spec/watirspec/spans_spec.rb +1 -1
  95. data/spec/watirspec/strong_spec.rb +14 -4
  96. data/spec/watirspec/table_body_spec.rb +4 -0
  97. data/spec/watirspec/table_cell_spec.rb +9 -3
  98. data/spec/watirspec/table_cells_spec.rb +0 -1
  99. data/spec/watirspec/table_footer_spec.rb +4 -0
  100. data/spec/watirspec/table_header_spec.rb +4 -0
  101. data/spec/watirspec/table_row_spec.rb +15 -7
  102. data/spec/watirspec/table_rows_spec.rb +2 -2
  103. data/spec/watirspec/table_spec.rb +13 -7
  104. data/spec/watirspec/tables_spec.rb +1 -1
  105. data/spec/watirspec/text_field_spec.rb +21 -12
  106. data/spec/watirspec/text_fields_spec.rb +6 -0
  107. data/spec/watirspec/ul_spec.rb +4 -0
  108. data/spec/window_switching_spec.rb +116 -0
  109. data/watir-webdriver.gemspec +38 -16
  110. metadata +51 -27
  111. data/lib/watir-webdriver/collections/table_row_collection.rb +0 -11
@@ -24,11 +24,17 @@ describe "SelectLists" do
24
24
 
25
25
  describe "#each" do
26
26
  it "iterates through the select lists correctly" do
27
+ count = 0
28
+
27
29
  browser.select_lists.each_with_index do |l, index|
28
30
  browser.select_list(:index, index).name.should == l.name
29
31
  browser.select_list(:index, index).id.should == l.id
30
32
  browser.select_list(:index, index).value.should == l.value
33
+
34
+ count += 1
31
35
  end
36
+
37
+ count.should > 0
32
38
  end
33
39
  end
34
40
 
@@ -12,14 +12,22 @@ describe "Span" do
12
12
  it "returns true if the 'span' exists" do
13
13
  browser.span(:id, "lead").should exist
14
14
  browser.span(:id, /lead/).should exist
15
- browser.span(:text, "Dubito, ergo cogito, ergo sum.").should exist
16
- browser.span(:text, /Dubito, ergo cogito, ergo sum/).should exist
15
+
16
+ bug "http://code.google.com/p/selenium/issues/detail?id=748", :webdriver do
17
+ browser.span(:text, "Dubito, ergo cogito, ergo sum.").should exist
18
+ browser.span(:text, /Dubito, ergo cogito, ergo sum/).should exist
19
+ end
20
+
17
21
  browser.span(:class, "lead").should exist
18
22
  browser.span(:class, /lead/).should exist
19
23
  browser.span(:index, 0).should exist
20
24
  browser.span(:xpath, "//span[@id='lead']").should exist
21
25
  end
22
26
 
27
+ it "returns the first span if given no args" do
28
+ browser.span.should exist
29
+ end
30
+
23
31
  it "returns false if the element doesn't exist" do
24
32
  browser.span(:id, "no_such_id").should_not exist
25
33
  browser.span(:id, /no_such_id/).should_not exist
@@ -27,7 +27,7 @@ describe "Spans" do
27
27
  s.id.should == browser.span(:index, index).id
28
28
  s.value.should == browser.span(:index, index).value
29
29
 
30
- count += 1
30
+ count += 1
31
31
  end
32
32
 
33
33
  count.should > 0
@@ -12,14 +12,22 @@ describe "Strong" do
12
12
  it "returns true if the element exists" do
13
13
  browser.strong(:id, "descartes").should exist
14
14
  browser.strong(:id, /descartes/).should exist
15
- browser.strong(:text, "Dubito, ergo cogito, ergo sum.").should exist
16
- browser.strong(:text, /Dubito, ergo cogito, ergo sum/).should exist
15
+
16
+ bug "http://code.google.com/p/selenium/issues/detail?id=748", :webdriver do
17
+ browser.strong(:text, "Dubito, ergo cogito, ergo sum.").should exist
18
+ browser.strong(:text, /Dubito, ergo cogito, ergo sum/).should exist
19
+ end
20
+
17
21
  browser.strong(:class, "descartes").should exist
18
22
  browser.strong(:class, /descartes/).should exist
19
23
  browser.strong(:index, 0).should exist
20
24
  browser.strong(:xpath, "//strong[@id='descartes']").should exist
21
25
  end
22
26
 
27
+ it "returns the first strong if given no args" do
28
+ browser.strong.should exist
29
+ end
30
+
23
31
  it "returns false if the element doesn't exist" do
24
32
  browser.strong(:id, "no_such_id").should_not exist
25
33
  browser.strong(:id, /no_such_id/).should_not exist
@@ -67,8 +75,10 @@ describe "Strong" do
67
75
  end
68
76
 
69
77
  describe "#text" do
70
- it "returns the text of the element" do
71
- browser.strong(:index, 0).text.should == "Dubito, ergo cogito, ergo sum."
78
+ bug "http://code.google.com/p/selenium/issues/detail?id=748", :webdriver do
79
+ it "returns the text of the element" do
80
+ browser.strong(:index, 0).text.should == "Dubito, ergo cogito, ergo sum."
81
+ end
72
82
  end
73
83
 
74
84
  it "raises UnknownObjectException if the element doesn't exist" do
@@ -22,6 +22,10 @@ describe "TableBody" do
22
22
  browser.table(:index, 0).tbody(:xpath, "//tbody[@id='first']").should exist
23
23
  end
24
24
 
25
+ it "returns the first table body if given no args" do
26
+ browser.table.tbody.should exist
27
+ end
28
+
25
29
  it "returns false if the table body doesn't exist (page context)" do
26
30
  browser.tbody(:id, 'no_such_id').should_not exist
27
31
  browser.tbody(:id, /no_such_id/).should_not exist
@@ -18,6 +18,10 @@ describe "TableCell" do
18
18
  browser.cell(:xpath, "//td[@id='t1_r2_c1']").should exist
19
19
  end
20
20
 
21
+ it "returns the first cell if given no args" do
22
+ browser.cell.should exist
23
+ end
24
+
21
25
  it "returns false when the table cell does not exist" do
22
26
  browser.cell(:id, 'no_such_id').should_not exist
23
27
  browser.cell(:id, /no_such_id/).should_not exist
@@ -52,9 +56,11 @@ describe "TableCell" do
52
56
  end
53
57
 
54
58
  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
59
+ bug "http://github.com/jarib/watir-webdriver/issues#issue/25", :webdriver do
60
+ it "gets the colspan attribute" do
61
+ browser.cell(:id, 'colspan_2').colspan.should == 2
62
+ browser.cell(:id, 'no_colspan').colspan.should == 1
63
+ end
58
64
  end
59
65
  end
60
66
 
@@ -49,7 +49,6 @@ describe "TableCells" do
49
49
 
50
50
  count.should > 0
51
51
 
52
-
53
52
  # Cells inside a table (should not include cells inside a table inside a table)
54
53
  outer_table = browser.table(:id, 'outer')
55
54
  count = 0
@@ -21,6 +21,10 @@ describe "TableFooter" do
21
21
  browser.table(:index, 0).tfoot(:xpath, "//tfoot[@id='tax_totals']").should exist
22
22
  end
23
23
 
24
+ it "returns the first tfoot if given no args" do
25
+ browser.tfoot.should exist
26
+ end
27
+
24
28
  it "returns false if the table tfoot doesn't exist (page context)" do
25
29
  browser.tfoot(:id, 'no_such_id').should_not exist
26
30
  browser.tfoot(:id, /no_such_id/).should_not exist
@@ -15,6 +15,10 @@ describe "TableHeader" do
15
15
  browser.thead(:xpath, "//thead[@id='tax_headers']").should exist
16
16
  end
17
17
 
18
+ it "returns the first thead if given no args" do
19
+ browser.thead.should exist
20
+ end
21
+
18
22
  it "returns true if the table theader exists (table context)" do
19
23
  browser.table(:index, 0).thead(:id, 'tax_headers').should exist
20
24
  browser.table(:index, 0).thead(:id, /tax_headers/).should exist
@@ -15,6 +15,10 @@ describe "TableRow" do
15
15
  browser.row(:xpath, "//tr[@id='outer_first']")
16
16
  end
17
17
 
18
+ it "returns the first row if given no args" do
19
+ browser.row.should exist
20
+ end
21
+
18
22
  it "returns false if the table row doesn't exist" do
19
23
  browser.row(:id, "no_such_id").should_not exist
20
24
  browser.row(:id, /no_such_id/).should_not exist
@@ -32,9 +36,11 @@ describe "TableRow" do
32
36
  end
33
37
 
34
38
  describe "#click" do
35
- it "fires the rows's onclick event" do
36
- browser.row(:id, 'inner_first').click
37
- messages.should include('tr')
39
+ bug "http://github.com/jarib/watir-webdriver/issues/issue/32", [:webdriver, :ie] do
40
+ it "fires the rows's onclick event" do
41
+ browser.row(:id, 'inner_first').click
42
+ messages.should include('tr')
43
+ end
38
44
  end
39
45
  end
40
46
 
@@ -57,9 +63,11 @@ describe "TableRow" do
57
63
  browser.table(:id, 'outer')[2][0].text.should == "Table 1, Row 3, Cell 1"
58
64
  end
59
65
 
60
- it "raises UnknownCellException if the index is out of bounds" do
61
- lambda { browser.table(:id, 'outer').row(:index, 0)[1337] }.should raise_error(UnknownCellException)
62
- lambda { browser.table(:id, 'outer')[0][1337] }.should raise_error(UnknownCellException)
66
+ bug "http://github.com/jarib/watir-webdriver/issues/issue/26", :webdriver do
67
+ it "raises UnknownCellException if the index is out of bounds" do
68
+ lambda { browser.table(:id, 'outer').row(:index, 0)[1337] }.should raise_error(UnknownCellException)
69
+ lambda { browser.table(:id, 'outer')[0][1337] }.should raise_error(UnknownCellException)
70
+ end
63
71
  end
64
72
  end
65
73
 
@@ -81,7 +89,7 @@ describe "TableRow" do
81
89
  bug "http://github.com/jarib/watir-webdriver/issues/#issue/2", :webdriver do
82
90
  describe "#each" do
83
91
  it "iterates correctly through the cells of the row" do
84
- browser.table(:id, 'outer')[1].each_with_index do |cell,idx|
92
+ browser.table(:id, 'outer')[1].each_with_index do |cell, idx|
85
93
  cell.id.should == "t1_r2_c#{idx + 1}"
86
94
  end
87
95
  end
@@ -38,7 +38,7 @@ describe "TableRows" do
38
38
  r.id.should == inner_table.row(:index, index).id
39
39
  r.value.should == inner_table.row(:index, index).value
40
40
 
41
- count += 1
41
+ count += 1
42
42
  end
43
43
 
44
44
  count.should > 0
@@ -50,7 +50,7 @@ describe "TableRows" do
50
50
  r.id.should == outer_table.row(:index, index).id
51
51
  r.value.should == outer_table.row(:index, index).value
52
52
 
53
- count += 1
53
+ count += 1
54
54
  end
55
55
 
56
56
  count.should > 0
@@ -16,6 +16,10 @@ describe "Table" do
16
16
  browser.table(:xpath, "//table[@id='axis_example']").should exist
17
17
  end
18
18
 
19
+ it "returns the first table if given no args" do
20
+ browser.table.should exist
21
+ end
22
+
19
23
  it "returns false if the table does not exist" do
20
24
  browser.table(:id, 'no_such_id').should_not exist
21
25
  browser.table(:id, /no_such_id/).should_not exist
@@ -23,11 +27,9 @@ describe "Table" do
23
27
  browser.table(:xpath, "//table[@id='no_such_id']").should_not exist
24
28
  end
25
29
 
26
- bug "http://github.com/jarib/watir-webdriver/issues#issue/6", :webdriver do
27
- it "checks the tag name when locating by xpath" do
28
- browser.table(:xpath, "//table//td").should_not exist
29
- browser.table(:xpath, "//table").should exist
30
- end
30
+ it "checks the tag name when locating by xpath" do
31
+ browser.table(:xpath, "//table//td").should_not exist
32
+ browser.table(:xpath, "//table").should exist
31
33
  end
32
34
 
33
35
  it "raises TypeError when 'what' argument is invalid" do
@@ -117,8 +119,12 @@ describe "Table" do
117
119
  browser.table(:id, 'inner')[0].id.should == "inner_first"
118
120
  browser.table(:id, 'outer')[2].id.should == "outer_last"
119
121
  end
120
- it "raises UnknownRowException if the index is out of bounds" do
121
- lambda { browser.table(:id, 'outer')[1337] }.should raise_error(UnknownRowException)
122
+
123
+
124
+ bug "http://github.com/jarib/watir-webdriver/issues/issue/26", :webdriver do
125
+ it "raises UnknownRowException if the index is out of bounds" do
126
+ lambda { browser.table(:id, 'outer')[1337] }.should raise_error(UnknownRowException)
127
+ end
122
128
  end
123
129
  end
124
130
 
@@ -29,7 +29,7 @@ describe "Tables" do
29
29
  t.id.should == browser.table(:index, index).id
30
30
  t.value.should == browser.table(:index, index).value
31
31
 
32
- count += 1
32
+ count += 1
33
33
  end
34
34
 
35
35
  count.should > 0
@@ -16,6 +16,7 @@ describe "TextField" do
16
16
  browser.text_field(:name, /new_user_email/).should exist
17
17
  browser.text_field(:value, 'Developer').should exist
18
18
  browser.text_field(:value, /Developer/).should exist
19
+ browser.text_field(:value, "Default comment.").should exist # textarea
19
20
  browser.text_field(:text, 'Developer').should exist
20
21
  browser.text_field(:text, /Developer/).should exist
21
22
  browser.text_field(:class, 'name').should exist
@@ -24,7 +25,11 @@ describe "TextField" do
24
25
  browser.text_field(:xpath, "//input[@id='new_user_email']").should exist
25
26
  browser.text_field(:label, "First name").should exist
26
27
  browser.text_field(:label, /(Last|First) name/).should exist
27
- end
28
+ end
29
+
30
+ it "returns the first text field if given no args" do
31
+ browser.text_field.should exist
32
+ end
28
33
 
29
34
  it "returns true if the element exists (no type attribute)" do
30
35
  browser.text_field(:id, 'new_user_first_name').should exist
@@ -179,16 +184,20 @@ describe "TextField" do
179
184
 
180
185
  # Manipulation methods
181
186
  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"
187
+ bug "http://code.google.com/p/selenium/issues/detail?id=698", [:webdriver, :ie] do
188
+ it "appends the text to the text field" do
189
+ browser.text_field(:name, "new_user_occupation").append(" Append This")
190
+ browser.text_field(:name, "new_user_occupation").value.should == "Developer Append This"
191
+ end
185
192
  end
186
193
 
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"
194
+ bug "http://code.google.com/p/selenium/issues/detail?id=698", [:webdriver, :ie] do
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
190
199
  end
191
-
200
+
192
201
  it "raises ObjectReadOnlyException if the object is read only" do
193
202
  lambda { browser.text_field(:id, "new_user_code").append("Append This") }.should raise_error(ObjectReadOnlyException)
194
203
  end
@@ -253,13 +262,13 @@ describe "TextField" do
253
262
  end
254
263
 
255
264
  it "sets the value of a password field" do
256
- browser.text_field(:name , 'new_user_password').set('secret')
257
- browser.text_field(:name , 'new_user_password').value.should == 'secret'
265
+ browser.text_field(:name, 'new_user_password').set('secret')
266
+ browser.text_field(:name, 'new_user_password').value.should == 'secret'
258
267
  end
259
268
 
260
269
  it "sets the value when accessed through the enclosing Form" do
261
- browser.form(:id, 'new_user').text_field(:name , 'new_user_password').set('secret')
262
- browser.form(:id, 'new_user').text_field(:name , 'new_user_password').value.should == 'secret'
270
+ browser.form(:id, 'new_user').text_field(:name, 'new_user_password').set('secret')
271
+ browser.form(:id, 'new_user').text_field(:name, 'new_user_password').value.should == 'secret'
263
272
  end
264
273
 
265
274
  it "is able to set multi-byte characters" do
@@ -23,11 +23,17 @@ describe "TextFields" do
23
23
 
24
24
  describe "#each" do
25
25
  it "iterates through text fields correctly" do
26
+ count = 0
27
+
26
28
  browser.text_fields.each_with_index do |r, index|
27
29
  r.name.should == browser.text_field(:index, index).name
28
30
  r.id.should == browser.text_field(:index, index).id
29
31
  r.value.should == browser.text_field(:index, index).value
32
+
33
+ count += 1
30
34
  end
35
+
36
+ count.should > 0
31
37
  end
32
38
  end
33
39
 
@@ -16,6 +16,10 @@ describe "Ul" do
16
16
  browser.ul(:xpath, "//ul[@id='navbar']").should exist
17
17
  end
18
18
 
19
+ it "returns the first ul if given no args" do
20
+ browser.ul.should exist
21
+ end
22
+
19
23
  it "returns false if the 'ul' doesn't exist" do
20
24
  browser.ul(:id, "no_such_id").should_not exist
21
25
  browser.ul(:id, /no_such_id/).should_not exist
@@ -0,0 +1,116 @@
1
+ require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
2
+
3
+
4
+ describe Watir::Browser do
5
+
6
+ before do
7
+ url = "file://" + File.expand_path("html/window_switching.html", File.dirname(__FILE__))
8
+ browser.goto url
9
+ browser.a(:id => "open").click
10
+ end
11
+
12
+ after do
13
+ win = browser.window(:title => "closeable window")
14
+ win && win.close
15
+ end
16
+
17
+ describe "#windows" do
18
+ it "returns an array of window handles" do
19
+ wins = browser.windows
20
+ wins.should_not be_empty
21
+ wins.each { |win| win.should be_kind_of(Watir::Window) }
22
+ end
23
+
24
+ it "only returns windows matching the given selector" do
25
+ browser.windows(:title => "closeable window").size.should == 1
26
+ end
27
+ end
28
+
29
+ describe "#window" do
30
+ it "finds window by :url" do
31
+ w = browser.window(:url => /closeable\.html/)
32
+ w.should be_kind_of(Watir::Window)
33
+ end
34
+
35
+ it "finds window by :title" do
36
+ w = browser.window(:title => "closeable window")
37
+ w.should be_kind_of(Watir::Window)
38
+ end
39
+
40
+ it "it executes the given block in the window" do
41
+ browser.window(:title => "closeable window") do
42
+ link = browser.a(:id => "close")
43
+ link.should exist
44
+ link.click
45
+ end
46
+
47
+ browser.windows.size.should == 1
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ describe Watir::Window do
54
+ before do
55
+ url = "file://" + File.expand_path("html/window_switching.html", File.dirname(__FILE__))
56
+ browser.goto url
57
+ browser.a(:id => "open").click
58
+ end
59
+
60
+ after do
61
+ browser.window(:title => "closeable window").close
62
+ end
63
+
64
+ describe "#close" do
65
+ it "closes the window" do
66
+ pending
67
+ end
68
+ end
69
+
70
+ describe "#use" do
71
+ it "switches to the window" do
72
+ pending
73
+ end
74
+ end
75
+
76
+ describe "#current?" do
77
+ it "returns true if it is the current window" do
78
+ browser.window(:title => browser.title).should be_current
79
+ end
80
+
81
+ it "returns false if it is not the current window" do
82
+ browser.window(:title => "closeable window").should_not be_current
83
+ end
84
+ end
85
+
86
+ describe "#title" do
87
+ it "returns the title of the window" do
88
+ titles = browser.windows.map { |e| e.title }
89
+ titles.size.should == 2
90
+
91
+ ["window switching", "closeable window"].each do |title|
92
+ titles.should include(title)
93
+ end
94
+ end
95
+
96
+ it "does not change the current window" do
97
+ browser.title.should == "window switching"
98
+ browser.windows.find { |w| w.title == "closeable window" }.should_not be_nil
99
+ browser.title.should == "window switching"
100
+ end
101
+ end
102
+
103
+ describe "#url" do
104
+ it "returns the url of the window" do
105
+ browser.windows.size.should == 2
106
+ browser.windows.select { |w| w.url =~ /window_switching\.html/ }.size.should == 1
107
+ browser.windows.select { |w| w.url =~ /closeable\.html$/ }.size.should == 1
108
+ end
109
+
110
+ it "does not change the current window" do
111
+ browser.url.should =~ /window_switching\.html/
112
+ browser.windows.find { |w| w.url =~ /closeable\.html/ }.should_not be_nil
113
+ browser.url.should =~ /window_switching/
114
+ end
115
+ end
116
+ end