xpath 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/xpath/html.rb CHANGED
@@ -14,8 +14,8 @@ module XPath
14
14
  end
15
15
 
16
16
  def button(locator)
17
- button = descendant(:input)[attr(:type).one_of('submit', 'image', 'button')][attr(:id).equals(locator) | attr(:value).is(locator)]
18
- button += descendant(:button)[attr(:id).equals(locator) | attr(:value).is(locator) | string.n.is(locator)]
17
+ button = descendant(:input)[attr(:type).one_of('submit', 'image', 'button')][attr(:id).equals(locator) | attr(:value).is(locator) | attr(:title).is(locator)]
18
+ button += descendant(:button)[attr(:id).equals(locator) | attr(:value).is(locator) | string.n.is(locator) | attr(:title).is(locator)]
19
19
  button += descendant(:input)[attr(:type).equals('image')][attr(:alt).is(locator)]
20
20
  end
21
21
 
data/lib/xpath/union.rb CHANGED
@@ -12,6 +12,10 @@ module XPath
12
12
  expressions.each(&block)
13
13
  end
14
14
 
15
+ def to_s
16
+ to_xpaths.join(' | ')
17
+ end
18
+
15
19
  def to_xpath(predicate=nil)
16
20
  expressions.map { |e| e.to_xpath(predicate) }.join(' | ')
17
21
  end
data/lib/xpath/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module XPath
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -25,17 +25,26 @@
25
25
  <input type="submit" value="submit-with-value" data="value-submit"/>
26
26
  <input type="submit" value="not exact value submit" data="not-exact-value-submit"/>
27
27
  <input type="submit" value="exact value submit" data="exact-value-submit"/>
28
+ <input type="submit" title="My submit title" value="submit-with-title" data="title-submit">
29
+ <input type="submit" title="Exact submit title" value="exact title submit" data="exact-title-submit">
30
+ <input type="submit" title="Not Exact submit title" value="exact title submit" data="not-exact-title-submit">
28
31
 
29
32
  <input type="button" id="button-with-id" data="id-button" value="Has ID"/>
30
33
  <input type="button" value="button-with-value" data="value-button"/>
31
34
  <input type="button" value="not exact value button" data="not-exact-value-button"/>
32
35
  <input type="button" value="exact value button" data="exact-value-button"/>
36
+ <input type="button" title="My button title" value="button-with-title" data="title-button">
37
+ <input type="button" title="Not Exact button title" value="not exact title button" data="not-exact-title-button">
38
+ <input type="button" title="Exact button title" value="exact title button" data="exact-title-button">
33
39
 
34
40
  <input type="image" id="imgbut-with-id" data="id-imgbut" value="Has ID"/>
35
41
  <input type="image" value="imgbut-with-value" data="value-imgbut"/>
36
42
  <input type="image" alt="imgbut-with-alt" data="alt-imgbut"/>
37
43
  <input type="image" value="not exact value imgbut" data="not-exact-value-imgbut"/>
38
44
  <input type="image" value="exact value imgbut" data="exact-value-imgbut"/>
45
+ <input type="image" title="My imgbut title" value="imgbut-with-title" data="title-imgbut">
46
+ <input type="image" title="Not Exact imgbut title" value="not exact title imgbut" data="not-exact-title-imgbut">
47
+ <input type="image" title="Exact imgbut title" value="exact title imgbut" data="exact-title-imgbut">
39
48
 
40
49
  <button id="btag-with-id" data="id-btag" value="Has ID"/>
41
50
  <button value="btag-with-value" data="value-btag"/>
@@ -45,6 +54,9 @@
45
54
  <button data="text-btag">btag-with-text</button>
46
55
  <button data="not-exact-text-btag">not exact text btag</button>
47
56
  <button data="exact-text-btag">exact text btag</button>
57
+ <button title="My btag title" data="title-btag">btag-with-title</button>
58
+ <button title="Not Exact btag title" data="not-exact-title-btag">not exact title btag</button>
59
+ <button title="Exact btag title" data="exact-title-btag">exact title btag</button>
48
60
 
49
61
  <button data="btag-with-whitespace"> My
50
62
 
@@ -84,3 +96,51 @@
84
96
  </tr>
85
97
  </table>
86
98
  </p>
