capybara-extensions 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be82a50d10aa44c6b41eed1bdadbe9ccc47962d9
4
+ data.tar.gz: 66a534229850cad98e8a94c9b1a6af35c4b3c01a
5
+ SHA512:
6
+ metadata.gz: a9fa104f4f7223a6578ef81b9a2a3762791641a2b57e3dbec208cf9d2426f85cfda12cc4adc975e825c40f6734422b9d7b44d2de309a83b3d1845275070b223b
7
+ data.tar.gz: 06102011a95173369fddad6c73caf117237de3c09090c69ed0d93733cb9a76ccd1bb6c9a98793fdb122b26b18b65f8c30dc6b0ee82e49ba4be369ca9e10c15a5
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ bin/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,24 @@
1
+ # Contribution Guidelines #
2
+
3
+ ## Submitting a new issue ##
4
+
5
+ If you want to ensure that your issue gets fixed *fast* you should
6
+ attempt to reproduce the issue in an isolated example application that
7
+ you can share.
8
+
9
+ ## Making a pull request ##
10
+
11
+ If you'd like to submit a pull request please adhere to the following:
12
+
13
+ 1. Your code *must* be tested. Please TDD your code!
14
+ 2. No single-character variables
15
+ 3. Two-spaces instead of tabs
16
+ 4. Single-quotes instead of double-quotes unless you are using string
17
+ interpolation or escapes.
18
+ 5. General Rails/Ruby naming conventions for files and classes
19
+
20
+ Please note that you must adhere to each of the aforementioned rules.
21
+ Failure to do so will result in an immediate closing of the pull
22
+ request. If you update and rebase the pull request to follow the
23
+ guidelines your pull request will be re-opened and considered for
24
+ inclusion.
data/Gemfile CHANGED
@@ -1,14 +1,4 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'https://rubygems.org'
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.6.4"
12
- gem "rcov", ">= 0"
13
- gem "capybara"
14
- end
3
+ # Specify your gem's dependencies in capybara_extensions.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2012 Andy Waite
1
+ Copyright (c) 2013 Michael Dupuis Jr.
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,26 +1,45 @@
1
- # capybara-extensions
1
+ # CapybaraExtensions
2
2
 
