watir 7.2.0 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/chrome.yml +1 -1
  3. data/.github/workflows/edge.yml +1 -1
  4. data/.github/workflows/firefox.yml +1 -1
  5. data/.github/workflows/ie.yml +1 -1
  6. data/.github/workflows/safari.yml +1 -1
  7. data/.github/workflows/unit.yml +1 -1
  8. data/.rubocop.yml +25 -12
  9. data/.rubocop_todo.yml +8 -1
  10. data/CHANGES.md +6 -1
  11. data/LICENSE +2 -2
  12. data/lib/watir/capabilities.rb +1 -1
  13. data/lib/watir/locators/anchor/selector_builder.rb +3 -0
  14. data/lib/watir/locators/element/matcher.rb +2 -1
  15. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
  16. data/lib/watir/locators/text_field/matcher.rb +0 -4
  17. data/lib/watir/version.rb +1 -1
  18. data/spec/locator_spec_helper.rb +0 -8
  19. data/spec/unit/capabilities_spec.rb +553 -561
  20. data/spec/unit/element_locator_spec.rb +89 -78
  21. data/spec/unit/match_elements/button_spec.rb +69 -62
  22. data/spec/unit/match_elements/element_spec.rb +303 -309
  23. data/spec/unit/match_elements/text_field_spec.rb +76 -73
  24. data/spec/unit/selector_builder/anchor_spec.rb +39 -33
  25. data/spec/unit/selector_builder/button_spec.rb +209 -202
  26. data/spec/unit/selector_builder/cell_spec.rb +48 -42
  27. data/spec/unit/selector_builder/element_spec.rb +634 -627
  28. data/spec/unit/selector_builder/row_spec.rb +119 -113
  29. data/spec/unit/selector_builder/text_field_spec.rb +195 -188
  30. data/spec/unit/selector_builder/textarea_spec.rb +22 -14
  31. data/spec/unit/wait_spec.rb +85 -81
  32. data/spec/watirspec/adjacent_spec.rb +249 -247
  33. data/spec/watirspec/after_hooks_spec.rb +161 -159
  34. data/spec/watirspec/alert_spec.rb +61 -58
  35. data/spec/watirspec/browser_spec.rb +409 -409
  36. data/spec/watirspec/capabilities_spec.rb +89 -99
  37. data/spec/watirspec/cookies_spec.rb +120 -118
  38. data/spec/watirspec/drag_and_drop_spec.rb +26 -24
  39. data/spec/watirspec/element_hidden_spec.rb +66 -60
  40. data/spec/watirspec/elements/area_spec.rb +49 -47
  41. data/spec/watirspec/elements/areas_spec.rb +27 -25
  42. data/spec/watirspec/elements/button_spec.rb +253 -251
  43. data/spec/watirspec/elements/buttons_spec.rb +36 -34
  44. data/spec/watirspec/elements/checkbox_spec.rb +48 -36
  45. data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
  46. data/spec/watirspec/elements/collections_spec.rb +126 -119
  47. data/spec/watirspec/elements/date_field_spec.rb +185 -183
  48. data/spec/watirspec/elements/date_fields_spec.rb +29 -27
  49. data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
  50. data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
  51. data/spec/watirspec/elements/dd_spec.rb +87 -85
  52. data/spec/watirspec/elements/dds_spec.rb +27 -25
  53. data/spec/watirspec/elements/del_spec.rb +106 -104
  54. data/spec/watirspec/elements/dels_spec.rb +26 -24
  55. data/spec/watirspec/elements/div_spec.rb +225 -221
  56. data/spec/watirspec/elements/divs_spec.rb +37 -35
  57. data/spec/watirspec/elements/dl_spec.rb +110 -108
  58. data/spec/watirspec/elements/dls_spec.rb +28 -26
  59. data/spec/watirspec/elements/dt_spec.rb +86 -84
  60. data/spec/watirspec/elements/dts_spec.rb +27 -25
  61. data/spec/watirspec/elements/element_spec.rb +794 -775
  62. data/spec/watirspec/elements/elements_spec.rb +40 -38
  63. data/spec/watirspec/elements/em_spec.rb +62 -60
  64. data/spec/watirspec/elements/ems_spec.rb +28 -26
  65. data/spec/watirspec/elements/filefield_spec.rb +116 -114
  66. data/spec/watirspec/elements/filefields_spec.rb +28 -26
  67. data/spec/watirspec/elements/font_spec.rb +20 -18
  68. data/spec/watirspec/elements/form_spec.rb +51 -49
  69. data/spec/watirspec/elements/forms_spec.rb +29 -27
  70. data/spec/watirspec/elements/frame_spec.rb +89 -87
  71. data/spec/watirspec/elements/frames_spec.rb +27 -25
  72. data/spec/watirspec/elements/hidden_spec.rb +81 -79
  73. data/spec/watirspec/elements/hiddens_spec.rb +28 -26
  74. data/spec/watirspec/elements/hn_spec.rb +59 -57
  75. data/spec/watirspec/elements/hns_spec.rb +26 -24
  76. data/spec/watirspec/elements/iframe_spec.rb +195 -191
  77. data/spec/watirspec/elements/iframes_spec.rb +31 -29
  78. data/spec/watirspec/elements/image_spec.rb +148 -146
  79. data/spec/watirspec/elements/images_spec.rb +26 -24
  80. data/spec/watirspec/elements/input_spec.rb +9 -7
  81. data/spec/watirspec/elements/ins_spec.rb +106 -104
  82. data/spec/watirspec/elements/inses_spec.rb +26 -24
  83. data/spec/watirspec/elements/label_spec.rb +56 -54
  84. data/spec/watirspec/elements/labels_spec.rb +26 -24
  85. data/spec/watirspec/elements/li_spec.rb +76 -74
  86. data/spec/watirspec/elements/link_spec.rb +173 -177
  87. data/spec/watirspec/elements/links_spec.rb +45 -43
  88. data/spec/watirspec/elements/lis_spec.rb +27 -25
  89. data/spec/watirspec/elements/list_spec.rb +44 -42
  90. data/spec/watirspec/elements/map_spec.rb +57 -55
  91. data/spec/watirspec/elements/maps_spec.rb +27 -25
  92. data/spec/watirspec/elements/meta_spec.rb +16 -14
  93. data/spec/watirspec/elements/metas_spec.rb +26 -24
  94. data/spec/watirspec/elements/ol_spec.rb +56 -65
  95. data/spec/watirspec/elements/ols_spec.rb +26 -24
  96. data/spec/watirspec/elements/option_spec.rb +91 -89
  97. data/spec/watirspec/elements/p_spec.rb +81 -79
  98. data/spec/watirspec/elements/pre_spec.rb +77 -75
  99. data/spec/watirspec/elements/pres_spec.rb +26 -24
  100. data/spec/watirspec/elements/ps_spec.rb +26 -24
  101. data/spec/watirspec/elements/radio_spec.rb +251 -249
  102. data/spec/watirspec/elements/radios_spec.rb +28 -26
  103. data/spec/watirspec/elements/select_list_spec.rb +537 -526
  104. data/spec/watirspec/elements/select_lists_spec.rb +32 -30
  105. data/spec/watirspec/elements/span_spec.rb +112 -110
  106. data/spec/watirspec/elements/spans_spec.rb +26 -24
  107. data/spec/watirspec/elements/strong_spec.rb +58 -58
  108. data/spec/watirspec/elements/strongs_spec.rb +28 -26
  109. data/spec/watirspec/elements/table_spec.rb +192 -139
  110. data/spec/watirspec/elements/tables_spec.rb +28 -26
  111. data/spec/watirspec/elements/tbody_spec.rb +74 -72
  112. data/spec/watirspec/elements/tbodys_spec.rb +40 -38
  113. data/spec/watirspec/elements/td_spec.rb +66 -64
  114. data/spec/watirspec/elements/tds_spec.rb +41 -39
  115. data/spec/watirspec/elements/text_field_spec.rb +206 -204
  116. data/spec/watirspec/elements/text_fields_spec.rb +30 -28
  117. data/spec/watirspec/elements/textarea_spec.rb +20 -18
  118. data/spec/watirspec/elements/textareas_spec.rb +18 -16
  119. data/spec/watirspec/elements/tfoot_spec.rb +65 -63
  120. data/spec/watirspec/elements/tfoots_spec.rb +42 -40
  121. data/spec/watirspec/elements/thead_spec.rb +65 -63
  122. data/spec/watirspec/elements/theads_spec.rb +42 -40
  123. data/spec/watirspec/elements/tr_spec.rb +48 -46
  124. data/spec/watirspec/elements/trs_spec.rb +42 -40
  125. data/spec/watirspec/elements/ul_spec.rb +56 -54
  126. data/spec/watirspec/elements/uls_spec.rb +26 -24
  127. data/spec/watirspec/radio_set_spec.rb +269 -267
  128. data/spec/watirspec/screenshot_spec.rb +20 -18
  129. data/spec/watirspec/scroll_spec.rb +152 -148
  130. data/spec/watirspec/shadow_root_spec.rb +86 -83
  131. data/spec/watirspec/user_editable_spec.rb +200 -198
  132. data/spec/watirspec/wait_spec.rb +289 -295
  133. data/spec/watirspec/window_switching_spec.rb +422 -434
  134. data/spec/watirspec_helper.rb +1 -23
  135. data/watir.gemspec +5 -4
  136. metadata +44 -33
  137. data/spec/watirspec/attributes_spec.rb +0 -18
  138. data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
  139. data/spec/watirspec/special_chars_spec.rb +0 -23
