ferrum_common 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ferrum_common.gemspec +3 -2
- data/lib/ferrum_common.rb +53 -21
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 337f36c693834482dea4e00fcb2d5407b2787df08279bdba679b5e22b3482745
|
4
|
+
data.tar.gz: 01bceb7e7fa64fa3082040ecc11b7c83674ace1a2282153132172cc3e6c12a9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56f406f33b726a82f4aa2f7e8b1c4e39b53ddc14dedea932f550bb1e4d7586d09d835915fd2a219327c7fdfeae34e245ae4721b9f06eb66a2cbec1b743b1f977
|
7
|
+
data.tar.gz: afbcaa65ed2a25940d44290e3e82f4269eb5b74c6cdc80f6d402da7e7d87ff14fd3f704243d7e080f51c9014e74abba580ecc11df39a4c5a6838e9cf98bf5dd2
|
data/ferrum_common.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "ferrum_common"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.1.0"
|
4
4
|
spec.summary = "[WIP] common useful extensions for ferrum or cuprite"
|
5
5
|
|
6
6
|
spec.author = "Victor Maslov aka Nakilon"
|
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.metadata = {"source_code_uri" => "https://github.com/nakilon/ferrum_common"}
|
10
10
|
|
11
11
|
spec.add_dependency "ferrum"
|
12
|
-
spec.
|
12
|
+
spec.add_dependency "browser_reposition"
|
13
|
+
spec.required_ruby_version = ">=2.5" # why?
|
13
14
|
|
14
15
|
spec.files = %w{ LICENSE ferrum_common.gemspec lib/ferrum_common.rb }
|
15
16
|
end
|
data/lib/ferrum_common.rb
CHANGED
@@ -1,28 +1,60 @@
|
|
1
1
|
require "ferrum"
|
2
2
|
module FerrumCommon
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
|
4
|
+
module Common
|
5
|
+
|
6
|
+
def self.mhtml browser, timeout, mtd, msg = nil
|
7
|
+
Timeout.timeout(timeout){ yield }
|
8
|
+
rescue Timeout::Error
|
9
|
+
browser.mhtml path: "temp.mhtml"
|
10
|
+
$!.backtrace.reject!{ |_| _[/\/gems\/concurrent-ruby-/] }
|
11
|
+
$!.backtrace.reject!{ |_| _[/\/gems\/ferrum-/] }
|
12
|
+
raise Timeout::Error, "#{$!.to_s} after #{timeout} sec in #{mtd}#{" (#{msg.respond_to?(:call) ? msg.call : msg})" if msg}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def until_true timeout, msg = nil
|
16
|
+
Module.nesting.first.mhtml self, timeout, __method__, msg do
|
17
|
+
begin
|
18
|
+
yield
|
19
|
+
rescue Ferrum::NodeNotFoundError
|
20
|
+
redo
|
21
|
+
end or (sleep timeout*0.1; redo)
|
20
22
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
def until_one type, selector, timeout
|
26
|
+
t = nil
|
27
|
+
Module.nesting.first.mhtml self, timeout, __method__, ->{ "expected exactly one node for #{type} #{selector.inspect}, got #{t ? t.size : "none"}" } do
|
28
|
+
t = begin
|
29
|
+
public_method(type).call selector
|
30
|
+
rescue Ferrum::NodeNotFoundError
|
31
|
+
sleep timeout * 0.1
|
32
|
+
redo
|
33
|
+
end
|
34
|
+
unless 1 == t.size
|
35
|
+
sleep timeout * 0.1
|
36
|
+
redo
|
37
|
+
end
|
25
38
|
end
|
39
|
+
t.first
|
40
|
+
end
|
41
|
+
|
42
|
+
def abort msg_or_cause
|
43
|
+
# puts (msg_or_cause.respond_to?(:backtrace) ? msg_or_cause : Thread.current).backtrace
|
44
|
+
puts (msg_or_cause.respond_to?(:full_message) ? msg_or_cause.full_message : Thread.current.backtrace)
|
45
|
+
mhtml path: "temp.mhtml"
|
46
|
+
puts "dumped to ./temp.mhtml"
|
47
|
+
Kernel.abort msg_or_cause.to_s
|
26
48
|
end
|
49
|
+
|
50
|
+
end
|
51
|
+
Ferrum::Page.include Common
|
52
|
+
Ferrum::Frame.include Common
|
53
|
+
|
54
|
+
require "browser_reposition"
|
55
|
+
Ferrum::Browser.include Common, BrowserReposition
|
56
|
+
def self.new **_
|
57
|
+
Ferrum::Browser.new(**_).tap(&:reposition)
|
27
58
|
end
|
59
|
+
|
28
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ferrum_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ferrum
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: browser_reposition
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description:
|
28
42
|
email: nakilon@gmail.com
|
29
43
|
executables: []
|