watir-nokogiri 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +65 -0
- data/lib/watir-nokogiri.rb +69 -0
- data/lib/watir-nokogiri/aliases.rb +6 -0
- data/lib/watir-nokogiri/attribute_helper.rb +145 -0
- data/lib/watir-nokogiri/cell_container.rb +31 -0
- data/lib/watir-nokogiri/container.rb +50 -0
- data/lib/watir-nokogiri/document.rb +171 -0
- data/lib/watir-nokogiri/element_collection.rb +93 -0
- data/lib/watir-nokogiri/elements/button.rb +71 -0
- data/lib/watir-nokogiri/elements/checkbox.rb +61 -0
- data/lib/watir-nokogiri/elements/dlist.rb +12 -0
- data/lib/watir-nokogiri/elements/element.rb +319 -0
- data/lib/watir-nokogiri/elements/file_field.rb +45 -0
- data/lib/watir-nokogiri/elements/font.rb +11 -0
- data/lib/watir-nokogiri/elements/form.rb +17 -0
- data/lib/watir-nokogiri/elements/frame.rb +75 -0
- data/lib/watir-nokogiri/elements/generated.rb +2662 -0
- data/lib/watir-nokogiri/elements/hidden.rb +24 -0
- data/lib/watir-nokogiri/elements/image.rb +59 -0
- data/lib/watir-nokogiri/elements/input.rb +34 -0
- data/lib/watir-nokogiri/elements/link.rb +7 -0
- data/lib/watir-nokogiri/elements/option.rb +83 -0
- data/lib/watir-nokogiri/elements/radio.rb +44 -0
- data/lib/watir-nokogiri/elements/select.rb +126 -0
- data/lib/watir-nokogiri/elements/table.rb +44 -0
- data/lib/watir-nokogiri/elements/table_cell.rb +36 -0
- data/lib/watir-nokogiri/elements/table_row.rb +46 -0
- data/lib/watir-nokogiri/elements/table_section.rb +15 -0
- data/lib/watir-nokogiri/elements/text_area.rb +22 -0
- data/lib/watir-nokogiri/elements/text_field.rb +44 -0
- data/lib/watir-nokogiri/exception.rb +20 -0
- data/lib/watir-nokogiri/locators/button_locator.rb +54 -0
- data/lib/watir-nokogiri/locators/child_cell_locator.rb +24 -0
- data/lib/watir-nokogiri/locators/child_row_locator.rb +29 -0
- data/lib/watir-nokogiri/locators/element_locator.rb +298 -0
- data/lib/watir-nokogiri/locators/text_area_locator.rb +20 -0
- data/lib/watir-nokogiri/locators/text_field_locator.rb +71 -0
- data/lib/watir-nokogiri/row_container.rb +42 -0
- data/lib/watir-nokogiri/user_editable.rb +38 -0
- data/lib/watir-nokogiri/version.rb +3 -0
- data/lib/watir-nokogiri/xpath_support.rb +22 -0
- metadata +102 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
module WatirNokogiri
|
2
|
+
class TextAreaLocator < ElementLocator
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def normalize_selector(how, what)
|
7
|
+
# We need to iterate through located elements and fetch
|
8
|
+
# attribute value using WebDriver because XPath doesn't understand
|
9
|
+
# difference between IDL vs content attribute.
|
10
|
+
# Current ElementLocator design doesn't allow to do that in any
|
11
|
+
# obvious way except to use regular expression.
|
12
|
+
if how == :value && what.kind_of?(String)
|
13
|
+
[how, Regexp.new('^' + Regexp.escape(what) + '$')]
|
14
|
+
else
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end # TextAreaLocator
|
20
|
+
end # WatirNokogiri
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module WatirNokogiri
|
2
|
+
class TextFieldLocator < ElementLocator
|
3
|
+
|
4
|
+
NON_TEXT_TYPES = %w[file radio checkbox submit reset image button hidden datetime date month week time datetime-local range color]
|
5
|
+
# TODO: better way of finding input text fields?
|
6
|
+
NEGATIVE_TYPE_EXPR = NON_TEXT_TYPES.map { |type| "%s!=%s" % [XpathSupport.downcase('@type'), type.inspect] }.join(' and ')
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def build_nokogiri_selector(selectors)
|
11
|
+
return if selectors.values.any? { |e| e.kind_of? Regexp }
|
12
|
+
|
13
|
+
selectors.delete(:tag_name)
|
14
|
+
|
15
|
+
@building = :textarea
|
16
|
+
textarea_attr_exp = attribute_expression(selectors)
|
17
|
+
|
18
|
+
@building = :input
|
19
|
+
input_attr_exp = attribute_expression(selectors)
|
20
|
+
|
21
|
+
xpath = ".//input[(not(@type) or (#{NEGATIVE_TYPE_EXPR}))"
|
22
|
+
xpath << " and #{input_attr_exp}" unless input_attr_exp.empty?
|
23
|
+
xpath << "] "
|
24
|
+
xpath << "| .//textarea"
|
25
|
+
xpath << "[#{textarea_attr_exp}]" unless textarea_attr_exp.empty?
|
26
|
+
|
27
|
+
p :build_nokogiri_selector => xpath if $DEBUG
|
28
|
+
|
29
|
+
[:xpath, xpath]
|
30
|
+
end
|
31
|
+
|
32
|
+
def lhs_for(key)
|
33
|
+
if @building == :input && key == :text
|
34
|
+
"@value"
|
35
|
+
elsif @building == :textarea && key == :value
|
36
|
+
"text()"
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def matches_selector?(element, rx_selector)
|
43
|
+
rx_selector = rx_selector.dup
|
44
|
+
|
45
|
+
tag_name = element.node_name.downcase
|
46
|
+
|
47
|
+
[:text, :value, :label].each do |key|
|
48
|
+
if rx_selector.has_key?(key)
|
49
|
+
correct_key = tag_name == 'input' ? :value : :text
|
50
|
+
rx_selector[correct_key] = rx_selector.delete(key)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
VALID_TEXT_FIELD_TAGS = %w[input textarea]
|
58
|
+
|
59
|
+
def tag_name_matches?(tag_name, _)
|
60
|
+
VALID_TEXT_FIELD_TAGS.include?(tag_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate_element(element)
|
64
|
+
if element.node_name.downcase == 'textarea'
|
65
|
+
warn "Locating textareas with '#text_field' is deprecated. Please, use '#textarea' method instead."
|
66
|
+
end
|
67
|
+
super
|
68
|
+
end
|
69
|
+
|
70
|
+
end # TextFieldLocator
|
71
|
+
end # WatirNokogiri
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module WatirNokogiri
|
2
|
+
module RowContainer
|
3
|
+
|
4
|
+
#
|
5
|
+
# Returns table row.
|
6
|
+
#
|
7
|
+
|
8
|
+
def row(*args)
|
9
|
+
row = tr(*args)
|
10
|
+
row.locator_class = ChildRowLocator
|
11
|
+
|
12
|
+
row
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Returns table rows collection.
|
17
|
+
#
|
18
|
+
|
19
|
+
def rows(*args)
|
20
|
+
rows = trs(*args)
|
21
|
+
rows.locator_class = ChildRowLocator
|
22
|
+
|
23
|
+
rows
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# The table as a 2D Array of strings with the text of each cell.
|
28
|
+
#
|
29
|
+
# @return [Array<Array<String>>]
|
30
|
+
#
|
31
|
+
|
32
|
+
def strings
|
33
|
+
assert_exists
|
34
|
+
|
35
|
+
rows.inject [] do |res, row|
|
36
|
+
res << row.cells.map { |cell| cell.text }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
alias_method :to_a, :strings
|
40
|
+
|
41
|
+
end # RowContainer
|
42
|
+
end # Watir
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module WatirNokogiri
|
2
|
+
module UserEditable
|
3
|
+
|
4
|
+
#
|
5
|
+
# Clear the element, the type in the given value.
|
6
|
+
#
|
7
|
+
# @param [String, Symbol] *args
|
8
|
+
#
|
9
|
+
|
10
|
+
def set(*args)
|
11
|
+
assert_exists
|
12
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
13
|
+
end
|
14
|
+
alias_method :value=, :set
|
15
|
+
|
16
|
+
#
|
17
|
+
# Appends the given value to the text in the text field.
|
18
|
+
#
|
19
|
+
# @param [String, Symbol] *args
|
20
|
+
#
|
21
|
+
|
22
|
+
def append(*args)
|
23
|
+
assert_exists
|
24
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
25
|
+
end
|
26
|
+
alias_method :<<, :append
|
27
|
+
|
28
|
+
#
|
29
|
+
# Clears the text field.
|
30
|
+
#
|
31
|
+
|
32
|
+
def clear
|
33
|
+
assert_exists
|
34
|
+
raise NotImplementedError, "not currently supported by WatirNokogiri"
|
35
|
+
end
|
36
|
+
|
37
|
+
end # UserEditable
|
38
|
+
end # WatirNokogiri
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module WatirNokogiri
|
4
|
+
module XpathSupport
|
5
|
+
|
6
|
+
def self.escape(value)
|
7
|
+
if value.include? "'"
|
8
|
+
parts = value.split("'", -1).map { |part| "'#{part}'" }
|
9
|
+
string = parts.join(%{,"'",})
|
10
|
+
|
11
|
+
"concat(#{string})"
|
12
|
+
else
|
13
|
+
"'#{value}'"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.downcase(value)
|
18
|
+
"translate(#{value},'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"
|
19
|
+
end
|
20
|
+
|
21
|
+
end # XpathSupport
|
22
|
+
end # WatirNokogiri
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir-nokogiri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Justin Ko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Watir-Nokogiri is an HTML parser using Watir's API.
|
31
|
+
email: jkotest@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/watir-nokogiri/aliases.rb
|
37
|
+
- lib/watir-nokogiri/attribute_helper.rb
|
38
|
+
- lib/watir-nokogiri/cell_container.rb
|
39
|
+
- lib/watir-nokogiri/container.rb
|
40
|
+
- lib/watir-nokogiri/document.rb
|
41
|
+
- lib/watir-nokogiri/elements/button.rb
|
42
|
+
- lib/watir-nokogiri/elements/checkbox.rb
|
43
|
+
- lib/watir-nokogiri/elements/dlist.rb
|
44
|
+
- lib/watir-nokogiri/elements/element.rb
|
45
|
+
- lib/watir-nokogiri/elements/file_field.rb
|
46
|
+
- lib/watir-nokogiri/elements/font.rb
|
47
|
+
- lib/watir-nokogiri/elements/form.rb
|
48
|
+
- lib/watir-nokogiri/elements/frame.rb
|
49
|
+
- lib/watir-nokogiri/elements/generated.rb
|
50
|
+
- lib/watir-nokogiri/elements/hidden.rb
|
51
|
+
- lib/watir-nokogiri/elements/image.rb
|
52
|
+
- lib/watir-nokogiri/elements/input.rb
|
53
|
+
- lib/watir-nokogiri/elements/link.rb
|
54
|
+
- lib/watir-nokogiri/elements/option.rb
|
55
|
+
- lib/watir-nokogiri/elements/radio.rb
|
56
|
+
- lib/watir-nokogiri/elements/select.rb
|
57
|
+
- lib/watir-nokogiri/elements/table.rb
|
58
|
+
- lib/watir-nokogiri/elements/table_cell.rb
|
59
|
+
- lib/watir-nokogiri/elements/table_row.rb
|
60
|
+
- lib/watir-nokogiri/elements/table_section.rb
|
61
|
+
- lib/watir-nokogiri/elements/text_area.rb
|
62
|
+
- lib/watir-nokogiri/elements/text_field.rb
|
63
|
+
- lib/watir-nokogiri/element_collection.rb
|
64
|
+
- lib/watir-nokogiri/exception.rb
|
65
|
+
- lib/watir-nokogiri/locators/button_locator.rb
|
66
|
+
- lib/watir-nokogiri/locators/child_cell_locator.rb
|
67
|
+
- lib/watir-nokogiri/locators/child_row_locator.rb
|
68
|
+
- lib/watir-nokogiri/locators/element_locator.rb
|
69
|
+
- lib/watir-nokogiri/locators/text_area_locator.rb
|
70
|
+
- lib/watir-nokogiri/locators/text_field_locator.rb
|
71
|
+
- lib/watir-nokogiri/row_container.rb
|
72
|
+
- lib/watir-nokogiri/user_editable.rb
|
73
|
+
- lib/watir-nokogiri/version.rb
|
74
|
+
- lib/watir-nokogiri/xpath_support.rb
|
75
|
+
- lib/watir-nokogiri.rb
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
homepage: https://github.com/jkotests/watir-nokogiri
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.24
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Watir HTML parser
|
102
|
+
test_files: []
|