99
+
100
+ <p>
101
+ <h2>Fields</h2>
102
+
103
+ <h4>With id</h4>
104
+ <input id="input-with-id" value="correct-value" data="input-with-id-data"/>
105
+ <input type="text" id="input-text-with-id" data="input-text-with-id-data"/>
106
+ <input type="password" id="input-password-with-id" data="input-password-with-id-data"/>
107
+ <input type="custom" id="input-custom-with-id" data="input-custom-with-id-data"/>
108
+ <textarea id="textarea-with-id" data="textarea-with-id-data">Correct value</textarea>
109
+ <select id="select-with-id" data="select-with-id-data"></select>
110
+ <input type="submit" id="input-submit-with-id" data="input-submit-with-id-data"/>
111
+ <input type="image" id="input-image-with-id" data="input-image-with-id-data"/>
112
+ <input type="hidden" id="input-hidden-with-id" data="input-hidden-with-id-data"/>
113
+
114
+ <h4>With name</h4>
115
+ <input name="input-with-name" data="input-with-name-data"/>
116
+ <input type="text" name="input-text-with-name" data="input-text-with-name-data"/>
117
+ <input type="password" name="input-password-with-name" data="input-password-with-name-data"/>
118
+ <input type="custom" name="input-custom-with-name" data="input-custom-with-name-data"/>
119
+ <textarea name="textarea-with-name" data="textarea-with-name-data"></textarea>
120
+ <select name="select-with-name" data="select-with-name-data"></select>
121
+ <input type="submit" name="input-submit-with-name" data="input-submit-with-name-data"/>
122
+ <input type="image" name="input-image-with-name" data="input-image-with-name-data"/>
123
+ <input type="hidden" name="input-hidden-with-name" data="input-hidden-with-name-data"/>
124
+
125
+ <h4>With referenced label</h4>
126
+ <label for="input-with-label">Input with label</label><input id="input-with-label" data="input-with-label-data"/>
127
+ <label for="input-text-with-label">Input text with label</label><input type="text" id="input-text-with-label" data="input-text-with-label-data"/>
128
+ <label for="input-password-with-label">Input password with label</label><input type="password" id="input-password-with-label" data="input-password-with-label-data"/>
129
+ <label for="input-custom-with-label">Input custom with label</label><input type="custom" id="input-custom-with-label" data="input-custom-with-label-data"/>
130
+ <label for="textarea-with-label">Textarea with label</label><textarea id="textarea-with-label" data="textarea-with-label-data"></textarea>
131
+ <label for="select-with-label">Select with label</label><select id="select-with-label" data="select-with-label-data"></select>
132
+ <label for="input-submit-with-label">Input submit with label</label><input type="submit" id="input-submit-with-label" data="input-submit-with-label-data"/>
133
+ <label for="input-image-with-label">Input image with label</label><input type="image" id="input-image-with-label" data="input-image-with-label-data"/>
134
+ <label for="input-hidden-with-label">Input hidden with label</label><input type="hidden" id="input-hidden-with-label" data="input-hidden-with-label-data"/>
135
+
136
+ <h4>With parent label</h4>
137
+ <label>Input with parent label<input data="input-with-parent-label-data"/></label>
138
+ <label>Input text with parent label<input type="text" data="input-text-with-parent-label-data"/></label>
139
+ <label>Input password with parent label<input type="password" data="input-password-with-parent-label-data"/></label>
140
+ <label>Input custom with parent label<input type="custom" data="input-custom-with-parent-label-data"/></label>
141
+ <label>Textarea with parent label<textarea data="textarea-with-parent-label-data"></textarea></label>
142
+ <label>Select with parent label<select data="select-with-parent-label-data"></select></label>
143
+ <label>Input submit with parent label<input type="submit" data="input-submit-with-parent-label-data"/></label>
144
+ <label>Input image with parent label<input type="image" data="input-image-with-parent-label-data"/></label>
145
+ <label>Input hidden with parent label<input type="hidden" data="input-hidden-with-parent-label-data"/></label>
146
+ </p>
data/spec/html_spec.rb CHANGED
@@ -45,6 +45,9 @@ describe XPath::HTML do
45
45
  it("finds buttons by value") { get('submit-with-value').should == 'value-submit' }
46
46
  it("finds buttons by approximate value") { get('mit-with-val').should == 'value-submit' }
47
47
  it("prefers buttons with exact value") { all('exact value submit').should == ['exact-value-submit', 'not-exact-value-submit'] }
48
+ it("finds buttons by title") { get('My submit title').should == 'title-submit' }
49
+ it("finds buttons by approximate title") { get('submit title').should == 'title-submit' }
50
+ it("prefers exact matches of title") { all('Exact submit title').should == ['exact-title-submit', 'not-exact-title-submit'] }
48
51
  end
49
52
 
50
53
  context "with button type" do
@@ -52,6 +55,9 @@ describe XPath::HTML do
52
55
  it("finds buttons by value") { get('button-with-value').should == 'value-button' }
53
56
  it("finds buttons by approximate value") { get('ton-with-val').should == 'value-button' }