@@ -2,166 +2,168 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Browser#cookies' do
6
- after { browser.cookies.clear }
5
+ module Watir
6
+ describe Cookies do
7
+ after { browser.cookies.clear }
7
8
 
8
- it 'gets an empty list of cookies' do
9
- browser.goto WatirSpec.url_for 'index.html'
10
- expect(browser.cookies.to_a).to eq []
11
- end
12
-
13
- it 'gets any cookies set' do
14
- browser.goto set_cookie_url
15
-
16
- verify_cookies_count 1
17
-
18
- cookie = browser.cookies.to_a.first
19
- expect(cookie[:name]).to eq 'monster'
20
- expect(cookie[:value]).to eq '1'
21
- end
9
+ it 'gets an empty list of cookies' do
10
+ browser.goto WatirSpec.url_for 'index.html'
11
+ expect(browser.cookies.to_a).to eq []
12
+ end
22
13
 
23
- describe '#[]' do
24
- before do
14
+ it 'gets any cookies set' do
25
15
  browser.goto set_cookie_url
16
+
26
17
  verify_cookies_count 1
27
- end
28
18
 
29
- it 'returns cookie by symbol name' do
30
- cookie = browser.cookies[:monster]
31
- expect(cookie[:name]).to eq('monster')
32
- expect(cookie[:value]).to eq('1')
19
+ cookie = browser.cookies.to_a.first
20
+ expect(cookie[:name]).to eq 'monster'
21
+ expect(cookie[:value]).to eq '1'
33
22
  end