3
- Adds the following methods to Capybara::Node::Finders
3
+ [Capybara](https://github.com/jnicklas/capybara) has an intuitive API which mimics the language of an actual user. This library extends Capybara's finders and matchers with additional methods for interacting with tables, lists, and list items, as well as many HTML5 elements.
4
4
 
5
- * parent
5
+ ## Installation
6
6
 
7
- ## Usage
7
+ Add this line to your application's Gemfile:
8
8
 
9
9
  gem 'capybara-extensions'
10
10
 
11
- require 'capybara-extensions'
11
+ And then execute:
12
12
 
13
- ## Contributing to capybara-extensions
13
+ $ bundle
14
14
 
15
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
16
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
17
- * Fork the project
18
- * Start a feature/bugfix branch
19
- * Commit and push until you are happy with your contribution
20
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
21
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
15
+ Or install it yourself as:
22
16
 
23
- ## Copyright
17
+ $ gem install capybara-extensions
24
18
 
25
- Copyright (c) 2012 Andy Waite. See LICENSE.txt for
26
- further details.
19
+ ## Setup
20
+
21
+ Require `capybara-extensions`:
22
+
23
+ ```ruby
24
+ require 'capybara-extensions'
25
+ ```
26
+
27
+ ## The DSL
28
+
29
+ A complete reference of the finders and matchers added by CapybaraExtensions is available at [Rubydoc.info](http://rubydoc.info/github/dockyard/capybara-extensions). You can read more about the library in [this blog post](http://reefpoints.dockyard.com/2013/10/25/capybara-extensions.html).
30
+
31
+ ## Versioning
32
+
33
+ This gem follows [semantic versioning](http://semver.org).
34
+
35
+ ## Contributing
36
+
37
+ Please see our [contribution guidelines](/CONTRIBUTING.md) on how to
38
+ properly submit issues and pull requests.
39
+
40
+ ## Legal
41
+
42
+ [DockYard, Inc](http://dockyard.com) © 2013
43
+
44
+ Licensed under the [MIT
45
+ license](http://www.opensource.org/licenses/mit-license.php).
data/Rakefile CHANGED
@@ -1,53 +1,11 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "capybara-extensions"
18
- gem.homepage = "http://github.com/andyw8/capybara-extensions"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Some useful extensions to Capybara}
21
- gem.description = %Q{Some useful extensions to Capybara}
22
- gem.email = "andy@andywaite.com"
23
- gem.authors = ["Andy Waite"]
24
- gem.add_dependency 'capybara'
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
1
+ require "bundler/gem_tasks"
28
2
  require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
3
 
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- test.rcov_opts << '--exclude "gems/*"'
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'lib'
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/*_test.rb'
8
+ t.verbose = false
41
9
  end
42
10
 
43
11
  task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "capybara-extensions #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
@@ -1,65 +1,30 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara-extensions/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = "capybara-extensions"
8
- s.version = "0.2.0"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capybara-extensions"
8
+ spec.version = CapybaraExtensions::VERSION
9
+ spec.authors = ["Michael Dupuis Jr.", 'Dan McClain']
10
+ spec.email = ["michael.dupuis@dockyard.com", 'rubygems@danmcclain.net']
11
+ spec.description = %q{Complements Capybara with additional finders and matchers.}
12
+ spec.summary = %q{Capybara has an intuitive API which mimics the language of an actual user. This library extends Capybara's finders and matchers with additional methods for interacting with tables, lists, and list items, as well as many HTML5 elements.}
13
+ spec.homepage = "https://github.com/dockyard/capybara-extensions"
14
+ spec.license = "MIT"
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Andy Waite"]
12
- s.date = "2012-03-25"
13
- s.description = "Some useful extensions to Capybara"
14
- s.email = "andy@andywaite.com"
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.txt",
24
- "README.md",
25
- "Rakefile",
26
- "VERSION",
27
- "capybara-extensions.gemspec",
28
- "lib/capybara-extensions.rb",
29
- "test/helper.rb",
30
- "test/test_capybara-extensions.rb"
31
- ]
32
- s.homepage = "http://github.com/andyw8/capybara-extensions"
33
- s.licenses = ["MIT"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = "1.8.10"
36
- s.summary = "Some useful extensions to Capybara"
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
37
19
 
38
- if s.respond_to? :specification_version then
39
- s.specification_version = 3
20
+ spec.add_development_dependency 'builder'
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'byebug'
23
+ spec.add_development_dependency 'capybara_minitest_spec'
24
+ spec.add_development_dependency 'minitest', '< 5.0'
25
+ spec.add_development_dependency 'minitest-reporters', '~> 0.14.21'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'yard'
40
28
 
41
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_development_dependency(%q<shoulda>, [">= 0"])
43
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
44
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
45
- s.add_development_dependency(%q<rcov>, [">= 0"])
46
- s.add_development_dependency(%q<capybara>, [">= 0"])
47
- s.add_runtime_dependency(%q<capybara>, [">= 0"])
48
- else
49
- s.add_dependency(%q<shoulda>, [">= 0"])
50
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
52
- s.add_dependency(%q<rcov>, [">= 0"])
53
- s.add_dependency(%q<capybara>, [">= 0"])
54
- s.add_dependency(%q<capybara>, [">= 0"])
55
- end
56
- else
57
- s.add_dependency(%q<shoulda>, [">= 0"])
58
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
- s.add_dependency(%q<rcov>, [">= 0"])
61
- s.add_dependency(%q<capybara>, [">= 0"])
62
- s.add_dependency(%q<capybara>, [">= 0"])
63
- end
29
+ spec.add_runtime_dependency 'capybara', '~> 2.1.0'
64
30
  end
65
-
@@ -0,0 +1,335 @@
1
+ require_relative 'locators'
2
+
3
+ module CapybaraExtensions::Finders
4
+ include CapybaraExtensions::Locators
5
+ CapybaraExtensions::ExtensionMethods.concat [:find_article, :find_aside, :find_footer, :find_form, :find_header, :find_list_item, :find_navigation, :find_ordered_list, :find_paragraph, :find_row, :find_section, :find_table, :find_unordered_list, :first_article, :first_aside, :first_footer, :first_form, :first_header, :first_navigation, :first_ordered_list, :first_paragraph, :first_row, :first_section, :first_table, :first_unordered_list, :list_item_number, :row_number]
6
+
7
+ # Find an HTML article based on the given arguments.
8
+ #
9
+ # @param args [String] text contained within the article sought.
10
+ # @param args [Object] the object whose article is sought.
11
+ # @return [Capybara::Element] the found element.
12
+ #
13
+ def find_article(args)
14
+ find_element('article', args)
15
+ end
16
+
17
+ alias_method :article, :find_article
18
+
19
+ # Find an HTML aside based on the given arguments.
20
+ #
21
+ # @param args [String] text contained within the aside sought.
22
+ # @param args [Object] the object whose aside is sought.
23
+ # @return [Capybara::Element] the found element.
24
+ #
25
+ def find_aside(args)
26
+ find_element('aside', args)
27
+ end
28
+
29
+ alias_method :aside, :find_aside
30
+
31
+ # Find an HTML footer based on the given arguments.
32
+ #
33
+ # @param args [String] text contained within the footer sought.
34
+ # @param args [Object] the object whose footer is sought.
35
+ # @return [Capybara::Element] the found element.
36
+ #
37
+ def find_footer(args)
38
+ find_element('footer', args)
39
+ end
40
+
41
+ alias_method :footer, :find_footer
42
+
43
+ # Find an HTML form based on the given arguments.
44
+ #
45
+ # @param args [String] text contained within the form sought.
46
+ # @param args [Object] the object whose form is sought.
47
+ # @return [Capybara::Element] the found element.
48
+ #
49
+ def find_form(args)
50
+ find_element('form', args)
51
+ end
52
+
53
+ alias_method :form, :find_form
54
+
55
+ # Find an HTML img based on the src and/or alt values.
56
+ #
57
+ # @param options [Hash] Must pass a hash containing the src and/or alt of the image sought.
58
+ # @return [Capybara::Element] the found element
59
+ #
60
+ def find_image(options = {})
61
+ raise "Must pass a hash containing 'src' or 'alt'" unless options.is_a?(Hash) && (options.has_key?(:src) || options.has_key?(:alt))
62
+ find(:xpath, "//img#{image_locator(options)}")
63
+ end
64
+
65
+ # Find an HTML header based on the given arguments.
66
+ #
67
+ # @param args [String] text contained within the header sought.
68
+ # @param args [Object] the object whose header is sought.
69
+ # @return [Capybara::Element] the found element.
70
+ #
71
+ def find_header(args)
72
+ find_element('header', args)
73
+ end
74
+
75
+ alias_method :header, :find_header
76
+
77
+ # Find an HTML li based on the given arguments.
78
+ #
79
+ # @param args [String] text contained within the li sought.
80
+ # @param args [Object] the object whose li is sought.
81
+ # @return [Capybara::Element] the found element.
82
+ #
83
+ def find_list_item(args)
84
+ find_element('li', args)
85
+ end
86
+
87
+ alias_method :list_item, :find_list_item
88
+
89
+ # Find an HTML nav based on the given arguments.
90
+ #
91
+ # @param args [String] text contained within the nav sought.
92
+ # @param args [Object] the object whose nav is sought.
93
+ # @return [Capybara::Element] the found element.
94
+ #
95
+ def find_navigation(args)
96
+ find_element('nav', args)
97
+ end
98
+
99
+ alias_method :navigation, :find_navigation
100
+
101
+ # Find an HTML ol based on the given arguments.
102
+ #
103
+ # @param args [String] text contained within the ol sought.
104
+ # @param args [Object] the object whose ol is sought.
105
+ # @return [Capybara::Element] the found element.
106
+ #
107
+ def find_ordered_list(args)
108
+ find_element('ol', args)
109
+ end
110
+
111
+ alias_method :ordered_list, :find_ordered_list
112
+
113
+ # Find an HTML p based on the given arguments.
114
+ #
115
+ # @param args [String] text contained within the p sought.
116
+ # @param args [Object] the object whose p is sought.
117
+ # @return [Capybara::Element] the found element.
118
+ #
119
+ def find_paragraph(args)
120
+ find_element('p', args)
121
+ end
122
+
123
+ alias_method :paragraph, :find_paragraph
124
+
125
+ # Find an HTML tr based on the given arguments.
126
+ #
127
+ # @param args [String] text contained within the tr sought.
128
+ # @param args [Object] the object whose tr is sought.
129
+ # @return [Capybara::Element] the found element.
130
+ #
131
+ def find_row(args)
132
+ find_element('tr', args)
133
+ end
134
+
135
+ alias_method :row, :find_row
136
+
137
+ # Find an HTML section based on the given arguments.
138
+ #
139
+ # @param args [String] text contained within the section sought.
140
+ # @param args [Object] the object whose section is sought.
141
+ # @return [Capybara::Element] the found element.
142
+ #
143
+ def find_section(args)
144
+ find_element('section', args)
145
+ end
146
+
147
+ alias_method :section, :find_section
148
+
149
+ # Find an HTML table based on the given arguments.
150
+ #
151
+ # @param args [String] text contained within the table sought.
152
+ # @param args [Object] the object whose table is sought.
153
+ # @return [Capybara::Element] the found element.
154
+ #
155
+ def find_table(args)
156
+ if String === args
157
+ find_element('table', args)
158
+ else
159
+ row = find_row(args)
160
+ row.find(:xpath, 'ancestor::table')
161
+ end
162
+ end
163
+
164
+ alias_method :table, :find_table
165
+
166
+ # Find an HTML ul based on the given arguments.
167
+ #
168
+ # @param args [String] text contained within the ul sought.
169
+ # @param args [Object] the object whose ul is sought.
170
+ # @return [Capybara::Element] the found element.
171
+ #
172
+ def find_unordered_list(args)
173
+ find_element('ul', args)
174
+ end
175
+
176
+ alias_method :unordered_list, :find_unordered_list
177
+
178
+ # Find the first HTML article on the page matching the given arguments.
179
+ #
180
+ # @param args [String] text contained within the article sought.
181
+ # @param args [Object] the object whose article is sought.
182
+ # @return [Capybara::Element] the found element.
183
+ #
184
+ def first_article(args)
185
+ first_element('article', args)
186
+ end
187
+
188
+ # Find the first HTML aside on the page matching the given arguments.
189
+ #
190
+ # @param args [String, Object] if passed a string, the text contained within the aside sought; if passed an object, the object whose aside is sought.
191
+ # @return [Capybara::Element] the found element.
192
+ #
193
+ def first_aside(args)
194
+ first_element('aside', args)
195
+ end
196
+
197
+ # Find the first HTML footer on the page matching the given arguments.
198
+ #
199
+ # @param args [String, Object] if passed a string, the text contained within the footer sought; if passed an object, the object whose footer is sought.
200
+ # @return [Capybara::Element] the found element.
201
+ #
202
+ def first_footer(args)
203
+ first_element('footer', args)
204
+ end
205
+
206
+ # Find the first HTML form on the page matching the given arguments.
207
+ #
208
+ # @param args [String, Object] if passed a string, the text contained within the form sought; if passed an object, the object whose form is sought.
209
+ # @return [Capybara::Element] the found element.
210
+ #
211
+ def first_form(args)
212
+ first_element('form', args)
213
+ end
214
+
215
+ # Find the first HTML header on the page matching the given arguments.
216
+ #
217
+ # @param args [String, Object] if passed a string, the text contained within the header sought; if passed an object, the object whose header is sought.
218
+ # @return [Capybara::Element] the found element.
219
+ #
220
+ def first_header(args)
221
+ first_element('header', args)
222
+ end
223
+
224
+ # Find the first HTML nav on the page matching the given arguments.
225
+ #
226
+ # @param args [String, Object] if passed a string, the text contained within the nav sought; if passed an object, the object whose nav is sought.
227
+ # @return [Capybara::Element] the found element.
228
+ #
229
+ def first_navigation(args)
230
+ first_element('nav', args)
231
+ end
232
+
233
+ # Find the first HTML ol on the page matching the given arguments.
234
+ #
235
+ # @param args [String, Object] if passed a string, the text contained within the ol sought; if passed an object, the object whose ol is sought.
236
+ # @return [Capybara::Element] the found element.
237
+ #
238
+ def first_ordered_list(args)
239
+ first_element('ol', args)
240
+ end
241
+
242
+ # Find the first HTML p on the page matching the given arguments.
243
+ #
244
+ # @param args [String, Object] if passed a string, the text contained within the p sought; if passed an object, the object whose p is sought.
245
+ # @return [Capybara::Element] the found element.
246
+ #
247
+ def first_paragraph(args)
248
+ first_element('p', args)
249
+ end
250
+
251
+ # Find the first HTML tr on the page matching the given arguments.
252
+ #
253
+ # @param args [String, Object] if passed a string, the text contained within the tr sought; if passed an object, the object whose tr is sought.
254
+ # @return [Capybara::Element] the found element.
255
+ #
256
+ def first_row(args)
257
+ first_element('tr', args)
258
+ end
259
+
260
+ # Find the first HTML section on the page matching the given arguments.
261
+ #
262
+ # @param args [String, Object] if passed a string, the text contained within the section sought; if passed an object, the object whose section is sought.
263
+ # @return [Capybara::Element] the found element.
264
+ #
265
+ def first_section(args)
266
+ first_element('section', args)
267
+ end
268
+
269
+ # Find the first HTML table on the page matching the given arguments.
270
+ #
271
+ # @param args [String, Object] if passed a string, the text contained within the table sought; if passed an object, the object whose table is sought.
272
+ # @return [Capybara::Element] the found element.
273
+ #
274
+ def first_table(args)
275
+ first_element('table', args)
276
+ end
277
+
278
+ # Find the first HTML ul on the page matching the given arguments.
279
+ #
280
+ # @param args [String, Object] if passed a string, the text contained within the ul sought; if passed an object, the object whose ul is sought.
281
+ # @return [Capybara::Element] the found element.
282
+ #
283
+ def first_unordered_list(args)
284
+ first_element('ul', args)
285
+ end
286
+
287
+ # When scoped to an ol or ul, find the first HTML li on the page matching the given arguments.
288
+ #
289
+ # @param number [Integer] the nth li element sought.
290
+ # @return [Capybara::Element] the found element.
291
+ #
292
+ def list_item_number(number)
293
+ all('li')[number.to_i - 1]
294
+ end
295
+
296
+ # When scoped to a table, find the first HTML tr on the page matching the given arguments.
297
+ #
298
+ # @param number [Integer] the nth tr element sought
299
+ # @return [Capybara::Element] the found element.
300
+ #
301
+ def row_number(number)
302
+ find('tbody').all('tr')[number.to_i - 1]
303
+ end
304
+
305
+ private
306
+
307
+ # Find an element matching the given arguments
308
+ #
309
+ # @param tag [String] the HTML tag for the element
310
+ # @param args [String] the text used to find the element
311
+ # @param args [Object] the object used to find the element. Designed to work with the `content_tag_for` method in Rails, which creates an HTML element with the class and id parameters that relate to the specified Active Record object.
312
+ #
313
+ def find_element(tag, args)
314
+ if String === args
315
+ find(tag, text: args)
316
+ else
317
+ klass = args.class.to_s.downcase
318
+ find("#{tag}##{klass}_#{args.id}", "#{tag}.#{klass}")
319
+ end
320
+ end
321
+
322
+ # Find the first element on the page matching the given arguments.
323
+ #
324
+ # @param args [String, Object] if passed a string, the text contained within the element sought; if passed an object, the object whose element is sought.
325
+ # @return [Capybara::Element] the found element.
326
+ #
327
+ def first_element(tag, args)
328
+ if String === args
329
+ first(tag, text: args)
330
+ else
331
+ klass = args.class.to_s.downcase
332
+ first("#{tag}##{klass}_#{args.id}", "#{tag}.#{klass}")
333
+ end
334
+ end
335
+ end
@@ -0,0 +1,28 @@
1
+ # Locators for xpath.
2
+ module CapybaraExtensions::Locators
3
+
4
+ # Builds a locator via the given src or alt.
5
+ #
6
+ # @param options[Hash] must pass a hash containing src and/or alt to match against.
7
+ # @return [String] string formatted for finding an attribute with xpath.
8
+ #
9
+ def image_locator(options)
10
+ locator = String.new
11
+ locator.concat "[@alt='#{options[:alt]}']" if options[:alt]
12
+ locator.concat "[@src='#{options[:src]}']" if options[:src]
13
+ locator
14
+ end
15
+
16
+ # Builds a locator via the given name and content.
17
+ #
18
+ # @params name[String] the name of the meta tag sought.
19
+ # @params content [String] the content of the meta tag sought.
20
+ # @return [String] string formatted for finding a meta tag with xpath.
21
+ #
22
+ def meta_tag_locator(name, content)
23
+ locator = String.new
24
+ locator.concat "[@name='#{name}']"
25
+ locator.concat "[@content='#{content}']"
26
+ locator
27
+ end
28
+ end