watir 6.15.0 → 6.15.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,12 +10,11 @@ describe Watir::Locators::Row::SelectorBuilder do
10
10
 
11
11
  @scope_tag_name ||= @query_scope.tag_name
12
12
 
13
- built = selector_builder.build(@selector)
14
- expect(built).to eq [@wd_locator, (@remaining || {})]
13
+ expect(selector_builder.build(@selector)).to eq @built
15
14
 
16
15
  next unless @data_locator || @tag_name
17
16
 
18
- expect { @located = @query_scope.wd.first(@wd_locator) }.not_to raise_exception
17
+ expect { @located = @query_scope.wd.first(@built) }.not_to raise_exception
19
18
 
20
19
  if @data_locator
21
20
  expect(@located.attribute('data-locator')).to eq(@data_locator)
@@ -34,7 +33,7 @@ describe Watir::Locators::Row::SelectorBuilder do
34
33
  it 'with only table query scope' do
35
34
  @query_scope = browser.element(id: 'outer').locate
36
35
  @selector = {}
37
- @wd_locator = {xpath: "./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
36
+ @built = {xpath: "./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
38
37
  "./*[local-name()='thead']/*[local-name()='tr'] | ./*[local-name()='tfoot']/*[local-name()='tr']"}
39
38
  @data_locator = 'first row'
40
39
  end
@@ -42,21 +41,21 @@ describe Watir::Locators::Row::SelectorBuilder do
42
41
  it 'with tbody query scope' do
43
42
  @query_scope = browser.element(id: 'first').locate
44
43
  @selector = {}
45
- @wd_locator = {xpath: "./*[local-name()='tr']"}
44
+ @built = {xpath: "./*[local-name()='tr']"}
46
45
  @data_locator = 'tbody row'
47
46
  end
48
47
 
49
48
  it 'with thead query scope' do
50
49
  @query_scope = browser.element(id: 'tax_headers').locate
51
50
  @selector = {}
52
- @wd_locator = {xpath: "./*[local-name()='tr']"}
51
+ @built = {xpath: "./*[local-name()='tr']"}
53
52
  @data_locator = 'thead row'
54
53
  end
55
54
 
56
55
  it 'with tfoot query scope' do
57
56
  @query_scope = browser.element(id: 'tax_totals').locate
58
57
  @selector = {}
59
- @wd_locator = {xpath: "./*[local-name()='tr']"}
58
+ @built = {xpath: "./*[local-name()='tr']"}
60
59
  @data_locator = 'tfoot row'
61
60
  end
62
61
  end
@@ -69,7 +68,7 @@ describe Watir::Locators::Row::SelectorBuilder do
69
68
  it 'positive' do
70
69
  @query_scope = browser.element(id: 'outer').locate
71
70
  @selector = {index: 1}
72
- @wd_locator = {xpath: "(./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
71
+ @built = {xpath: "(./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
73
72
  "./*[local-name()='thead']/*[local-name()='tr'] | ./*[local-name()='tfoot']/*[local-name()='tr'])[2]"}
74
73
  @data_locator = 'middle row'
75
74
  end
@@ -77,7 +76,7 @@ describe Watir::Locators::Row::SelectorBuilder do
77
76
  it 'negative' do
78
77
  @query_scope = browser.element(id: 'outer').locate
79
78
  @selector = {index: -3}
80
- @wd_locator = {xpath: "(./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
79
+ @built = {xpath: "(./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
81
80
  "./*[local-name()='thead']/*[local-name()='tr'] | ./*[local-name()='tfoot']/*[local-name()='tr'])[last()-2]"}
82
81
  @data_locator = 'first row'
83
82
  end
@@ -85,7 +84,7 @@ describe Watir::Locators::Row::SelectorBuilder do
85
84
  it 'last' do
86
85
  @query_scope = browser.element(id: 'outer').locate
87
86
  @selector = {index: -1}
88
- @wd_locator = {xpath: "(./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
87
+ @built = {xpath: "(./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
89
88
  "./*[local-name()='thead']/*[local-name()='tr'] | ./*[local-name()='tfoot']/*[local-name()='tr'])[last()]"}
90
89
  @data_locator = 'last row'
91
90
  end
@@ -93,7 +92,7 @@ describe Watir::Locators::Row::SelectorBuilder do
93
92
  it 'does not return index if it is zero' do
94
93
  @query_scope = browser.element(id: 'outer').locate
95
94
  @selector = {index: 0}
96
- @wd_locator = {xpath: "./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
95
+ @built = {xpath: "./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
97
96
  "./*[local-name()='thead']/*[local-name()='tr'] | ./*[local-name()='tfoot']/*[local-name()='tr']"}
98
97
  @data_locator = 'first row'
99
98
  end
@@ -101,7 +100,7 @@ describe Watir::Locators::Row::SelectorBuilder do
101
100
  it 'raises exception when index is not an Integer', skip_after: true do
102
101
  @query_scope = browser.element(id: 'outer').locate
103
102
  selector = {index: 'foo'}
104
- msg = 'expected Integer, got "foo":String'
103
+ msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/
105
104
  expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
106
105
  end
107
106
  end
@@ -114,7 +113,7 @@ describe Watir::Locators::Row::SelectorBuilder do
114
113
 
115
114
  it 'attribute and class' do
116
115
  @selector = {id: 'gregory', class: /brick/}
117
- @wd_locator = {xpath: "./*[local-name()='tr'][contains(@class, 'brick')][@id='gregory'] | " \
116
+ @built = {xpath: "./*[local-name()='tr'][contains(@class, 'brick')][@id='gregory'] | " \
118
117
  "./*[local-name()='tbody']/*[local-name()='tr'][contains(@class, 'brick')][@id='gregory'] | " \
119
118
  "./*[local-name()='thead']/*[local-name()='tr'][contains(@class, 'brick')][@id='gregory'] | " \
120
119
  "./*[local-name()='tfoot']/*[local-name()='tr'][contains(@class, 'brick')][@id='gregory']"}
@@ -130,9 +129,8 @@ describe Watir::Locators::Row::SelectorBuilder do
130
129
 
131
130
  it 'any text value' do
132
131
  @selector = {text: 'Gregory'}
133
- @wd_locator = {xpath: "./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
134
- "./*[local-name()='thead']/*[local-name()='tr'] | ./*[local-name()='tfoot']/*[local-name()='tr']"}
135
- @remaining = {text: 'Gregory'}
132
+ @built = {xpath: "./*[local-name()='tr'] | ./*[local-name()='tbody']/*[local-name()='tr'] | " \
133
+ "./*[local-name()='thead']/*[local-name()='tr'] | ./*[local-name()='tfoot']/*[local-name()='tr']", text: 'Gregory'}
136
134
  end
137
135
  end
138
136
 
@@ -143,7 +141,7 @@ describe Watir::Locators::Row::SelectorBuilder do
143
141
  @query_scope = browser.element(id: 'gregory').locate
144
142
 
145
143
  @selector = {adjacent: :ancestor, index: 1}
146
- @wd_locator = {xpath: './ancestor::*[2]'}
144
+ @built = {xpath: './ancestor::*[2]'}
147
145
  @data_locator = 'top table'
148
146
  end
149
147
  end
@@ -27,12 +27,11 @@ describe Watir::Locators::TextField::SelectorBuilder do
27
27
 
28
28
  @query_scope ||= browser
29
29
 
30
- built = selector_builder.build(@selector)
31
- expect(built).to eq [@wd_locator, (@remaining || {})]
30
+ expect(selector_builder.build(@selector)).to eq @built
32
31
 
33
32
  next unless @data_locator || @tag_name
34
33
 
35
- expect { @located = @query_scope.wd.first(@wd_locator) }.not_to raise_exception
34
+ expect { @located = @query_scope.wd.first(@built) }.not_to raise_exception
36
35
 
37
36
  if @data_locator
38
37
  expect(@located.attribute('data-locator')).to eq(@data_locator)
@@ -46,7 +45,7 @@ describe Watir::Locators::TextField::SelectorBuilder do
46
45
  it 'without any arguments' do
47
46
  browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
48
47
  @selector = {}
49
- @wd_locator = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]"}
48
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]"}
50
49
  @data_locator = 'input name'
51
50
  end
52
51
 
@@ -55,27 +54,27 @@ describe Watir::Locators::TextField::SelectorBuilder do
55
54
 
56
55
  it 'specified text field type that is text' do
57
56
  @selector = {type: 'text'}
58
- @wd_locator = {xpath: ".//*[local-name()='input']" \
57
+ @built = {xpath: ".//*[local-name()='input']" \
59
58
  "[translate(@type,'#{uppercase}','#{lowercase}')='text']"}
60
59
  @data_locator = 'first text'
61
60
  end
62
61
 
63
62
  it 'specified text field type that is not text' do
64
63
  @selector = {type: 'number'}
65
- @wd_locator = {xpath: ".//*[local-name()='input']" \
64
+ @built = {xpath: ".//*[local-name()='input']" \
66
65
  "[translate(@type,'#{uppercase}','#{lowercase}')='number']"}
67
66
  @data_locator = '42'
68
67
  end
69
68
 
70
69
  it 'true locates text field with a type specified' do
71
70
  @selector = {type: true}
72
- @wd_locator = {xpath: ".//*[local-name()='input'][#{negative_types}]"}
71
+ @built = {xpath: ".//*[local-name()='input'][#{negative_types}]"}
73
72
  @data_locator = 'input name'
74
73
  end
75
74
 
76
75
  it 'false locates text field without type specified' do
77
76
  @selector = {type: false}
78
- @wd_locator = {xpath: ".//*[local-name()='input'][not(@type)]"}
77
+ @built = {xpath: ".//*[local-name()='input'][not(@type)]"}
79
78
  @data_locator = 'input name'
80
79
  end
81
80
 
@@ -94,31 +93,31 @@ describe Watir::Locators::TextField::SelectorBuilder do
94
93
 
95
94
  it 'positive' do
96
95
  @selector = {index: 4}
97
- @wd_locator = {xpath: "(.//*[local-name()='input'][not(@type) or (#{negative_types})])[5]"}
96
+ @built = {xpath: "(.//*[local-name()='input'][not(@type) or (#{negative_types})])[5]"}
98
97
  @data_locator = 'dev'
99
98
  end
100
99
 
101
100
  it 'negative' do
102
101
  @selector = {index: -3}
103
- @wd_locator = {xpath: "(.//*[local-name()='input'][not(@type) or (#{negative_types})])[last()-2]"}
102
+ @built = {xpath: "(.//*[local-name()='input'][not(@type) or (#{negative_types})])[last()-2]"}
104
103
  @data_locator = '42'
105
104
  end
106
105
 
107
106
  it 'last' do
108
107
  @selector = {index: -1}
109
- @wd_locator = {xpath: "(.//*[local-name()='input'][not(@type) or (#{negative_types})])[last()]"}
108
+ @built = {xpath: "(.//*[local-name()='input'][not(@type) or (#{negative_types})])[last()]"}
110
109
  @data_locator = 'last text'
111
110
  end
112
111
 
113
112
  it 'does not return index if it is zero' do
114
113
  @selector = {index: 0}
115
- @wd_locator = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]"}
114
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]"}
116
115
  @data_locator = 'input name'
117
116
  end
118
117
 
119
118
  it 'raises exception when index is not an Integer', skip_after: true do
120
119
  selector = {index: 'foo'}
121
- msg = 'expected Integer, got "foo":String'
120
+ msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/
122
121
  expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
123
122
  end
124
123
  end
@@ -128,20 +127,51 @@ describe Watir::Locators::TextField::SelectorBuilder do
128
127
 
129
128
  it 'String for value' do
130
129
  @selector = {text: 'Developer'}
131
- @wd_locator = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]"}
132
- @remaining = {text: 'Developer'}
130
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]", text: 'Developer'}
133
131
  end
134
132
 
135
133
  it 'Simple Regexp for value' do
136
134
  @selector = {text: /Dev/}
137
- @wd_locator = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]"}
138
- @remaining = {text: /Dev/}
135
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]", text: /Dev/}
139
136
  end