34
23
 
35
- it 'returns cookie by string name' do
36
- cookie = browser.cookies['monster']
37
- expect(cookie[:name]).to eq('monster')
38
- expect(cookie[:value]).to eq('1')
39
- end
24
+ describe '#[]' do
25
+ before do
26
+ browser.goto set_cookie_url
27
+ verify_cookies_count 1
28
+ end
40
29
 
41
- it 'returns nil if there is no cookie with such name' do
42
- expect(browser.cookies[:non_monster]).to eq(nil)
43
- end
44
- end
30
+ it 'returns cookie by symbol name' do
31
+ cookie = browser.cookies[:monster]
32
+ expect(cookie[:name]).to eq('monster')
33
+ expect(cookie[:value]).to eq('1')
34
+ end
45
35
 
46
- it 'adds a cookie without options' do
47
- browser.goto WatirSpec.url_for 'index.html'
48
- verify_cookies_count 0
36
+ it 'returns cookie by string name' do
37
+ cookie = browser.cookies['monster']
38
+ expect(cookie[:name]).to eq('monster')
39
+ expect(cookie[:value]).to eq('1')
40
+ end
49
41
 
50
- browser.cookies.add 'foo', 'bar'
51
- verify_cookies_count 1
52
- end
42
+ it 'returns nil if there is no cookie with such name' do
43
+ expect(browser.cookies[:non_monster]).to be_nil
44
+ end
45
+ end
53
46
 
54
- it 'adds a cookie with a string expires value' do
55
- browser.goto WatirSpec.url_for 'index.html'
47
+ it 'adds a cookie without options' do
48
+ browser.goto WatirSpec.url_for 'index.html'
49
+ verify_cookies_count 0
56
50
 
