watir-capybara-helpers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +26 -0
- data/Rakefile +2 -0
- data/lib/watir-capybara-helpers.rb +7 -0
- data/lib/watir-capybara-helpers/browser.rb +72 -0
- data/lib/watir-capybara-helpers/container.rb +193 -0
- data/lib/watir-capybara-helpers/element.rb +12 -0
- data/lib/watir-capybara-helpers/exception.rb +7 -0
- data/lib/watir-capybara-helpers/version.rb +3 -0
- data/watir-capybara-helpers.gemspec +27 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fad4614151ebc9e3caf614115a93a140179da099
|
4
|
+
data.tar.gz: d93a374cd62d6914b87e211e49d086a4ee5ecfc0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df21164a3bdc4b4cc36dc16859db3b151ec1490b3c6e826735b45ee5b7d5eb25788795c4d2a5528a397475a022675a020c54543c17032eb9732042f1cea74ee5
|
7
|
+
data.tar.gz: 9638a3cd6c09937a0db634a80f726b5317b744498c9fbc4efa84b4d2ad21760a0325d5b8fc0a658ae06085f5946a838ca99927205fe1bb0a7ce57ed9496422ff
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
watir-capybara-helpers
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.2
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Eugene Melnikov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Watir::Capybara::Helpers
|
2
|
+
|
3
|
+
Make it possible to use most popular capybara methods in watir tests.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'watir-capybara-helpers'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install watir-capybara-helpers
|
18
|
+
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
1. Fork it ( https://github.com/melnikaite/watir-capybara-helpers/fork )
|
23
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
24
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
25
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
26
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
class Browser
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
alias_method :current_url, :url
|
7
|
+
alias_method :visit, :goto
|
8
|
+
alias_method :go_back, :back
|
9
|
+
alias_method :go_forward, :forward
|
10
|
+
|
11
|
+
def_delegator :@driver, :window_handle, :current_window_handle
|
12
|
+
|
13
|
+
def evaluate_script(script)
|
14
|
+
execute_script "return #{script}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def save_screenshot(path = nil, options = {})
|
18
|
+
path ||= "watir-#{DateTime.now.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.png"
|
19
|
+
screenshot.save path
|
20
|
+
path
|
21
|
+
end
|
22
|
+
|
23
|
+
def save_page(path = nil)
|
24
|
+
path ||= "watir-#{DateTime.now.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.html"
|
25
|
+
File.open(path, 'w') { |f| f.write(browser.html) }
|
26
|
+
path
|
27
|
+
end
|
28
|
+
|
29
|
+
def save_and_open_page(path = nil)
|
30
|
+
require "launchy"
|
31
|
+
Launchy.open(save_page(path))
|
32
|
+
rescue LoadError
|
33
|
+
warn "Please install the launchy gem to open page with save_and_open_page"
|
34
|
+
end
|
35
|
+
|
36
|
+
def save_and_open_screenshot(path = nil, options = {})
|
37
|
+
require "launchy"
|
38
|
+
Launchy.open(save_screenshot(path))
|
39
|
+
rescue LoadError
|
40
|
+
warn "Please install the launchy gem to open page with save_and_open_page"
|
41
|
+
end
|
42
|
+
|
43
|
+
def within(*args, &block)
|
44
|
+
element = if args[0].is_a?(Watir::Element)
|
45
|
+
args[0]
|
46
|
+
else
|
47
|
+
find(*args)
|
48
|
+
end
|
49
|
+
element.instance_eval &block
|
50
|
+
end
|
51
|
+
|
52
|
+
def within_frame(selector, &block)
|
53
|
+
frame = %w(id name).each do |field|
|
54
|
+
element = browser.frame(field.to_sym => selector)
|
55
|
+
break element if element.exist?
|
56
|
+
end
|
57
|
+
|
58
|
+
raise_can_not_find_by(selector) unless frame.class.eql?(Watir::Frame)
|
59
|
+
|
60
|
+
frame.instance_eval &block
|
61
|
+
end
|
62
|
+
|
63
|
+
# make all selenium methods accessible
|
64
|
+
def method_missing(name, *args, &block)
|
65
|
+
if driver.respond_to?(name)
|
66
|
+
driver.send(name, *args, &block)
|
67
|
+
else
|
68
|
+
super
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Watir
|
3
|
+
module Container
|
4
|
+
def all(*args)
|
5
|
+
if args.length == 2
|
6
|
+
elements(args[0] => args[1]).to_a.map(&:to_subtype)
|
7
|
+
else
|
8
|
+
elements(:css => args[0] || '*').to_a.map(&:to_subtype)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def first(*args)
|
13
|
+
element = if args.length == 2
|
14
|
+
element(args[0] => args[1])
|
15
|
+
else
|
16
|
+
element(:css => args[0])
|
17
|
+
end
|
18
|
+
|
19
|
+
element.exist? ? element.to_subtype : nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def find(*args)
|
23
|
+
elements = if args.length == 2
|
24
|
+
elements(args[0] => args[1]).to_a.map(&:to_subtype)
|
25
|
+
else
|
26
|
+
elements(:css => args[0]).to_a.map(&:to_subtype)
|
27
|
+
end
|
28
|
+
|
29
|
+
raise Watir::Exception::Ambiguous.new("Ambiguous match, found #{elements.length} elements matching #{args[1] || args[0]}") if elements.length > 1
|
30
|
+
|
31
|
+
elements.empty? ? nil : elements.first.to_subtype
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_xpath(selector)
|
35
|
+
find(:xpath, selector)
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_css(selector)
|
39
|
+
find(:css, selector)
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_no_selector?(*args)
|
43
|
+
first(args).nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
alias_method :have_no_selector?, :has_no_selector?
|
47
|
+
|
48
|
+
def has_selector?(*args)
|
49
|
+
!has_no_selector?(args)
|
50
|
+
end
|
51
|
+
|
52
|
+
alias_method :have_selector?, :has_selector?
|
53
|
+
|
54
|
+
def has_no_xpath?(selector)
|
55
|
+
first(:xpath, selector).nil?
|
56
|
+
end
|
57
|
+
|
58
|
+
alias_method :have_no_xpath?, :has_no_xpath?
|
59
|
+
|
60
|
+
def has_xpath?(selector)
|
61
|
+
!has_no_xpath?(selector)
|
62
|
+
end
|
63
|
+
|
64
|
+
alias_method :have_xpath?, :has_xpath?
|
65
|
+
|
66
|
+
def has_no_css?(selector)
|
67
|
+
first(:css, selector).nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
alias_method :have_no_css?, :has_no_css?
|
71
|
+
|
72
|
+
def has_css?(selector)
|
73
|
+
!has_no_css?(selector)
|
74
|
+
end
|
75
|
+
|
76
|
+
alias_method :have_css?, :has_css?
|
77
|
+
|
78
|
+
def has_no_content?(text)
|
79
|
+
text = text.is_a?(Regexp) ? text : Regexp.new(Regexp.escape(text))
|
80
|
+
text.scan(text).empty?
|
81
|
+
end
|
82
|
+
|
83
|
+
alias_method :have_no_content?, :has_no_content?
|
84
|
+
|
85
|
+
def has_content?(text)
|
86
|
+
!has_no_content?(text)
|
87
|
+
end
|
88
|
+
|
89
|
+
alias_method :have_content?, :has_content?
|
90
|
+
|
91
|
+
def fill_in(selector, options = {})
|
92
|
+
find(selector).set(options[:with])
|
93
|
+
end
|
94
|
+
|
95
|
+
def click_button(selector)
|
96
|
+
%w(id text value).each do |field|
|
97
|
+
element = button(field.to_sym => selector)
|
98
|
+
if element.exist?
|
99
|
+
element.click
|
100
|
+
return element
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
raise_can_not_find_by(selector)
|
105
|
+
end
|
106
|
+
|
107
|
+
def click_link(selector)
|
108
|
+
%w(id text).each do |field|
|
109
|
+
element = link(field.to_sym => selector)
|
110
|
+
if element.exist?
|
111
|
+
element.click
|
112
|
+
return element
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
image = image(:alt => selector)
|
117
|
+
if image.exist?
|
118
|
+
element = image.parent
|
119
|
+
if element.exist? && element.is_a?(Watir::Anchor)
|
120
|
+
element.click
|
121
|
+
return element
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
raise_can_not_find_by(selector)
|
126
|
+
end
|
127
|
+
|
128
|
+
def choose(selector)
|
129
|
+
find_by_name_id_or_label(:radio, selector).set(true)
|
130
|
+
end
|
131
|
+
|
132
|
+
def check(selector)
|
133
|
+
find_by_name_id_or_label(:checkbox, selector).set(true)
|
134
|
+
end
|
135
|
+
|
136
|
+
def uncheck(selector)
|
137
|
+
find_by_name_id_or_label(:checkbox, selector).set(false)
|
138
|
+
end
|
139
|
+
|
140
|
+
def select(value, options = {})
|
141
|
+
if options.has_key?(:from)
|
142
|
+
select = find_by_name_id_or_label(:select_list, options[:from])
|
143
|
+
select.option(:text => value).select
|
144
|
+
|
145
|
+
select
|
146
|
+
else
|
147
|
+
option = option(:text => value)
|
148
|
+
option.select
|
149
|
+
|
150
|
+
option
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def unselect(value, options={})
|
155
|
+
if options.has_key?(:from)
|
156
|
+
select = find_by_name_id_or_label(:select_list, options[:from])
|
157
|
+
select.option(:text => value).clear
|
158
|
+
else
|
159
|
+
option(:text => value).clear
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def attach_file(selector, path)
|
164
|
+
Array(path).each do |p|
|
165
|
+
raise Capybara::FileNotFound, "cannot attach file, #{p} does not exist" unless File.exist?(p.to_s)
|
166
|
+
end
|
167
|
+
|
168
|
+
find_by_name_id_or_label(:file_field, selector).set(path)
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
def raise_can_not_find_by(selector)
|
174
|
+
raise Watir::Exception::UnknownObjectException, "unable to locate element, using `#{selector}`"
|
175
|
+
end
|
176
|
+
|
177
|
+
def find_by_name_id_or_label(field_type, selector)
|
178
|
+
%w(name id).each do |field|
|
179
|
+
element = send(field_type, field.to_sym => selector)
|
180
|
+
return element if element.exist?
|
181
|
+
end
|
182
|
+
|
183
|
+
label = label(:text => selector)
|
184
|
+
raise_can_not_find_by(selector) unless label.exist?
|
185
|
+
|
186
|
+
id = label(:text => selector).for
|
187
|
+
element = file_field(:id => id)
|
188
|
+
return element if element.exist?
|
189
|
+
|
190
|
+
raise_can_not_find_by(selector)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'watir-capybara-helpers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "watir-capybara-helpers"
|
8
|
+
spec.version = WatirCapybaraHelpers::VERSION
|
9
|
+
spec.authors = ["Eugene Melnikov"]
|
10
|
+
spec.email = ["melnikaite.melnikaite@gmail.com"]
|
11
|
+
spec.summary = "Creates aliases for existing capybara methods."
|
12
|
+
spec.description = "Make it possible to use most popular capybara methods in watir tests."
|
13
|
+
spec.homepage = "https://github.com/melnikaite/watir-capybara-helpers"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "byebug"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "watir-webdriver"
|
26
|
+
spec.add_runtime_dependency "launchy"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir-capybara-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugene Melnikov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: watir-webdriver
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: launchy
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Make it possible to use most popular capybara methods in watir tests.
|
84
|
+
email:
|
85
|
+
- melnikaite.melnikaite@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".ruby-gemset"
|
92
|
+
- ".ruby-version"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/watir-capybara-helpers.rb
|
98
|
+
- lib/watir-capybara-helpers/browser.rb
|
99
|
+
- lib/watir-capybara-helpers/container.rb
|
100
|
+
- lib/watir-capybara-helpers/element.rb
|
101
|
+
- lib/watir-capybara-helpers/exception.rb
|
102
|
+
- lib/watir-capybara-helpers/version.rb
|
103
|
+
- watir-capybara-helpers.gemspec
|
104
|
+
homepage: https://github.com/melnikaite/watir-capybara-helpers
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Creates aliases for existing capybara methods.
|
128
|
+
test_files: []
|