crabfarm 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crabfarm/dsl/surfer.rb +1 -1
- data/lib/crabfarm/dsl/surfer/search_context.rb +59 -47
- data/lib/crabfarm/dsl/surfer/surf_context.rb +9 -9
- data/lib/crabfarm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 591615890c50a205b34d45a201987d95f4ae3fae
|
4
|
+
data.tar.gz: f67f0538057b4708da26bd00a52ef4bcfaa7bd34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee2b73e89eef91889cdeb754dfe527fcbae9e4f2491e1d3c71169d5bcee7e2f0e42c1797a2299a756af24c87a74756f85c298354e009622395a0d218e83f5212
|
7
|
+
data.tar.gz: 4a0aee39da4bb582b025d417da92a57ba9269f1f5baf287c121369106494e4248cd761a121f662ea09bbe0acaa38d000a37d2e4049bcffed05f871cb1cc6a662
|
data/lib/crabfarm/dsl/surfer.rb
CHANGED
@@ -11,7 +11,7 @@ module Crabfarm
|
|
11
11
|
def initialize(_message, _ctx)
|
12
12
|
super _message
|
13
13
|
@ctx = _ctx
|
14
|
-
@source = _ctx.
|
14
|
+
@source = _ctx.root.page_source rescue nil # cache page source for future reference
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -7,33 +7,48 @@ module Crabfarm
|
|
7
7
|
|
8
8
|
TIMEOUT = 10.0 # Default timeout for waiting operations
|
9
9
|
|
10
|
+
attr_accessor :elements, :parent
|
11
|
+
|
12
|
+
def_delegators :elements, :length, :count, :empty?
|
13
|
+
|
10
14
|
def initialize(_elements, _parent)
|
11
15
|
@elements = _elements
|
12
16
|
@parent = _parent
|
13
17
|
end
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
return @parent.root_context if @parent
|
18
|
-
self
|
19
|
+
def root
|
20
|
+
@parent.root
|
19
21
|
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
@parent
|
23
|
+
def each
|
24
|
+
elements.each { |el| yield child_context [el] }
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
return enum_for(__method__) if _block.nil?
|
32
|
-
context.each do |el|
|
33
|
-
_block.call SearchContext.new([el], self)
|
27
|
+
def [](*args)
|
28
|
+
if args[0].is_a? String or args[0].is_a? Symbol
|
29
|
+
attribute args[0]
|
30
|
+
else
|
31
|
+
child_context Array(elements.send(:[],*args))
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
35
|
+
def first
|
36
|
+
if elements.first.nil? then nil else child_context [elements.first] end
|
37
|
+
end
|
38
|
+
|
39
|
+
def last
|
40
|
+
if elements.last.nil? then nil else child_context [elements.last] end
|
41
|
+
end
|
42
|
+
|
43
|
+
def element!
|
44
|
+
raise EmptySetError.new("This set is empty", self) if empty?
|
45
|
+
elements.first
|
46
|
+
end
|
47
|
+
|
48
|
+
def classes
|
49
|
+
wrap_errors { (element!['class'] || '').split(' ') }
|
50
|
+
end
|
51
|
+
|
37
52
|
# searches for elements that match a given selector
|
38
53
|
def search(_selector=nil, _options={})
|
39
54
|
_options[:css] = _selector if _selector
|
@@ -46,34 +61,35 @@ module Crabfarm
|
|
46
61
|
timeout = TIMEOUT if timeout.nil?
|
47
62
|
|
48
63
|
# use a selenium timeout
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
wrap_errors do
|
65
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
66
|
+
wait.until do
|
67
|
+
new_elements = search_elements _options
|
68
|
+
|
69
|
+
# test wait condition
|
70
|
+
ok = case wait_mode
|
71
|
+
when :present then (new_elements.length > 0)
|
72
|
+
when :visible then (new_elements.length > 0 and new_elements.first.displayed?)
|
73
|
+
when :enabled then (new_elements.length > 0 and new_elements.first.displayed? and new_elements.first.enabled?)
|
74
|
+
when :not_present then (new_elements.length == 0)
|
75
|
+
when :not_visible then (not new_elements.any? { |e| e.displayed? })
|
76
|
+
else
|
77
|
+
raise SetupError.new "Invalid wait mode '#{wait_mode}'"
|
78
|
+
end
|
79
|
+
|
80
|
+
child_context new_elements if ok
|
62
81
|
end
|
63
|
-
|
64
|
-
SearchContext.new new_elements, self if ok
|
65
82
|
end
|
66
83
|
else
|
67
|
-
|
84
|
+
child_context search_elements(_options)
|
68
85
|
end
|
69
86
|
end
|
70
87
|
|
71
88
|
# clears and sends_keys to this context main element
|
72
89
|
def fill(_value)
|
73
|
-
raise EmptySetError.new('Cannot call \'fill\' on an empty set', self) if empty?
|
74
90
|
wrap_errors do
|
75
|
-
|
76
|
-
|
91
|
+
element!.clear
|
92
|
+
element!.send_keys _value
|
77
93
|
end
|
78
94
|
end
|
79
95
|
|
@@ -83,10 +99,9 @@ module Crabfarm
|
|
83
99
|
m = /^(.*)_all$/.match _method.to_s
|
84
100
|
if m then
|
85
101
|
return [] if empty?
|
86
|
-
|
102
|
+
elements.map { |e| e.send(m[1], *_args, &_block) }
|
87
103
|
else
|
88
|
-
|
89
|
-
context.first.send(_method, *_args, &_block)
|
104
|
+
element!.send(_method, *_args, &_block)
|
90
105
|
end
|
91
106
|
end
|
92
107
|
end
|
@@ -96,16 +111,19 @@ module Crabfarm
|
|
96
111
|
m = /^.*_all$/.match _method.to_s
|
97
112
|
if m then
|
98
113
|
return true if empty?
|
99
|
-
|
114
|
+
elements.first.respond_to? m[1], _include_all
|
100
115
|
else
|
101
116
|
return true if empty?
|
102
|
-
|
117
|
+
elements.first.respond_to? _method, _include_all
|
103
118
|
end
|
104
119
|
end
|
105
120
|
|
106
121
|
private
|
107
122
|
|
108
|
-
|
123
|
+
def child_context(_elements)
|
124
|
+
SearchContext.new _elements, self
|
125
|
+
end
|
126
|
+
|
109
127
|
def wrap_errors
|
110
128
|
begin
|
111
129
|
yield
|
@@ -114,20 +132,14 @@ module Crabfarm
|
|
114
132
|
end
|
115
133
|
end
|
116
134
|
|
117
|
-
# base filtering method, expands current context
|
118
135
|
def search_elements(_options)
|
119
136
|
wrap_errors do
|
120
|
-
|
137
|
+
elements.inject([]) do |r, element|
|
121
138
|
r + element.find_elements(_options)
|
122
139
|
end
|
123
140
|
end
|
124
141
|
end
|
125
142
|
|
126
|
-
# returns the current context
|
127
|
-
def context
|
128
|
-
@elements
|
129
|
-
end
|
130
|
-
|
131
143
|
end
|
132
144
|
end
|
133
145
|
end
|
@@ -2,16 +2,23 @@ module Crabfarm
|
|
2
2
|
module Dsl
|
3
3
|
module Surfer
|
4
4
|
class SurfContext < SearchContext
|
5
|
-
extend Forwardable
|
6
5
|
|
7
6
|
def_delegators :@bucket, :parse, :setup
|
8
7
|
def_delegators 'driver.navigate', :back, :forward, :refresh
|
9
8
|
|
10
9
|
def initialize(_bucket)
|
11
|
-
super nil,
|
10
|
+
super nil, self
|
12
11
|
@bucket = _bucket
|
13
12
|
end
|
14
13
|
|
14
|
+
def root
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def elements
|
19
|
+
[driver]
|
20
|
+
end
|
21
|
+
|
15
22
|
def driver
|
16
23
|
@bucket.original
|
17
24
|
end
|
@@ -45,13 +52,6 @@ module Crabfarm
|
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def context
|
52
|
-
[driver]
|
53
|
-
end
|
54
|
-
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
data/lib/crabfarm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crabfarm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Baixas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jbuilder
|