57
- expire_time = Time.now + 10_000
51
+ browser.cookies.add 'foo', 'bar'
52
+ verify_cookies_count 1
53
+ end
58
54
 
59
- browser.cookies.add 'foo', 'bar', expires: expire_time.to_s
55
+ it 'adds a cookie with a string expires value' do
56
+ browser.goto WatirSpec.url_for 'index.html'
60
57
 
61
- cookie = browser.cookies[:foo]
62
- expect(cookie[:expires]).to be_kind_of(Time)
63
- end
58
+ expire_time = ::Time.now + 10_000
64
59
 
65
- it 'adds a cookie with path',
66
- except: {browser: :ie, reason: 'path contains two slashes'} do
67
- browser.goto WatirSpec.url_for 'index.html'
60
+ browser.cookies.add 'foo', 'bar', expires: expire_time.to_s
68
61
 
69
- options = {path: '/set_cookie'}
70
- browser.cookies.add 'path', 'b', options
62
+ cookie = browser.cookies[:foo]
63
+ expect(cookie[:expires]).to be_a(::Time)
64
+ end
71
65
 
72
- expect(browser.cookies.to_a).to be_empty
66
+ it 'adds a cookie with path',
67
+ except: {browser: :ie, reason: 'path contains two slashes'} do
68
+ browser.goto WatirSpec.url_for 'index.html'
73
69
 
74
- browser.goto set_cookie_url
75
- cookie = browser.cookies.to_a.find { |e| e[:name] == 'path' }
70
+ options = {path: '/set_cookie'}
71
+ browser.cookies.add 'path', 'b', options
76
72
 
77
- expect(cookie[:name]).to eq 'path'
78
- expect(cookie[:value]).to eq 'b'
79
- expect(cookie[:path]).to eq '/set_cookie'
80
- end
73
+ expect(browser.cookies.to_a).to be_empty
81
74
 
82
- it 'adds a cookie with expiration' do
83
- browser.goto WatirSpec.url_for 'index.html'
75
+ browser.goto set_cookie_url
76
+ cookie = browser.cookies.to_a.find { |e| e[:name] == 'path' }
84
77
 
85
- expires = Time.now + 10_000
86
- options = {expires: expires}
78
+ expect(cookie[:name]).to eq 'path'
79
+ expect(cookie[:value]).to eq 'b'
80
+ expect(cookie[:path]).to eq '/set_cookie'
81
+ end
87
82
 
88
- browser.cookies.add 'expiration', 'b', options
89
- cookie = browser.cookies.to_a.first
83
+ it 'adds a cookie with expiration' do
84
+ browser.goto WatirSpec.url_for 'index.html'
90
85
 
91
- expect(cookie[:name]).to eq 'expiration'
92
- expect(cookie[:value]).to eq 'b'
86
+ expires = ::Time.now + 10_000
87
+ options = {expires: expires}
93
88
 
94
- expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i)
95
- end
89
+ browser.cookies.add 'expiration', 'b', options
90
+ cookie = browser.cookies.to_a.first
96
91
 
97
- # Pending resolution of https://github.com/w3c/webdriver/issues/1571
98
- it 'adding cookie with security does not raise exception but can not be retrieved',
99
- except: [{browser: :firefox,
100
- reason: 'https://github.com/mozilla/geckodriver/issues/1840'},
101
- {browser: %i[chrome edge], platform: :windows}] do
102
- browser.goto WatirSpec.url_for 'index.html'
92
+ expect(cookie[:name]).to eq 'expiration'
93
+ expect(cookie[:value]).to eq 'b'
103
94
 
104
- options = {secure: true}
95
+ expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i)
96
+ end
105
97
 
106
- browser.cookies.add 'secure', 'b', options
107
- cookie = browser.cookies.to_a.find { |e| e[:name] == 'secure' }
108
- expect(cookie).to be_nil
109
- end
98
+ # Pending resolution of https://github.com/w3c/webdriver/issues/1571
99
+ it 'adding cookie with security does not raise exception but can not be retrieved',
100
+ except: [{browser: :firefox,
101
+ reason: 'https://github.com/mozilla/geckodriver/issues/1840'},
102
+ {browser: %i[chrome edge], platform: :windows}] do
103
+ browser.goto WatirSpec.url_for 'index.html'
110
104
 
111
- it 'removes a cookie' do
112
- browser.goto set_cookie_url
113
- verify_cookies_count 1
105
+ options = {secure: true}
114
106
 
