watir_pump 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/watir_pump/component.rb +98 -11
- data/lib/watir_pump/component_collection.rb +23 -0
- data/lib/watir_pump/page.rb +60 -6
- data/lib/watir_pump.rb +2 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cbb8887dcba5251fc46c03f1df81c4d860a804f
|
4
|
+
data.tar.gz: 3ba5eaef6712ccad5a413f4848447476f3fda28f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bbc87cfee1e802483f7808384510cb9b8d52b62f0b86bfea1beb2bc625e98f3fa1de46da49c28e5e0701c315a0d24f0c8ec51c1b38d0a161a9a080e298ab5b4
|
7
|
+
data.tar.gz: 05d9534cfe798b3834db12bbc8140195e301b22a9877999551bcc703343ebb4dfcebafd30db2f9923234b661a433ed57d6484e0c2ee131182de357430a885e1d
|
data/lib/watir_pump/component.rb
CHANGED
@@ -1,31 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'component_collection'
|
4
|
+
require 'forwardable'
|
5
|
+
|
1
6
|
module WatirPump
|
2
7
|
class Component
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
delegate %i[visible? present?] => :root
|
11
|
+
|
3
12
|
attr_reader :browser
|
4
13
|
attr_reader :parent
|
5
14
|
|
6
15
|
class << self
|
7
|
-
|
8
|
-
|
16
|
+
# Proxy methods for HTML tags
|
17
|
+
Watir::Container.instance_methods(false).each do |watir_method|
|
18
|
+
define_method watir_method do |name, *args|
|
19
|
+
define_method(name) do |*loc_args|
|
20
|
+
if args&.first.is_a? Proc
|
21
|
+
instance_exec(*loc_args, &args.first)
|
22
|
+
else
|
23
|
+
root.send(watir_method, *args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Methods for element content readers
|
30
|
+
# span_reader, :title, id: asd
|
31
|
+
# will create methods :title and :title_element
|
32
|
+
# where :title is a shortcut for :title_element.text
|
33
|
+
%i[span div].each do |watir_method|
|
34
|
+
define_method "#{watir_method}_reader" do |name, *args|
|
35
|
+
send(watir_method, "#{name}_element", *args)
|
9
36
|
define_method(name) do
|
10
|
-
|
37
|
+
send("#{name}_element").text
|
11
38
|
end
|
12
39
|
end
|
13
40
|
end
|
14
41
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
42
|
+
# Methods for element content writers
|
43
|
+
%i[text_field].each do |watir_method|
|
44
|
+
define_method "#{watir_method}_writer" do |name, *args|
|
45
|
+
send(watir_method, "#{name}_element", *args)
|
46
|
+
define_method("#{name}=") do |value|
|
47
|
+
send("#{name}_element").set value
|
48
|
+
end
|
19
49
|
end
|
20
50
|
end
|
21
51
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
52
|
+
# Methods for element clickers
|
53
|
+
%i[button link].each do |watir_method|
|
54
|
+
define_method "#{watir_method}_clicker" do |name, *args|
|
55
|
+
send(watir_method, "#{name}_element", *args)
|
56
|
+
define_method(name) do
|
57
|
+
send("#{name}_element").click
|
26
58
|
end
|
27
59
|
end
|
28
60
|
end
|
61
|
+
|
62
|
+
def query(name, p)
|
63
|
+
define_method(name) do |*args|
|
64
|
+
instance_exec(*args, &p)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def region(name, loc_method = nil, *loc_args, &blk)
|
69
|
+
klass = Class.new(Component) { instance_exec(&blk) }
|
70
|
+
component(name, klass, loc_method, *loc_args)
|
71
|
+
end
|
72
|
+
|
73
|
+
def component(name, klass, loc_method = nil, *loc_args)
|
74
|
+
define_method(name) do |*args|
|
75
|
+
node = if loc_method.is_a? Proc
|
76
|
+
instance_exec(*args, &loc_method)
|
77
|
+
else
|
78
|
+
loc_method.nil? ? root : root.send(loc_method, *loc_args)
|
79
|
+
end
|
80
|
+
klass.new(browser, self, node)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def components(name, klass, loc_method = nil, *loc_args)
|
85
|
+
define_method(name) do |*args|
|
86
|
+
nodes = if loc_method.is_a? Proc
|
87
|
+
instance_exec(*args, &loc_method)
|
88
|
+
else
|
89
|
+
root.send(loc_method, *loc_args)
|
90
|
+
end
|
91
|
+
ComponentCollection.new(nodes.map { |n| klass.new(browser, self, n) })
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def decorate(method, klass)
|
96
|
+
alias_method "#{method}_original".to_sym, method
|
97
|
+
define_method method do |*args|
|
98
|
+
klass.new(send("#{method}_original", *args))
|
99
|
+
end
|
100
|
+
end
|
29
101
|
end
|
30
102
|
|
31
103
|
def initialize(browser, parent = nil, root_node = nil)
|
@@ -40,5 +112,20 @@ module WatirPump
|
|
40
112
|
ret = parent.root
|
41
113
|
ret.class.name.include?('Collection') ? ret.first : ret
|
42
114
|
end
|
115
|
+
alias node root
|
116
|
+
|
117
|
+
def method_missing(name, *args)
|
118
|
+
# delegate missing methods to current RSpec example if set
|
119
|
+
example = WatirPump.config.current_example
|
120
|
+
if example&.instance_exec { respond_to? name }
|
121
|
+
return example.instance_exec { send(name, *args) }
|
122
|
+
end
|
123
|
+
super
|
124
|
+
end
|
125
|
+
|
126
|
+
def respond_to_missing?(name, include_private = false)
|
127
|
+
example = WatirPump.config.current_example
|
128
|
+
example&.instance_exec { respond_to? name } || super
|
129
|
+
end
|
43
130
|
end
|
44
131
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module WatirPump
|
6
|
+
class ComponentCollection
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
delegate Enumerable.instance_methods(false) => :@arr
|
10
|
+
delegate %i[[] empty? each] => :@arr
|
11
|
+
|
12
|
+
def initialize(arr)
|
13
|
+
@arr = arr
|
14
|
+
end
|
15
|
+
|
16
|
+
%i[present? visible?].each do |method_name|
|
17
|
+
define_method method_name do
|
18
|
+
return false if empty?
|
19
|
+
find { |component| component.node.send(method_name) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/watir_pump/page.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'addressable/template'
|
2
4
|
require_relative 'component'
|
3
5
|
|
@@ -10,26 +12,78 @@ module WatirPump
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def open(params = {}, &blk)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
instance.open(params, &blk)
|
16
|
+
end
|
17
|
+
|
18
|
+
def open_yield(params = {}, &blk)
|
19
|
+
instance.open_yield(params, &blk)
|
17
20
|
end
|
18
21
|
|
19
22
|
def browser
|
20
23
|
instance.browser
|
21
24
|
end
|
22
25
|
|
23
|
-
def use
|
24
|
-
|
26
|
+
def use(&blk)
|
27
|
+
instance.use(&blk)
|
25
28
|
end
|
26
29
|
alias act use
|
27
30
|
|
31
|
+
def use_yield(&blk)
|
32
|
+
instance.use_yield(&blk)
|
33
|
+
end
|
34
|
+
alias act_yield use_yield
|
35
|
+
|
36
|
+
def loaded?
|
37
|
+
Addressable::Template.new(instance.url_template).match browser.url
|
38
|
+
end
|
39
|
+
|
28
40
|
def instance
|
29
41
|
@instance ||= new(WatirPump.config.browser)
|
30
42
|
end
|
31
43
|
end # << self
|
32
44
|
|
45
|
+
def open_yield(params = {}, &blk)
|
46
|
+
url = Addressable::Template.new(url_template).expand(params).to_s
|
47
|
+
browser.goto url
|
48
|
+
use_yield(&blk) if block_given?
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def open(params = {}, &blk)
|
53
|
+
url = Addressable::Template.new(url_template).expand(params).to_s
|
54
|
+
browser.goto url
|
55
|
+
use(&blk) if block_given?
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def use_yield
|
60
|
+
wait_for_loaded
|
61
|
+
yield self, browser
|
62
|
+
self
|
63
|
+
end
|
64
|
+
alias act_yield use_yield
|
65
|
+
|
66
|
+
def use(&blk)
|
67
|
+
wait_for_loaded
|
68
|
+
instance_exec(&blk)
|
69
|
+
self
|
70
|
+
end
|
71
|
+
alias act use
|
72
|
+
|
73
|
+
def url_template
|
74
|
+
WatirPump.config.base_url + self.class.uri
|
75
|
+
end
|
76
|
+
|
77
|
+
def wait_for_loaded
|
78
|
+
Watir::Wait.until(message: "Timeout waiting for #{self} to load") do
|
79
|
+
loaded?
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def loaded?
|
84
|
+
self.class.loaded?
|
85
|
+
end
|
86
|
+
|
33
87
|
def uri
|
34
88
|
self.class.uri
|
35
89
|
end
|
data/lib/watir_pump.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir_pump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartek Wilczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -116,6 +116,7 @@ extra_rdoc_files: []
|
|
116
116
|
files:
|
117
117
|
- lib/watir_pump.rb
|
118
118
|
- lib/watir_pump/component.rb
|
119
|
+
- lib/watir_pump/component_collection.rb
|
119
120
|
- lib/watir_pump/page.rb
|
120
121
|
homepage: https://github.com/bwilczek/watir_pump
|
121
122
|
licenses:
|
@@ -129,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
130
|
requirements:
|
130
131
|
- - "~>"
|
131
132
|
- !ruby/object:Gem::Version
|
132
|
-
version: '2.
|
133
|
+
version: '2.4'
|
133
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
135
|
requirements:
|
135
136
|
- - ">="
|
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
140
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.6.
|
141
|
+
rubygems_version: 2.6.11
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
144
|
summary: Page Objects for Watir
|