140
137
 
141
138
  it 'returns complicated Regexp to the locator as a value' do
142
139
  @selector = {text: /^foo$/}
143
- @wd_locator = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]"}
144
- @remaining = {text: /^foo$/}
140
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]", text: /^foo$/}
141
+ end
142
+ end
143
+
144
+ context 'with label' do
145
+ before(:each) { browser.goto(WatirSpec.url_for('forms_with_input_elements.html')) }
146
+
147
+ it 'using String' do
148
+ @selector = {label: 'First name'}
149
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]" \
150
+ "[@id=//label[normalize-space()='First name']/@for or parent::label[normalize-space()='First name']]"}
151
+ @data_locator = 'input name'
152
+ end
153
+
154
+ it 'uses String with hidden text' do
155
+ @selector = {label: 'With hidden text'}
156
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]" \
157
+ "[@id=//label[normalize-space()='With hidden text']/@for or parent::label[normalize-space()='With hidden text']]"}
158
+ @data_locator = 'hidden'
159
+ end
160
+
161
+ # Desired Behavior
162
+ xit 'using simple Regexp' do
163
+ @selector = {label: /First/}
164
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]" \
165
+ "[@id=//label[contains(text(), 'First')]/@for or parent::label[contains(text(), 'First')]]"}
166
+ @data_locator = 'input name'
167
+ end
168
+
169
+ # Desired Behavior
170
+ xit 'using complex Regexp' do
171
+ @selector = {label: /([qa])st? name/}
172
+ @built = {xpath: ".//*[local-name()='input'][not(@type) or (#{negative_types})]" \
173
+ "[@id=//label[contains(text(), 's') and contains(text(), ' name')]/@for or " \
174
+ "parent::label[contains(text(), 's') and contains(text(), ' name')]]", label_element: /([qa])st? name/}
145
175
  end