54
57
  it("prefers buttons with exact value") { all('exact value button').should == ['exact-value-button', 'not-exact-value-button'] }
58
+ it("finds buttons by title") { get('My button title').should == 'title-button' }
59
+ it("finds buttons by approximate title") { get('button title').should == 'title-button' }
60
+ it("prefers exact matches of title") { all('Exact button title').should == ['exact-title-button', 'not-exact-title-button'] }
55
61
  end
56
62
 
57
63
  context "with image type" do
@@ -60,6 +66,9 @@ describe XPath::HTML do
60
66
  it("finds buttons by approximate value") { get('gbut-with-val').should == 'value-imgbut' }
61
67
  it("finds buttons by alt attribute") { get('imgbut-with-alt').should == 'alt-imgbut' }
62
68
  it("prefers buttons with exact value") { all('exact value imgbut').should == ['exact-value-imgbut', 'not-exact-value-imgbut'] }
69
+ it("finds buttons by title") { get('My imgbut title').should == 'title-imgbut' }
70
+ it("finds buttons by approximate title") { get('imgbut title').should == 'title-imgbut' }
71
+ it("prefers exact matches of title") { all('Exact imgbut title').should == ['exact-title-imgbut', 'not-exact-title-imgbut'] }
63
72
  end
64
73
 
65
74
  context "with button tag" do
@@ -73,6 +82,9 @@ describe XPath::HTML do
73
82
  it("finds buttons with child tags by text") { get('An emphatic button').should == 'btag-with-children' }
74
83
  it("finds buttons by text of their children") { get('emphatic').should == 'btag-with-children' }
75
84
  it("prefers buttons with exact text") { all('exact text btag').should == ['exact-text-btag', 'not-exact-text-btag'] }
85
+ it("finds buttons by title") { get('My btag title').should == 'title-btag' }
86
+ it("finds buttons by approximate title") { get('btag title').should == 'title-btag' }
87
+ it("prefers exact matches of title") { all('Exact btag title').should == ['exact-title-btag', 'not-exact-title-btag'] }
76
88
  end
77
89
 
78
90
  context "with unkown type" do
@@ -94,55 +106,58 @@ describe XPath::HTML do
94
106
  subject { :field }
95
107
 
96
108
  context "by id" do
97
- it("finds inputs with text type") {}
98
- it("finds inputs with password type") {}
99
- it("finds inputs with custom type") {}
100
- it("finds textareas") {}
101
- it("finds select boxes") {}
102
- it("does not find submit buttons") {}
103
- it("does not find image buttons") {}
104
- it("does not find hidden fields") {}
109
+ it("finds inputs with no type") { get('input-with-id').should == 'input-with-id-data' }
110
+ it("finds inputs with text type") { get('input-text-with-id').should == 'input-text-with-id-data' }
111
+ it("finds inputs with password type") { get('input-password-with-id').should == 'input-password-with-id-data' }
112
+ it("finds inputs with custom type") { get('input-custom-with-id').should == 'input-custom-with-id-data' }
113
+ it("finds textareas") { get('textarea-with-id').should == 'textarea-with-id-data' }
114
+ it("finds select boxes") { get('select-with-id').should == 'select-with-id-data' }
115
+ it("does not find submit buttons") { get('input-submit-with-id').should be_nil }
116
+ it("does not find image buttons") { get('input-image-with-id').should be_nil }
117
+ it("does not find hidden fields") { get('input-hidden-with-id').should be_nil }
105
118
  end
106
119
 
107
120
  context "by name" do
108
- it("finds inputs with text type") {}
109
- it("finds inputs with password type") {}
110
- it("finds inputs with custom type") {}
111
- it("finds textareas") {}
112
- it("finds select boxes") {}
113
- it("does not find submit buttons") {}
114
- it("does not find image buttons") {}
115
- it("does not find hidden fields") {}
121
+ it("finds inputs with no type") { get('input-with-name').should == 'input-with-name-data' }
122
+ it("finds inputs with text type") { get('input-text-with-name').should == 'input-text-with-name-data' }
123
+ it("finds inputs with password type") { get('input-password-with-name').should == 'input-password-with-name-data' }
124
+ it("finds inputs with custom type") { get('input-custom-with-name').should == 'input-custom-with-name-data' }
125
+ it("finds textareas") { get('textarea-with-name').should == 'textarea-with-name-data' }
126
+ it("finds select boxes") { get('select-with-name').should == 'select-with-name-data' }
127
+ it("does not find submit buttons") { get('input-submit-with-name').should be_nil }
128
+ it("does not find image buttons") { get('input-image-with-name').should be_nil }
129
+ it("does not find hidden fields") { get('input-hidden-with-name').should be_nil }
116
130
  end
