watir_css 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +6 -0
- data/lib/watir_css/locators/element/locator.rb +9 -0
- data/lib/watir_css/locators/element/selector_builder/css.rb +65 -0
- data/lib/watir_css/locators/element/selector_builder.rb +25 -0
- data/lib/watir_css/locators/element/validator.rb +8 -0
- data/lib/watir_css/version.rb +3 -0
- data/lib/watir_css.rb +15 -0
- data/watir_css.gemspec +31 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b6f07dd5e75eeda87032565d7a935dd18dd81f20
|
4
|
+
data.tar.gz: b430308783605df302565a8184735645b7250f28
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea6d64b1471d18104fd43ff246f6244c0439b8ecadf419b1c64b24c37ddc45417ec2f0128a78d0a0ec49f86fe437d7c8fbd51c365824c9cc0d8fd49c178f3fad
|
7
|
+
data.tar.gz: bcadc60e3fc40afb296fe3db22d1aa212fd18883c0f53c6a6f30ea23b00da3f06bf370b4dd7ae554fe9b85b0e0167092bbec59336aa9e3180a33c9c662c91c39
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Titus Fortner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# WatirCss
|
2
|
+
|
3
|
+
CSS-based locator engine for [watir-webdriver](https://github.com/watir/watir-webdriver).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'watir_css'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install watir_css
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Require after watir-webdriver, the rest should just work.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'watir-webdriver'
|
31
|
+
require 'watir_css'
|
32
|
+
```
|
33
|
+
|
34
|
+
## Comparison with default watir-webdriver locator
|
35
|
+
|
36
|
+
By default Watir converts calls into XPath; this gem will replace XPath calls
|
37
|
+
with CSS calls where possible.
|
38
|
+
|
39
|
+
This functionality used to be present directly in watir-webdriver. During
|
40
|
+
the transition to Watir 6.0, a hook was included in the repository to
|
41
|
+
allow for alternate locator strategies.
|
42
|
+
|
43
|
+
This gem replaces:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Watir.prefer_css
|
47
|
+
```
|
48
|
+
|
49
|
+
## Limitations
|
50
|
+
|
51
|
+
Some watir-webdriver locators cannot be reimplemented with watir_css. In such cases,
|
52
|
+
it fall backs to watir-webdriver, so you should be able to migrate pretty easily.
|
53
|
+
|
54
|
+
## Development
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
57
|
+
To release a new version, update the version number in `version.rb`,
|
58
|
+
and then run `bundle exec rake release`, which will create a git tag for the version,
|
59
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
|
+
|
61
|
+
## Specs
|
62
|
+
|
63
|
+
Watir_css uses [watirspec](https://github.com/watir/watirspec) for testing, so
|
64
|
+
you should first fetch it:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
$ git submodule init && git submodule update
|
68
|
+
```
|
69
|
+
|
70
|
+
Now, you can run all specs:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
$ bundle exec rake spec
|
74
|
+
```
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/watir/watir_css.
|
79
|
+
This project is intended to be a safe, welcoming space for collaboration,
|
80
|
+
and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module WatirCss
|
2
|
+
module Locators
|
3
|
+
class Element
|
4
|
+
class SelectorBuilder
|
5
|
+
class CSS
|
6
|
+
|
7
|
+
def build(selectors)
|
8
|
+
return unless use_css?(selectors)
|
9
|
+
|
10
|
+
if selectors.empty?
|
11
|
+
css = '*'
|
12
|
+
else
|
13
|
+
css = ''
|
14
|
+
css << (selectors.delete(:tag_name) || '')
|
15
|
+
|
16
|
+
klass = selectors.delete(:class)
|
17
|
+
if klass
|
18
|
+
if klass.include? ' '
|
19
|
+
css << %([class="#{css_escape klass}"])
|
20
|
+
else
|
21
|
+
css << ".#{klass}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
href = selectors.delete(:href)
|
26
|
+
if href
|
27
|
+
css << %([href~="#{css_escape href}"])
|
28
|
+
end
|
29
|
+
|
30
|
+
selectors.each do |key, value|
|
31
|
+
key = key.to_s.tr("_", "-")
|
32
|
+
css << %([#{key}="#{css_escape value}"]) # TODO: proper escaping
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
[:css, css]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def use_css?(selectors)
|
42
|
+
if selectors.key?(:text) || selectors.key?(:label) || selectors.key?(:index)
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
|
46
|
+
if selectors[:tag_name] == 'input' && selectors.key?(:type)
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
if selectors.key?(:class) && selectors[:class] !~ /^[\w-]+$/ui
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
def css_escape(str)
|
58
|
+
str.gsub('"', '\\"')
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module WatirCss
|
2
|
+
module Locators
|
3
|
+
class Element
|
4
|
+
class SelectorBuilder < Watir::Locators::Element::SelectorBuilder
|
5
|
+
|
6
|
+
def css_builder
|
7
|
+
@css_builder ||= CSS.new
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def build_wd_selector(selectors)
|
13
|
+
unless selectors.values.any? { |e| e.is_a? Regexp }
|
14
|
+
build_css(selectors) || build_xpath(selectors)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_css(selectors)
|
19
|
+
css_builder.build(selectors)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/watir_css.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'watir'
|
2
|
+
|
3
|
+
require 'watir_css/locators/element/locator'
|
4
|
+
require 'watir_css/locators/element/selector_builder'
|
5
|
+
require 'watir_css/locators/element/selector_builder/css'
|
6
|
+
require 'watir_css/locators/element/validator'
|
7
|
+
require 'watir_css/version'
|
8
|
+
|
9
|
+
Watir.locator_namespace = WatirCss::Locators
|
10
|
+
|
11
|
+
WatirCss::Locators::Button = Watir::Locators::Button
|
12
|
+
WatirCss::Locators::Cell = Watir::Locators::Cell
|
13
|
+
WatirCss::Locators::Row = Watir::Locators::Row
|
14
|
+
WatirCss::Locators::TextArea = Watir::Locators::TextArea
|
15
|
+
WatirCss::Locators::TextField = Watir::Locators::TextField
|
data/watir_css.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'watir_css/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "watir_css"
|
8
|
+
spec.version = WatirCss::VERSION
|
9
|
+
spec.authors = ["Titus Fortner"]
|
10
|
+
spec.email = ["titusfortner@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{CSS locator engine for Watir}
|
13
|
+
spec.description = <<-DESCRIPTION_MESSAGE
|
14
|
+
By default Watir converts calls into XPath; this gem will replace XPath calls
|
15
|
+
with CSS calls where possible.
|
16
|
+
DESCRIPTION_MESSAGE
|
17
|
+
|
18
|
+
spec.homepage = "https://github.com/watir/watir_css"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency 'watir', '>= 6.0.0.beta2'
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency 'sinatra' # watirspec
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir_css
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Titus Fortner
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: watir
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0.beta2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0.beta2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: |
|
84
|
+
By default Watir converts calls into XPath; this gem will replace XPath calls
|
85
|
+
with CSS calls where possible.
|
86
|
+
email:
|
87
|
+
- titusfortner@gmail.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".gitmodules"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- lib/watir_css.rb
|
101
|
+
- lib/watir_css/locators/element/locator.rb
|
102
|
+
- lib/watir_css/locators/element/selector_builder.rb
|
103
|
+
- lib/watir_css/locators/element/selector_builder/css.rb
|
104
|
+
- lib/watir_css/locators/element/validator.rb
|
105
|
+
- lib/watir_css/version.rb
|
106
|
+
- watir_css.gemspec
|
107
|
+
homepage: https://github.com/watir/watir_css
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.4.5.1
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: CSS locator engine for Watir
|
131
|
+
test_files: []
|