puppeteer-ruby 0.33.0 → 0.34.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/CHANGELOG.md +7 -1
- data/README.md +10 -10
- data/docs/api_coverage.md +5 -5
- data/lib/puppeteer/concurrent_ruby_utils.rb +20 -2
- data/lib/puppeteer/define_async_method.rb +55 -4
- data/lib/puppeteer/frame.rb +1 -1
- data/lib/puppeteer/page.rb +3 -3
- data/lib/puppeteer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5338fde85118520d164288e9853e88f3edfadd0c0d6be491edcbde0c9d5609c
|
4
|
+
data.tar.gz: b6ac2dada9f4c7ce72401cf75b39ca452801165d68d5bd6ae537cf3a390e68ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eacd79d2af5cf69228ef6592739d20fd4f1739ec990355d904c32eb226c5dc998f7a37df7364a145df3e8beb763c304eaa8b1e1707c6aa8a237d4d8ec40f3b07
|
7
|
+
data.tar.gz: f0a725e220a109e0498c34e2f3e0d8e8e979b89d6003124d8cff7bb30c8b3579e72e5d1531a6f80669307d5a81a13f62fe99ee3c811ab9cffcb617bd12969830
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.
|
1
|
+
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.0...master)]
|
2
2
|
|
3
3
|
* xxx
|
4
4
|
|
5
|
+
### 0.34.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.33.0...0.34.0)]
|
6
|
+
|
7
|
+
New features:
|
8
|
+
|
9
|
+
* Sync API with block
|
10
|
+
|
5
11
|
### 0.33.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.4...0.33.0)]
|
6
12
|
|
7
13
|
NOTE: Requires Ruby version >= 2.6 explicitly since this version.
|
data/README.md
CHANGED
@@ -49,12 +49,13 @@ Puppeteer.launch(headless: false, slow_mo: 50, args: ['--guest', '--window-size=
|
|
49
49
|
page.goto("https://github.com/", wait_until: 'domcontentloaded')
|
50
50
|
|
51
51
|
form = page.query_selector("form.js-site-search-form")
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
search_input = form.query_selector("input.header-search-input")
|
53
|
+
search_input.click
|
54
|
+
page.keyboard.type_text("puppeteer")
|
55
|
+
|
56
|
+
page.wait_for_navigation do
|
57
|
+
search_input.press('Enter')
|
58
|
+
end
|
58
59
|
|
59
60
|
list = page.query_selector("ul.repo-list")
|
60
61
|
items = list.query_selector_all("div.f4")
|
@@ -136,10 +137,9 @@ RSpec.describe 'hotel.testplanisphere.dev', type: :feature do
|
|
136
137
|
|
137
138
|
reservation_link = puppeteer_page.query_selector_all('li.nav-item')[1]
|
138
139
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
)
|
140
|
+
puppeteer_page.wait_for_navigation do
|
141
|
+
reservation_link.click
|
142
|
+
end
|
143
143
|
|
144
144
|
# expectation with Capybara DSL
|
145
145
|
expect(page).to have_text('宿泊プラン一覧')
|
data/docs/api_coverage.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# API coverages
|
2
2
|
- Puppeteer version: v10.0.0
|
3
|
-
- puppeteer-ruby version: 0.
|
3
|
+
- puppeteer-ruby version: 0.34.0
|
4
4
|
|
5
5
|
## Puppeteer
|
6
6
|
|
@@ -131,9 +131,9 @@
|
|
131
131
|
* ~~waitFor~~
|
132
132
|
* waitForFileChooser => `#wait_for_file_chooser`
|
133
133
|
* waitForFunction => `#wait_for_function`
|
134
|
-
* waitForNavigation => `#
|
135
|
-
* waitForRequest => `#
|
136
|
-
* waitForResponse => `#
|
134
|
+
* waitForNavigation => `#wait_for_navigation`
|
135
|
+
* waitForRequest => `#wait_for_request`
|
136
|
+
* waitForResponse => `#wait_for_response`
|
137
137
|
* waitForSelector => `#wait_for_selector`
|
138
138
|
* waitForTimeout => `#wait_for_timeout`
|
139
139
|
* waitForXPath => `#wait_for_xpath`
|
@@ -226,7 +226,7 @@
|
|
226
226
|
* url
|
227
227
|
* ~~waitFor~~
|
228
228
|
* waitForFunction => `#wait_for_function`
|
229
|
-
* waitForNavigation => `#
|
229
|
+
* waitForNavigation => `#wait_for_navigation`
|
230
230
|
* waitForSelector => `#wait_for_selector`
|
231
231
|
* waitForTimeout => `#wait_for_timeout`
|
232
232
|
* waitForXPath => `#wait_for_xpath`
|
@@ -1,5 +1,23 @@
|
|
1
1
|
# utility methods for Concurrent::Promises.
|
2
2
|
module Puppeteer::ConcurrentRubyUtils
|
3
|
+
module ConcurrentPromisesFutureExtension
|
4
|
+
# Extension for describing 2 concurrent tasks smartly.
|
5
|
+
#
|
6
|
+
# page.async_for_navigation.with_waiting_for_complete do
|
7
|
+
# page.click('#submit')
|
8
|
+
# end
|
9
|
+
def with_waiting_for_complete(&block)
|
10
|
+
async_block_call = Concurrent::Promises.future do
|
11
|
+
block.call
|
12
|
+
rescue => err
|
13
|
+
Logger.new($stderr).warn(err)
|
14
|
+
raise err
|
15
|
+
end
|
16
|
+
|
17
|
+
Concurrent::Promises.zip(self, async_block_call).value!.first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
3
21
|
# wait for all promises.
|
4
22
|
# REMARK: This method doesn't assure the order of calling.
|
5
23
|
# for example, await_all(async1, async2) calls calls2 -> calls1 often.
|
@@ -48,7 +66,7 @@ module Puppeteer::ConcurrentRubyUtils
|
|
48
66
|
rescue => err
|
49
67
|
Logger.new($stderr).warn(err)
|
50
68
|
raise err
|
51
|
-
end
|
69
|
+
end.extend(ConcurrentPromisesFutureExtension)
|
52
70
|
end
|
53
71
|
|
54
72
|
def resolvable_future(&block)
|
@@ -56,7 +74,7 @@ module Puppeteer::ConcurrentRubyUtils
|
|
56
74
|
if block
|
57
75
|
block.call(future)
|
58
76
|
end
|
59
|
-
future
|
77
|
+
future.extend(ConcurrentPromisesFutureExtension)
|
60
78
|
end
|
61
79
|
end
|
62
80
|
|
@@ -9,22 +9,73 @@ module Puppeteer::DefineAsyncMethod
|
|
9
9
|
raise ArgumentError.new("#{async_method_name} is already defined")
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
original_method_name = async_method_name[6..-1]
|
13
|
+
original_method = instance_method(original_method_name)
|
14
|
+
|
15
|
+
# - Modify only wait_for_xxx
|
16
|
+
# - Do not modify private methods.
|
17
|
+
if method_defined?(original_method_name) && original_method_name.start_with?('wait_for_')
|
18
|
+
# def wait_for_xxx(xx, yy, &block)
|
19
|
+
#
|
20
|
+
# -> await_all(
|
21
|
+
# async_wait_for_xxx(xx, yy),
|
22
|
+
# future { block.call },
|
23
|
+
# ).first
|
24
|
+
define_method(original_method_name) do |*args, **kwargs, &block|
|
25
|
+
if block
|
26
|
+
async_method_call =
|
27
|
+
if kwargs.empty? # for Ruby 2.6
|
28
|
+
Concurrent::Promises.future do
|
29
|
+
original_method.bind(self).call(*args)
|
30
|
+
rescue => err
|
31
|
+
Logger.new($stderr).warn(err)
|
32
|
+
raise err
|
33
|
+
end
|
34
|
+
else
|
35
|
+
Concurrent::Promises.future do
|
36
|
+
original_method.bind(self).call(*args, **kwargs)
|
37
|
+
rescue => err
|
38
|
+
Logger.new($stderr).warn(err)
|
39
|
+
raise err
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
async_block_call = Concurrent::Promises.future do
|
44
|
+
block.call
|
45
|
+
rescue => err
|
46
|
+
Logger.new($stderr).warn(err)
|
47
|
+
raise err
|
48
|
+
end
|
49
|
+
|
50
|
+
Concurrent::Promises.zip(
|
51
|
+
async_method_call,
|
52
|
+
async_block_call,
|
53
|
+
).value!.first
|
54
|
+
else
|
55
|
+
if kwargs.empty? # for Ruby 2.6
|
56
|
+
original_method.bind(self).call(*args)
|
57
|
+
else
|
58
|
+
original_method.bind(self).call(*args, **kwargs)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
13
64
|
define_method(async_method_name) do |*args, **kwargs|
|
14
|
-
if kwargs.empty? # for Ruby
|
65
|
+
if kwargs.empty? # for Ruby 2.6
|
15
66
|
Concurrent::Promises.future do
|
16
67
|
original_method.bind(self).call(*args)
|
17
68
|
rescue => err
|
18
69
|
Logger.new($stderr).warn(err)
|
19
70
|
raise err
|
20
|
-
end
|
71
|
+
end.extend(Puppeteer::ConcurrentRubyUtils::ConcurrentPromisesFutureExtension)
|
21
72
|
else
|
22
73
|
Concurrent::Promises.future do
|
23
74
|
original_method.bind(self).call(*args, **kwargs)
|
24
75
|
rescue => err
|
25
76
|
Logger.new($stderr).warn(err)
|
26
77
|
raise err
|
27
|
-
end
|
78
|
+
end.extend(Puppeteer::ConcurrentRubyUtils::ConcurrentPromisesFutureExtension)
|
28
79
|
end
|
29
80
|
end
|
30
81
|
end
|
data/lib/puppeteer/frame.rb
CHANGED
@@ -35,7 +35,7 @@ class Puppeteer::Frame
|
|
35
35
|
|
36
36
|
# @param timeout [number|nil]
|
37
37
|
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
|
38
|
-
|
38
|
+
def wait_for_navigation(timeout: nil, wait_until: nil)
|
39
39
|
@frame_manager.wait_for_frame_navigation(self, timeout: timeout, wait_until: wait_until)
|
40
40
|
end
|
41
41
|
|
data/lib/puppeteer/page.rb
CHANGED
@@ -637,7 +637,7 @@ class Puppeteer::Page
|
|
637
637
|
).first
|
638
638
|
end
|
639
639
|
|
640
|
-
|
640
|
+
def wait_for_navigation(timeout: nil, wait_until: nil)
|
641
641
|
main_frame.send(:wait_for_navigation, timeout: timeout, wait_until: wait_until)
|
642
642
|
end
|
643
643
|
|
@@ -683,7 +683,7 @@ class Puppeteer::Page
|
|
683
683
|
end
|
684
684
|
end
|
685
685
|
|
686
|
-
|
686
|
+
def wait_for_request(url: nil, predicate: nil, timeout: nil)
|
687
687
|
if !url && !predicate
|
688
688
|
raise ArgumentError.new('url or predicate must be specified')
|
689
689
|
end
|
@@ -717,7 +717,7 @@ class Puppeteer::Page
|
|
717
717
|
# @param predicate [Proc(Puppeteer::Request -> Boolean)]
|
718
718
|
define_async_method :async_wait_for_request
|
719
719
|
|
720
|
-
|
720
|
+
def wait_for_response(url: nil, predicate: nil, timeout: nil)
|
721
721
|
if !url && !predicate
|
722
722
|
raise ArgumentError.new('url or predicate must be specified')
|
723
723
|
end
|
data/lib/puppeteer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppeteer-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.34.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|