146
176
  end
147
177
 
@@ -152,9 +182,8 @@ describe Watir::Locators::TextField::SelectorBuilder do
152
182
 
153
183
  it 'locates using tag name, class, attributes and text' do
154
184
  @selector = {text: 'Developer', class: /c/, id: true}
155
- @wd_locator = {xpath: ".//*[local-name()='input'][contains(@class, 'c')]" \
156
- "[not(@type) or (#{negative_types})][@id]"}
157
- @remaining = {text: 'Developer'}
185
+ @built = {xpath: ".//*[local-name()='input'][contains(@class, 'c')]" \
186
+ "[not(@type) or (#{negative_types})][@id]", text: 'Developer'}
158
187
  end
159
188
 
160
189
  it 'delegates adjacent to Element SelectorBuilder' do
@@ -162,7 +191,7 @@ describe Watir::Locators::TextField::SelectorBuilder do
162
191
  @query_scope = browser.element(id: 'new_user_email').locate
163
192
 
164
193
  @selector = {adjacent: :ancestor, index: 1}
165
- @wd_locator = {xpath: './ancestor::*[2]'}
194
+ @built = {xpath: './ancestor::*[2]'}
166
195
  @data_locator = 'form'
167
196
  end
168
197
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.15.0
4
+ version: 6.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Rodionov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-07 00:00:00.000000000 Z
12
+ date: 2018-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver