watigiri 0.1.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: 88ad103bcf8deb0b774e803ba687e340e8ee5373
4
+ data.tar.gz: 3b29a90e092b817df788048b3f03a5acb2542848
5
+ SHA512:
6
+ metadata.gz: 621425770d2df585d453c8aaa1874d81c21e003ed580ab9861118cc48f04a7e66c6ef4474a070cdb1af9753468d6e0772990e067fac3b7d6b03ba8037339b0db
7
+ data.tar.gz: 507d3b8fd60b950ee55a635e8adc7f2a3fd709bd94c6539ba0287c3677a187578115786104dfadee604f2ef0e963dc0380f499d64cbdda43a6a5e2fcdccc3fe6
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in watigiri.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 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,39 @@
1
+ # Watigiri
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/watigiri`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'watigiri'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install watigiri
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/watigiri.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ module Watir
2
+
3
+ class Browser
4
+ attr_reader :doc
5
+
6
+ #
7
+ # Store instance of Nokogiri
8
+ #
9
+
10
+ def doc=(html)
11
+ @doc = html
12
+
13
+ return if @doc.nil?
14
+ reset_doc = ->(browser) { browser.doc = nil }
15
+ after_hooks.add(reset_doc)
16
+ end
17
+
18
+ #
19
+ # Uses Nokogiri to return the text of page body.
20
+ #
21
+ # @return [String]
22
+ #
23
+
24
+ def text!
25
+ body.text!
26
+ end
27
+
28
+ end # Browser
29
+ end # Watir
@@ -0,0 +1,19 @@
1
+ module Watir
2
+
3
+ class Element
4
+
5
+ # TODO - reimplement with Watir Executor when available
6
+
7
+ #
8
+ # Uses Nokogiri to return the text of the element.
9
+ #
10
+ # @return [String]
11
+ #
12
+
13
+ def text!
14
+ @selector[:nokogiri] = true
15
+ text
16
+ end
17
+
18
+ end # Element
19
+ end # Watir
@@ -0,0 +1,25 @@
1
+ module Watir
2
+ class IFrame < HTMLElement
3
+ #
4
+ # Uses Nokogiri to return the text of iframe body.
5
+ #
6
+ # @return [String]
7
+ #
8
+
9
+ def text!
10
+ body.text!
11
+ end
12
+ end
13
+
14
+ class FramedDriver
15
+
16
+ private
17
+
18
+ def switch!
19
+ @browser.doc = nil
20
+ super
21
+ end
22
+
23
+ end # FramedDriver
24
+
25
+ end # Watir
data/lib/watigiri.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'watir'
2
+ require 'nokogiri'
3
+
4
+ require 'extensions/watir/browser'
5
+ require 'extensions/watir/element'
6
+ require 'extensions/watir/iframe'
7
+
8
+ require 'watigiri/locators/element/locator'
9
+ require 'watigiri/locators/element/selector_builder'
10
+ require 'watigiri/locators/element/validator'
11
+
12
+ Watir.locator_namespace = Watigiri::Locators
@@ -0,0 +1,129 @@
1
+ module Watigiri
2
+ module Locators
3
+ class Element
4
+ class Locator < Watir::Locators::Element::Locator
5
+
6
+ def locate
7
+ @nokogiri = @selector.delete(:nokogiri)
8
+
9
+ return super unless @nokogiri
10
+ @query_scope.browser.doc ||= Nokogiri::HTML(@query_scope.html).tap {|d| d.css('script').remove }
11
+
12
+ reset_doc = ->(browser) { browser.doc = nil }
13
+ @query_scope.browser.after_hooks.add(reset_doc)
14
+
15
+ find_first_by_multiple
16
+ end
17
+
18
+ def locate_element(how, what)
19
+ unless @nokogiri
20
+ return ensure_scope_context.find_element(how, what)
21
+ end
22
+ case how
23
+ when :css
24
+ @query_scope.browser.doc.at_css(what)
25
+ when :xpath
26
+ @query_scope.browser.doc.at_xpath(what)
27
+ end
28
+ end
29
+
30
+ def locate_elements(how, what, _scope = nil)
31
+ unless @nokogiri
32
+ return ensure_scope_context.find_elements(how, what)
33
+ end
34
+ case how
35
+ when :css
36
+ @query_scope.browser.doc.css(what).to_a
37
+ when :xpath
38
+ @query_scope.browser.doc.xpath(what).to_a
39
+ end
40
+ end
41
+
42
+ def fetch_value(element, how)
43
+ return super unless @nokogiri
44
+ case how
45
+ when :text
46
+ element.inner_text
47
+ when :tag_name
48
+ element.name.to_s.downcase
49
+ when :href
50
+ (href = element.attribute('href')) && href.to_s.strip
51
+ else
52
+ element.attribute(how.to_s.tr("_", "-")).to_s
53
+ end
54
+ end
55
+
56
+ # TODO remove after https://github.com/watir/watir/pull/630
57
+ def find_first_by_multiple
58
+ selector = selector_builder.normalized_selector
59
+
60
+ idx = selector.delete(:index) unless selector[:adjacent]
61
+ visible = selector.delete(:visible)
62
+
63
+ how, what = selector_builder.build(selector)
64
+
65
+ if how
66
+ # could build xpath/css for selector
67
+ if idx || !visible.nil?
68
+ idx ||= 0
69
+ elements = locate_elements(how, what)
70
+ elements = elements.select { |el| visible == el.displayed? } unless visible.nil?
71
+ elements[idx] unless elements.nil?
72
+ else
73
+ locate_element(how, what)
74
+ end
75
+ else
76
+ # can't use xpath, probably a regexp in there
77
+ if idx || !visible.nil?
78
+ idx ||= 0
79
+ elements = wd_find_by_regexp_selector(selector, :select)
80
+ elements = elements.select { |el| visible == el.displayed? } unless visible.nil?
81
+ elements[idx] unless elements.nil?
82
+ else
83
+ wd_find_by_regexp_selector(selector, :find)
84
+ end
85
+ end
86
+ end
87
+
88
+ # TODO Remove after https://github.com/watir/watir/pull/630
89
+ def wd_find_by_regexp_selector(selector, method = :find)
90
+ query_scope = ensure_scope_context
91
+ rx_selector = delete_regexps_from(selector)
92
+
93
+ if rx_selector.key?(:label) && selector_builder.should_use_label_element?
94
+ label = label_from_text(rx_selector.delete(:label)) || return
95
+ if (id = label.attribute(:for))
96
+ selector[:id] = id
97
+ else
98
+ query_scope = label
99
+ end
100
+ end
101
+
102
+ how, what = selector_builder.build(selector)
103
+
104
+ unless how
105
+ raise Error, "internal error: unable to build Selenium selector from #{selector.inspect}"
106
+ end
107
+
108
+ if how == :xpath && can_convert_regexp_to_contains?
109
+ rx_selector.each do |key, value|
110
+ next if key == :tag_name || key == :text
111
+
112
+ predicates = regexp_selector_to_predicates(key, value)
113
+ what = "(#{what})[#{predicates.join(' and ')}]" unless predicates.empty?
114
+ end
115
+ end
116
+
117
+ elements = locate_elements(how, what, query_scope)
118
+ elements.__send__(method) { |el| matches_selector?(el, rx_selector) }
119
+ end
120
+
121
+ # TODO Remove after https://github.com/watir/watir/pull/630
122
+ def ensure_scope_context
123
+ @query_scope.wd
124
+ end
125
+
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,15 @@
1
+ module Watigiri
2
+ module Locators
3
+ class Element
4
+ class SelectorBuilder < Watir::Locators::Element::SelectorBuilder
5
+
6
+ def initialize(query_scope, selector, attribute_list)
7
+ attribute_list << :nokogiri
8
+ super
9
+ @selector.delete :nokogiri
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ module Watigiri
2
+ module Locators
3
+ class Element
4
+ class Validator < Watir::Locators::Element::Validator
5
+ end
6
+ end
7
+ end
8
+ end
data/watigiri.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "watigiri"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Titus Fortner"]
9
+ spec.email = ["titusfortner@gmail.com"]
10
+
11
+ spec.summary = %q{Nokogiri locator engine for Watir}
12
+ spec.description = <<-DESCRIPTION_MESSAGE
13
+ By default Watir locates elements with Selenium; this gem will replace Selenium calls
14
+ with Nokogiri calls where designated.
15
+ DESCRIPTION_MESSAGE
16
+ spec.homepage = "http://github.com/titusfortner/watigiri"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
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_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "webdrivers", "~> 2.0"
30
+
31
+ spec.add_runtime_dependency "watir"
32
+ spec.add_runtime_dependency "nokogiri"
33
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watigiri
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: 2017-08-21 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webdrivers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: watir
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
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |
98
+ By default Watir locates elements with Selenium; this gem will replace Selenium calls
99
+ with Nokogiri calls where designated.
100
+ email:
101
+ - titusfortner@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/extensions/watir/browser.rb
114
+ - lib/extensions/watir/element.rb
115
+ - lib/extensions/watir/iframe.rb
116
+ - lib/watigiri.rb
117
+ - lib/watigiri/locators/element/locator.rb
118
+ - lib/watigiri/locators/element/selector_builder.rb
119
+ - lib/watigiri/locators/element/validator.rb
120
+ - watigiri.gemspec
121
+ homepage: http://github.com/titusfortner/watigiri
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.11
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Nokogiri locator engine for Watir
145
+ test_files: []