115
- browser.cookies.delete 'monster'
116
- verify_cookies_count 0
117
- end
118
-
119
- it 'clears all cookies' do
120
- browser.goto set_cookie_url
121
- browser.cookies.add 'foo', 'bar'
122
- verify_cookies_count 2
107
+ browser.cookies.add 'secure', 'b', options
108
+ cookie = browser.cookies.to_a.find { |e| e[:name] == 'secure' }
109
+ expect(cookie).to be_nil
110
+ end
123
111
 
124
- browser.cookies.clear
125
- verify_cookies_count 0
126
- end
112
+ it 'removes a cookie' do
113
+ browser.goto set_cookie_url
114
+ verify_cookies_count 1
127
115
 
128
- context 'cookie file' do
129
- let(:file) { "#{Dir.tmpdir}/cookies" }
116
+ browser.cookies.delete 'monster'
117
+ verify_cookies_count 0
118
+ end
130
119
 
131
- before do
120
+ it 'clears all cookies' do
132
121
  browser.goto set_cookie_url
133
- browser.cookies.save file
122
+ browser.cookies.add 'foo', 'bar'
123
+ verify_cookies_count 2
124
+
125
+ browser.cookies.clear
126
+ verify_cookies_count 0
134
127
  end
135
128
 
136
- describe '#save' do
137
- it 'saves cookies to file' do
138
- expect(File.read(file)).to eq(browser.cookies.to_a.to_yaml)
129
+ context 'when using file' do
130
+ let(:file) { "#{Dir.tmpdir}/cookies" }
131
+
132
+ before do
133
+ browser.goto set_cookie_url
134
+ browser.cookies.save file
135
+ end
136
+
137
+ describe '#save' do
138
+ it 'saves cookies to file' do
139
+ expect(File.read(file)).to eq(browser.cookies.to_a.to_yaml)
140
+ end
139
141
  end
140
- end
141
142
 
142
- describe '#load', except: {browser: :ie} do
143
- it 'loads cookies from file' do
144
- browser.cookies.clear
145
- browser.cookies.load file
146
- expected = browser.cookies.to_a
147
- actual = YAML.safe_load(File.read(file), permitted_classes: [Symbol])
143
+ describe '#load', except: {browser: :ie} do
144
+ it 'loads cookies from file' do
145
+ browser.cookies.clear
146
+ browser.cookies.load file
147
+ expected = browser.cookies.to_a
148
+ actual = YAML.safe_load(File.read(file), permitted_classes: [::Symbol])
148
149
 
149
- expected.each { |cookie| cookie.delete(:expires) }
150
- actual.each { |cookie| cookie.delete(:expires) }
150
+ expected.each { |cookie| cookie.delete(:expires) }
151
+ actual.each { |cookie| cookie.delete(:expires) }
151
152
 
152
- expect(actual).to eq(expected)
153
+ expect(actual).to eq(expected)
154
+ end
153
155
  end
154
156
  end
155
- end
156
157
 
157
- def set_cookie_url
158
- # add timestamp to url to avoid caching in IE8
159
- WatirSpec.url_for('set_cookie/index.html') + "?t=#{Time.now.to_i + Time.now.usec}"
160
- end
158
+ def set_cookie_url
159
+ # add timestamp to url to avoid caching in IE8
160
+ WatirSpec.url_for('set_cookie/index.html') + "?t=#{::Time.now.to_i + ::Time.now.usec}"
161
+ end
161
162
 
162
- def verify_cookies_count(expected_size)
163
- cookies = browser.cookies.to_a
164
- msg = "expected #{expected_size} cookies, got #{cookies.size}: #{cookies.inspect}"
165
- expect(cookies.size).to eq(expected_size), msg
163
+ def verify_cookies_count(expected_size)
164
+ cookies = browser.cookies.to_a
165
+ msg = "expected #{expected_size} cookies, got #{cookies.size}: #{cookies.inspect}"
166
+ expect(cookies.size).to eq(expected_size), msg
167
+ end
166
168
  end
167
169
  end
@@ -2,35 +2,37 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Element' do
6
- context 'drag and drop', except: {browser: :ie} do
7
- before { browser.goto WatirSpec.url_for('drag_and_drop.html') }
5
+ module Watir
6
+ describe Element do
7
+ describe 'using drag and drop', except: {browser: :ie} do
8
+ before { browser.goto WatirSpec.url_for('drag_and_drop.html') }
8
9
 
9
- let(:draggable) { browser.div id: 'draggable' }
10
- let(:droppable) { browser.div id: 'droppable' }
10
+ let(:draggable) { browser.div id: 'draggable' }
11
+ let(:droppable) { browser.div id: 'droppable' }
11
12
 
12
- it 'can drag and drop an element onto another' do
13
- expect(droppable.text).to include 'Drop here'
14
- draggable.drag_and_drop_on droppable
15
- expect(droppable.text).to include 'Dropped!'
16
- end
13
+ it 'can drag and drop an element onto another' do
14
+ expect(droppable.text).to include 'Drop here'
15
+ draggable.drag_and_drop_on droppable
16
+ expect(droppable.text).to include 'Dropped!'
17
+ end
17
18
 
18
- it 'can drag and drop an element onto another with specified scroll position' do
19
- expect(droppable.text).to include 'Drop here'
20
- draggable.drag_and_drop_on droppable, scroll_to: :center
21
- expect(droppable.text).to include 'Dropped!'
22
- end
19
+ it 'can drag and drop an element onto another with specified scroll position' do
20
+ expect(droppable.text).to include 'Drop here'
21
+ draggable.drag_and_drop_on droppable, scroll_to: :center
22
+ expect(droppable.text).to include 'Dropped!'
23
+ end
23
24
 
24
- it 'can drag an element by the given offset' do
25
- expect(droppable.text).to include 'Drop here'
26
- draggable.drag_and_drop_by 200, 50
27
- expect(droppable.text).to include 'Dropped!'
28
- end
25
+ it 'can drag an element by the given offset' do
26
+ expect(droppable.text).to include 'Drop here'
27
+ draggable.drag_and_drop_by 200, 50
28
+ expect(droppable.text).to include 'Dropped!'
29
+ end
29
30
 
30
- it 'can drag an element by the given offset with specified scroll position' do
31
- expect(droppable.text).to include 'Drop here'
32
- draggable.drag_and_drop_by 200, 50, scroll_to: :center
33
- expect(droppable.text).to include 'Dropped!'
31
+ it 'can drag an element by the given offset with specified scroll position' do
32
+ expect(droppable.text).to include 'Drop here'
33
+ draggable.drag_and_drop_by 200, 50, scroll_to: :center
34
+ expect(droppable.text).to include 'Dropped!'
35
+ end
34
36
  end
35
37
  end
36
38
  end
@@ -2,79 +2,85 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe Watir::Locators::Element::Locator do
6
- describe 'Visible Elements' do
7
- before do
8
- browser.goto(WatirSpec.url_for('wait.html'))
9
- end
5
+ module Watir
6
+ module Locators
7
+ class Element
8
+ describe Locator do
9
+ describe 'Visible Elements' do
10
+ before do
11
+ browser.goto(WatirSpec.url_for('wait.html'))
12
+ end
10
13
 
11
- context 'when true' do
12
- it 'finds single element' do
13
- element = browser.body.element(visible: true)
14
- expect(element.id).to eq 'foo'
15
- end
14
+ context 'when true' do
15
+ it 'finds single element' do
16
+ element = browser.body.element(visible: true)
17
+ expect(element.id).to eq 'foo'
18
+ end
16
19
 
17
- it 'handles tag_name and index' do
18
- element = browser.div(visible: true, index: 1)
19
- expect(element.id).to eq 'buttons'
20
- end
20
+ it 'handles tag_name and index' do
21
+ element = browser.div(visible: true, index: 1)
22
+ expect(element.id).to eq 'buttons'
23
+ end
21
24
 
22
- it 'handles :tag_name and a single regexp attribute' do
23
- element = browser.div(visible: true, id: /ons/)
24
- expect(element.id).to eq 'buttons'
25
- end
25
+ it 'handles :tag_name and a single regexp attribute' do
26
+ element = browser.div(visible: true, id: /ons/)
27
+ expect(element.id).to eq 'buttons'
28
+ end
26
29
 
27
- it 'handles :xpath' do
28
- element = browser.element(visible: true, xpath: './/div[@id="foo"]')
29
- expect(element.id).to eq 'foo'
30
- end
30
+ it 'handles :xpath' do
31
+ element = browser.element(visible: true, xpath: './/div[@id="foo"]')
32
+ expect(element.id).to eq 'foo'
33
+ end
31
34
 
32
- it 'handles :css' do
33
- element = browser.element(visible: true, css: 'div#foo')
34
- expect(element.id).to eq 'foo'
35
- end
35
+ it 'handles :css' do
36
+ element = browser.element(visible: true, css: 'div#foo')
37
+ expect(element.id).to eq 'foo'
38
+ end
36
39
 
37
- it 'handles in collections' do
38
- elements = browser.divs(visible: true)
39
- expect(elements.size).to eq 3
40
- end
41
- end
40
+ it 'handles in collections' do
41
+ elements = browser.divs(visible: true)
42
+ expect(elements.size).to eq 3
43
+ end
44
+ end
42
45
 
43
- context 'when false' do
44
- it 'finds single element' do
45
- element = browser.body.element(visible: false)
46
- expect(element.id).to eq 'bar'
47
- end
46
+ context 'when false' do
47
+ it 'finds single element' do
48
+ element = browser.body.element(visible: false)
49
+ expect(element.id).to eq 'bar'
50
+ end
48
51
 
49
- it 'handles tag_name and index' do
50
- element = browser.div(visible: false, index: 1)
51
- expect(element.id).to eq 'also_hidden'
52
- end
52
+ it 'handles tag_name and index' do
53
+ element = browser.div(visible: false, index: 1)
54
+ expect(element.id).to eq 'also_hidden'
55
+ end
53
56
 
54
- it 'handles :tag_name and a single regexp attribute' do
55
- element = browser.div(visible: false, id: /_/)
56
- expect(element.id).to eq 'also_hidden'
57
- end
57
+ it 'handles :tag_name and a single regexp attribute' do
58
+ element = browser.div(visible: false, id: /_/)
59
+ expect(element.id).to eq 'also_hidden'
60
+ end
58
61
 
59
- it 'handles :xpath' do
60
- element = browser.element(visible: false, xpath: './/div[@id="bar"]')
61
- expect(element.id).to eq 'bar'
62
- end
62
+ it 'handles :xpath' do
63
+ element = browser.element(visible: false, xpath: './/div[@id="bar"]')
64
+ expect(element.id).to eq 'bar'
65
+ end
63
66
 
64
- it 'handles :css' do
65
- element = browser.element(visible: false, css: 'div#bar')
66
- expect(element.id).to eq 'bar'
67
- end
67
+ it 'handles :css' do
68
+ element = browser.element(visible: false, css: 'div#bar')
69
+ expect(element.id).to eq 'bar'
70
+ end
68
71
 
69
- it 'handles in collections' do
70
- elements = browser.divs(visible: false)
71
- expect(elements.size).to eq 3
72
- end
73
- end
72
+ it 'handles in collections' do
73
+ elements = browser.divs(visible: false)
74
+ expect(elements.size).to eq 3
75
+ end
76
+ end
74
77
 
75
- it 'raises exception when value is not Boolean' do
76
- msg = 'expected one of [TrueClass, FalseClass], got "true":String'
77
- expect { browser.body.element(visible: 'true') }.to raise_exception(TypeError, msg)
78
+ it 'raises exception when value is not Boolean' do
79
+ msg = 'expected one of [TrueClass, FalseClass], got "true":String'
80
+ expect { browser.body.element(visible: 'true') }.to raise_exception(TypeError, msg)
81
+ end
82
+ end
83
+ end
78
84
  end
79
85
  end
80
86
  end
@@ -2,66 +2,68 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Area' do
6
- before :each do
7
- browser.goto(WatirSpec.url_for('images.html'))
8
- end
5
+ module Watir
6
+ describe Area do
7
+ before do
8
+ browser.goto(WatirSpec.url_for('images.html'))
9
+ end
9
10
 
10
- # Exists method
11
- describe '#exist?' do
12
- it 'returns true if the area exists' do
13
- expect(browser.area(id: 'NCE')).to exist
14
- expect(browser.area(id: /NCE/)).to exist
15
- expect(browser.area(title: 'Tables')).to exist
16
- expect(browser.area(title: /Tables/)).to exist
17
- expect(browser.area(href: 'tables.html')).to exist
18
- expect(browser.area(href: /tables/)).to exist
11
+ # Exists method
12
+ describe '#exist?' do
13
+ it 'returns true if the area exists' do
14
+ expect(browser.area(id: 'NCE')).to exist
15
+ expect(browser.area(id: /NCE/)).to exist
16
+ expect(browser.area(title: 'Tables')).to exist
17
+ expect(browser.area(title: /Tables/)).to exist
18
+ expect(browser.area(href: 'tables.html')).to exist
19
+ expect(browser.area(href: /tables/)).to exist
19
20
 
20
- expect(browser.area(index: 0)).to exist
21
- expect(browser.area(xpath: "//area[@id='NCE']")).to exist
22
- end
21
+ expect(browser.area(index: 0)).to exist
22
+ expect(browser.area(xpath: "//area[@id='NCE']")).to exist
23
+ end
23
24
 
24
- it 'returns the first area if given no args' do
25
- expect(browser.area).to exist
26
- end
25
+ it 'returns the first area if given no args' do
26
+ expect(browser.area).to exist
27
+ end
27
28
 
28
- it "returns false if the area doesn't exist" do
29
- expect(browser.area(id: 'no_such_id')).to_not exist
30
- expect(browser.area(id: /no_such_id/)).to_not exist
31
- expect(browser.area(title: 'no_such_title')).to_not exist
32
- expect(browser.area(title: /no_such_title/)).to_not exist
29
+ it "returns false if the area doesn't exist" do
30
+ expect(browser.area(id: 'no_such_id')).not_to exist
31
+ expect(browser.area(id: /no_such_id/)).not_to exist
32
+ expect(browser.area(title: 'no_such_title')).not_to exist
33
+ expect(browser.area(title: /no_such_title/)).not_to exist
33
34
 
34
- expect(browser.area(href: 'no-tables.html')).to_not exist
35
- expect(browser.area(href: /no-tables/)).to_not exist
35
+ expect(browser.area(href: 'no-tables.html')).not_to exist
36
+ expect(browser.area(href: /no-tables/)).not_to exist
36
37
 
37
- expect(browser.area(index: 1337)).to_not exist
38
- expect(browser.area(xpath: "//area[@id='no_such_id']")).to_not exist
39
- end
38
+ expect(browser.area(index: 1337)).not_to exist
39
+ expect(browser.area(xpath: "//area[@id='no_such_id']")).not_to exist
40
+ end
40
41
 
41
- it "raises TypeError when 'what' argument is invalid" do
42
- expect { browser.area(id: 3.14).exists? }.to raise_error(TypeError)
42
+ it "raises TypeError when 'what' argument is invalid" do
43
+ expect { browser.area(id: 3.14).exists? }.to raise_error(TypeError)
44
+ end
43
45
  end
44
- end
45
46
 
46
- # Attribute methods
47
- describe '#id' do
48
- it 'returns the id attribute' do
49
- expect(browser.area(index: 0).id).to eq 'NCE'
50
- end
47
+ # Attribute methods
48
+ describe '#id' do
49
+ it 'returns the id attribute' do
50
+ expect(browser.area(index: 0).id).to eq 'NCE'
51
+ end
51
52
 
52
- it "returns an empty string if the element exists and the attribute doesn't" do
53
- expect(browser.area(index: 2).id).to eq ''
54
- end
53
+ it "returns an empty string if the element exists and the attribute doesn't" do
54
+ expect(browser.area(index: 2).id).to eq ''
55
+ end
55
56
 
56
- it "raises UnknownObjectException if the area doesn't exist" do
57
- expect { browser.area(id: 'no_such_id').id }.to raise_unknown_object_exception
58
- expect { browser.area(index: 1337).id }.to raise_unknown_object_exception
57
+ it "raises UnknownObjectException if the area doesn't exist" do
58
+ expect { browser.area(id: 'no_such_id').id }.to raise_unknown_object_exception
59
+ expect { browser.area(index: 1337).id }.to raise_unknown_object_exception
60
+ end
59
61
  end
60
- end
61
62
 
62
- describe '#respond_to?' do
63
- it 'returns true for all attribute methods' do
64
- expect(browser.area(index: 0)).to respond_to(:id)
63
+ describe '#respond_to?' do
64
+ it 'returns true for all attribute methods' do
65
+ expect(browser.area(index: 0)).to respond_to(:id)
66
+ end
65
67
  end
66
68
  end
67
69
  end