117
131
 
118
132
  context "by referenced label" do
119
- it("finds inputs with text type") {}
120
- it("finds inputs with password type") {}
121
- it("finds inputs with custom type") {}
122
- it("finds textareas") {}
123
- it("finds select boxes") {}
124
- it("does not find submit buttons") {}
125
- it("does not find image buttons") {}
126
- it("does not find hidden fields") {}
133
+ it("finds inputs with no type") { get('Input with label').should == 'input-with-label-data' }
134
+ it("finds inputs with text type") { get('Input text with label').should == 'input-text-with-label-data' }
135
+ it("finds inputs with password type") { get('Input password with label').should == 'input-password-with-label-data' }
136
+ it("finds inputs with custom type") { get('Input custom with label').should == 'input-custom-with-label-data' }
137
+ it("finds textareas") { get('Textarea with label').should == 'textarea-with-label-data' }
138
+ it("finds select boxes") { get('Select with label').should == 'select-with-label-data' }
139
+ it("does not find submit buttons") { get('Input submit with label').should be_nil }
140
+ it("does not find image buttons") { get('Input image with label').should be_nil }
141
+ it("does not find hidden fields") { get('Input hidden with label').should be_nil }
127
142
  end
128
143
 
129
144
  context "by parent label" do
130
- it("finds inputs with text type") { get('Label text').should == 'id-text' }
131
- it("finds inputs where label has problem chars") { get("Label text's got an apostrophe").should == 'id-problem-text' }
132
- it("finds inputs with password type") {}
133
- it("finds inputs with custom type") {}
134
- it("finds textareas") {}
135
- it("finds select boxes") {}
136
- it("does not find submit buttons") {}
137
- it("does not find image buttons") {}
138
- it("does not find hidden fields") {}
145
+ it("finds inputs with no type") { get('Input with parent label').should == 'input-with-parent-label-data' }
146
+ it("finds inputs with text type") { get('Input text with parent label').should == 'input-text-with-parent-label-data' }
147
+ it("finds inputs with password type") { get('Input password with parent label').should == 'input-password-with-parent-label-data' }
148
+ it("finds inputs with custom type") { get('Input custom with parent label').should == 'input-custom-with-parent-label-data' }
149
+ it("finds textareas") { get('Textarea with parent label').should == 'textarea-with-parent-label-data' }
150
+ it("finds select boxes") { get('Select with parent label').should == 'select-with-parent-label-data' }
151
+ it("does not find submit buttons") { get('Input submit with parent label').should be_nil }
152
+ it("does not find image buttons") { get('Input image with parent label').should be_nil }
153
+ it("does not find hidden fields") { get('Input hidden with parent label').should be_nil }
139
154
  end
140
155
 
141
156
  context "with :with option" do
142
- it("finds inputs that match option") {}
143
- it("omits inputs that don't match option") {}
144
- it("finds textareas that match option") {}
145
- it("omits textareas that don't match option") {}
157
+ it("finds inputs that match option") { get('input-with-id', :with => 'correct-value').should == 'input-with-id-data' }
158
+ it("omits inputs that don't match option") { get('input-with-id', :with => 'wrong-value').should be_nil }
159
+ it("finds textareas that match option") { get('textarea-with-id', :with => 'Correct value').should == 'textarea-with-id-data' }
160
+ it("omits textareas that don't match option") { get('textarea-with-id', :with => 'Wrong value').should be_nil }
146
161
  end
147
162
 
148
163
  context "with :checked option" do
@@ -170,6 +185,26 @@ describe XPath::HTML do
170
185
 
171
186
  end
172
187
 
188
+ describe '#select' do
189
+
190
+ end
191
+
192
+ describe '#checkbox' do
193
+
194
+ end
195
+
196
+ describe '#radio_button' do
197
+
198
+ end
199
+
200
+ describe '#file_field' do
201
+
202
+ end
203
+
204
+ describe '#option' do
205
+
206
+ end
207
+
173
208
  describe "#optgroup" do
174
209
  subject { :optgroup }
175
210
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jonas Nicklas
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-09 00:00:00 +01:00
17
+ date: 2011-04-25 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -37,13 +37,12 @@ dependencies:
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
40
- - - ">="
40
+ - - ~>
41
41
  - !ruby/object:Gem::Version
42
42
  segments:
43
- - 1
44
43
  - 2
45
- - 9
46
- version: 1.2.9
44
+ - 0
45
+ version: "2.0"
47
46
  type: :development
48
47
  version_requirements: *id002
49
48
  - !ruby/object:Gem::Dependency