ferrumwizard 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ferrumwizard.rb +75 -11
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5eb39e3f7b96b87809950695d7987529b5d2abd7fe8a445e5e658453694d3c4
|
4
|
+
data.tar.gz: ab1de29c5cb1c2c9a904069e0a6ef6d8bf8cbdadd68eba2ad1992945c4189948
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 511884c66a570b8fe74ab14109f3f731316a74824869b73a46cf26bff6b7fbc4f63a92848790229a95aa753b91ff3ada227ebdfa6ed19fe40641da812597d394
|
7
|
+
data.tar.gz: 166d533864edff9c4b3cd00e9174064a900532bf8e420edf7ea1c4d16dad3145bb99acc0ab93a4ababf7bb76a12f5b383018a1f61ead98433cec2b1de07814d0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ferrumwizard.rb
CHANGED
@@ -10,11 +10,13 @@ class FerrumWizard
|
|
10
10
|
|
11
11
|
attr_reader :browser, :links, :radio, :buttons, :js_methods
|
12
12
|
|
13
|
-
def initialize(url, headless: true, debug: false)
|
13
|
+
def initialize(url, headless: true, timeout: 10, debug: false)
|
14
14
|
|
15
15
|
@url, @debug = url, debug
|
16
|
-
@browser = Ferrum::Browser.new headless: headless
|
16
|
+
@browser = Ferrum::Browser.new headless: headless, timeout: timeout
|
17
17
|
sleep 2
|
18
|
+
|
19
|
+
@browser.goto url if url
|
18
20
|
end
|
19
21
|
|
20
22
|
def inspect()
|
@@ -45,13 +47,41 @@ class FerrumWizard
|
|
45
47
|
end
|
46
48
|
|
47
49
|
e_password.focus.type(password, :Enter) if e_password
|
50
|
+
|
51
|
+
after_login()
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def login2(usernamex=nil, passwordx=nil, username: usernamex, password: passwordx)
|
56
|
+
|
57
|
+
puts 'username: ' + username.inspect if @debug
|
58
|
+
|
59
|
+
b = @browser
|
60
|
+
b.goto(@url)
|
48
61
|
@browser.network.wait_for_idle
|
62
|
+
sleep 3
|
63
|
+
|
64
|
+
# search for the username input box
|
65
|
+
e_username = b.at_xpath('//input[@type="email"]')
|
66
|
+
puts 'e_username: ' + e_username.inspect if @debug
|
67
|
+
sleep 1
|
68
|
+
# search for the password input box
|
49
69
|
|
50
|
-
|
70
|
+
if username and e_username then
|
71
|
+
puts 'entering the username' if @debug
|
72
|
+
e_username.focus.type(username, :Enter)
|
73
|
+
sleep 2
|
74
|
+
end
|
51
75
|
|
52
|
-
|
76
|
+
e_password = b.at_xpath('//input[@type="password"]')
|
77
|
+
sleep 1
|
53
78
|
|
54
|
-
|
79
|
+
e_password.focus.type(password, :Enter) if e_password
|
80
|
+
|
81
|
+
after_login()
|
82
|
+
|
83
|
+
|
84
|
+
end
|
55
85
|
|
56
86
|
def quit
|
57
87
|
@browser.quit
|
@@ -63,7 +93,23 @@ class FerrumWizard
|
|
63
93
|
fetch_links()
|
64
94
|
scan_form_elements()
|
65
95
|
scan_js_links()
|
66
|
-
self
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def submit(h)
|
100
|
+
|
101
|
+
e = nil
|
102
|
+
|
103
|
+
h.each do |key, value|
|
104
|
+
e = @browser.xpath('//input').find {|x| x.attribute('name') == key.to_s}
|
105
|
+
e.focus.type(value)
|
106
|
+
end
|
107
|
+
|
108
|
+
e.focus.type('', :Enter)
|
109
|
+
|
110
|
+
sleep 4
|
111
|
+
scan_page()
|
112
|
+
|
67
113
|
end
|
68
114
|
|
69
115
|
def to_rb()
|
@@ -71,6 +117,18 @@ class FerrumWizard
|
|
71
117
|
|
72
118
|
private
|
73
119
|
|
120
|
+
def after_login()
|
121
|
+
|
122
|
+
@browser.network.wait_for_idle
|
123
|
+
sleep 4
|
124
|
+
scan_page()
|
125
|
+
|
126
|
+
@browser.base_url = File.dirname(@browser.url)
|
127
|
+
@browser.mouse.scroll_to(0, 800)
|
128
|
+
self
|
129
|
+
|
130
|
+
end
|
131
|
+
|
74
132
|
def fetch_buttons()
|
75
133
|
|
76
134
|
a2 = @browser.xpath('//input[@type="button"]')
|
@@ -100,7 +158,7 @@ class FerrumWizard
|
|
100
158
|
|
101
159
|
def fetch_links()
|
102
160
|
|
103
|
-
all_links = @doc.root.xpath('//a')
|
161
|
+
all_links = @doc.root.xpath('//a[@href]')
|
104
162
|
|
105
163
|
all_links.each do |x|
|
106
164
|
|
@@ -121,9 +179,10 @@ class FerrumWizard
|
|
121
179
|
r
|
122
180
|
|
123
181
|
end
|
182
|
+
|
124
183
|
indices = valid_links.map {|x| all_links.index x}
|
125
184
|
|
126
|
-
active_links = @browser.xpath('//a')
|
185
|
+
active_links = @browser.xpath('//a[@href]')
|
127
186
|
valid_active_links = indices.map {|n| active_links[n]}
|
128
187
|
|
129
188
|
|
@@ -133,7 +192,8 @@ class FerrumWizard
|
|
133
192
|
a << [valid_links[i].text, x]
|
134
193
|
|
135
194
|
puts 'a: ' + a.inspect if @debug
|
136
|
-
a + a.map {|
|
195
|
+
a + a.map {|x2, obj| [x2.downcase, obj]}
|
196
|
+
|
137
197
|
end.to_h
|
138
198
|
|
139
199
|
names = @links.keys.map(&:downcase).uniq.select {|x| x =~ /^[\w ]+$/}
|
@@ -142,10 +202,14 @@ class FerrumWizard
|
|
142
202
|
names.each do |name|
|
143
203
|
|
144
204
|
define_singleton_method name.gsub(/ +/,'_').to_sym do
|
205
|
+
|
145
206
|
links[name].click
|
207
|
+
@browser.network.wait_for_idle
|
208
|
+
|
146
209
|
sleep 1
|
147
210
|
scan_page()
|
148
211
|
self
|
212
|
+
|
149
213
|
end
|
150
214
|
|
151
215
|
end
|
@@ -177,7 +241,7 @@ class FerrumWizard
|
|
177
241
|
|
178
242
|
|
179
243
|
s = e.attribute('href')[/(?<=^javascript:)[^\(]+/]
|
180
|
-
puts 's: ' + s.inspect
|
244
|
+
puts 's: ' + s.inspect if @debug
|
181
245
|
a = s.split(/\W+|(?=[A-Z])/).map {|label| [label, s]}
|
182
246
|
a << [s, s]
|
183
247
|
a << [s.split(/\W+|(?=[A-Z])/).join('_'), s]
|
@@ -186,7 +250,7 @@ class FerrumWizard
|
|
186
250
|
|
187
251
|
a.concat a.map {|x, name| [x.downcase, name] }
|
188
252
|
|
189
|
-
puts 'a: ' + a.inspect
|
253
|
+
puts 'a: ' + a.inspect if @debug
|
190
254
|
|
191
255
|
a.uniq.select {|x, _| x =~ /^[a-z0-9_]+$/}.each do |x, name|
|
192
256
|
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|