puppeteer-ruby 0.29.0 → 0.30.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 -2
- data/README.md +7 -7
- data/lib/puppeteer/dom_world.rb +21 -17
- data/lib/puppeteer/element_handle.rb +15 -11
- data/lib/puppeteer/frame.rb +20 -16
- data/lib/puppeteer/page.rb +20 -16
- 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: f1b2bb89d30c93e2f942e9e14b72952f7fbbdcb027c564a9477d920316032d83
|
4
|
+
data.tar.gz: 716ee3c3cc6d7a7d1086d9dc34b97c879996dfcc18e88744a9a70e8d2292b842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 952bc67ff27947ac127c43316476a9e690f6dfc0cdfaa6dabb5030ddca782f178bb0e9c71c156c6a707979d1322a4d0f24eacf0015e2b92db77d4da31e1ecc7c
|
7
|
+
data.tar.gz: 58775749a3ef44e2e2ab27fd90fee93ae74b2fa7ecec087bdb8df4bc5ede5e4199f07dd9cff587fd968ea509b03962c43b35e7711307f7b163f59ffceb3b7a07
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,19 @@
|
|
1
|
-
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.
|
1
|
+
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.30.0...master)]
|
2
2
|
|
3
3
|
* xxx
|
4
4
|
|
5
|
+
### 0.30.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.29.0...0.30.0)]
|
6
|
+
|
7
|
+
New features:
|
8
|
+
|
9
|
+
* S, SS, Seval, SSeval is renamed to query_selector, query_selector_all, eval_on_selector, eval_on_selector_all
|
10
|
+
|
5
11
|
### 0.29.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.28.1...0.29.0)]
|
6
12
|
|
7
13
|
New features:
|
8
14
|
|
9
15
|
* Add `AriaQueryHandler`. Now we can use "aria/...." for selectors.
|
10
16
|
|
11
|
-
|
12
17
|
### 0.28.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.27...0.28.1)]
|
13
18
|
|
14
19
|
New features:
|
data/README.md
CHANGED
@@ -46,18 +46,18 @@ Puppeteer.launch(headless: false, slow_mo: 50, args: ['--guest', '--window-size=
|
|
46
46
|
page.viewport = Puppeteer::Viewport.new(width: 1280, height: 800)
|
47
47
|
page.goto("https://github.com/", wait_until: 'domcontentloaded')
|
48
48
|
|
49
|
-
form = page.
|
50
|
-
searchInput = form.
|
49
|
+
form = page.query_selector("form.js-site-search-form")
|
50
|
+
searchInput = form.query_selector("input.header-search-input")
|
51
51
|
searchInput.type_text("puppeteer")
|
52
52
|
await_all(
|
53
53
|
page.async_wait_for_navigation,
|
54
54
|
searchInput.async_press("Enter"),
|
55
55
|
)
|
56
56
|
|
57
|
-
list = page.
|
58
|
-
items = list.
|
57
|
+
list = page.query_selector("ul.repo-list")
|
58
|
+
items = list.query_selector_all("div.f4")
|
59
59
|
items.each do |item|
|
60
|
-
title = item.
|
60
|
+
title = item.eval_on_selector("a", "a => a.innerText")
|
61
61
|
puts("==> #{title}")
|
62
62
|
end
|
63
63
|
end
|
@@ -130,7 +130,7 @@ RSpec.describe 'hotel.testplanisphere.dev', type: :feature do
|
|
130
130
|
puppeteer_page = @browser.pages.first
|
131
131
|
puppeteer_page.wait_for_selector('li.nav-item')
|
132
132
|
|
133
|
-
reservation_link = puppeteer_page.
|
133
|
+
reservation_link = puppeteer_page.query_selector_all('li.nav-item')[1]
|
134
134
|
|
135
135
|
await_all(
|
136
136
|
puppeteer_page.async_wait_for_navigation,
|
@@ -147,7 +147,7 @@ RSpec.describe 'hotel.testplanisphere.dev', type: :feature do
|
|
147
147
|
|
148
148
|
# expectation with puppeteer
|
149
149
|
puppeteer_page = @browser.pages.first
|
150
|
-
body_text = puppeteer_page.
|
150
|
+
body_text = puppeteer_page.eval_on_selector('body', '(el) => el.textContent')
|
151
151
|
expect(body_text).to include('宿泊プラン一覧')
|
152
152
|
end
|
153
153
|
```
|
data/lib/puppeteer/dom_world.rb
CHANGED
@@ -126,12 +126,13 @@ class Puppeteer::DOMWorld
|
|
126
126
|
execution_context.evaluate(page_function, *args)
|
127
127
|
end
|
128
128
|
|
129
|
-
# `$()` in JavaScript.
|
129
|
+
# `$()` in JavaScript.
|
130
130
|
# @param {string} selector
|
131
131
|
# @return {!Promise<?Puppeteer.ElementHandle>}
|
132
|
-
def
|
133
|
-
document.
|
132
|
+
def query_selector(selector)
|
133
|
+
document.query_selector(selector)
|
134
134
|
end
|
135
|
+
alias_method :S, :query_selector
|
135
136
|
|
136
137
|
private def evaluate_document
|
137
138
|
# sometimes execution_context.evaluate_handle('document') returns null object.
|
@@ -158,30 +159,33 @@ class Puppeteer::DOMWorld
|
|
158
159
|
document.Sx(expression)
|
159
160
|
end
|
160
161
|
|
161
|
-
# `$eval()` in JavaScript.
|
162
|
+
# `$eval()` in JavaScript.
|
162
163
|
# @param {string} selector
|
163
164
|
# @param {Function|string} pageFunction
|
164
165
|
# @param {!Array<*>} args
|
165
166
|
# @return {!Promise<(!Object|undefined)>}
|
166
|
-
def
|
167
|
-
document.
|
167
|
+
def eval_on_selector(selector, page_function, *args)
|
168
|
+
document.eval_on_selector(selector, page_function, *args)
|
168
169
|
end
|
170
|
+
alias_method :Seval, :eval_on_selector
|
169
171
|
|
170
|
-
# `$$eval()` in JavaScript.
|
172
|
+
# `$$eval()` in JavaScript.
|
171
173
|
# @param {string} selector
|
172
174
|
# @param {Function|string} pageFunction
|
173
175
|
# @param {!Array<*>} args
|
174
176
|
# @return {!Promise<(!Object|undefined)>}
|
175
|
-
def
|
176
|
-
document.
|
177
|
+
def eval_on_selector_all(selector, page_function, *args)
|
178
|
+
document.eval_on_selector_all(selector, page_function, *args)
|
177
179
|
end
|
180
|
+
alias_method :SSeval, :eval_on_selector_all
|
178
181
|
|
179
|
-
# `$$()` in JavaScript.
|
182
|
+
# `$$()` in JavaScript.
|
180
183
|
# @param {string} selector
|
181
184
|
# @return {!Promise<!Array<!Puppeteer.ElementHandle>>}
|
182
|
-
def
|
183
|
-
document.
|
185
|
+
def query_selector_all(selector)
|
186
|
+
document.query_selector_all(selector)
|
184
187
|
end
|
188
|
+
alias_method :SS, :query_selector_all
|
185
189
|
|
186
190
|
# @return [String]
|
187
191
|
def content
|
@@ -376,14 +380,14 @@ class Puppeteer::DOMWorld
|
|
376
380
|
# @param button [String] "left"|"right"|"middle"
|
377
381
|
# @param click_count [Number]
|
378
382
|
def click(selector, delay: nil, button: nil, click_count: nil)
|
379
|
-
handle =
|
383
|
+
handle = query_selector(selector) or raise ElementNotFoundError.new(selector)
|
380
384
|
handle.click(delay: delay, button: button, click_count: click_count)
|
381
385
|
handle.dispose
|
382
386
|
end
|
383
387
|
|
384
388
|
# @param selector [String]
|
385
389
|
def focus(selector)
|
386
|
-
handle =
|
390
|
+
handle = query_selector(selector) or raise ElementNotFoundError.new(selector)
|
387
391
|
handle.focus
|
388
392
|
handle.dispose
|
389
393
|
end
|
@@ -401,7 +405,7 @@ class Puppeteer::DOMWorld
|
|
401
405
|
# @param selector [String]
|
402
406
|
# @return [Array<String>]
|
403
407
|
def select(selector, *values)
|
404
|
-
handle =
|
408
|
+
handle = query_selector(selector) or raise ElementNotFoundError.new(selector)
|
405
409
|
result = handle.select(*values)
|
406
410
|
handle.dispose
|
407
411
|
|
@@ -410,7 +414,7 @@ class Puppeteer::DOMWorld
|
|
410
414
|
|
411
415
|
# @param selector [String]
|
412
416
|
def tap(selector)
|
413
|
-
handle =
|
417
|
+
handle = query_selector(selector) or raise ElementNotFoundError.new(selector)
|
414
418
|
handle.tap
|
415
419
|
handle.dispose
|
416
420
|
end
|
@@ -419,7 +423,7 @@ class Puppeteer::DOMWorld
|
|
419
423
|
# @param text [String]
|
420
424
|
# @param delay [Number]
|
421
425
|
def type_text(selector, text, delay: nil)
|
422
|
-
handle =
|
426
|
+
handle = query_selector(selector) or raise ElementNotFoundError.new(selector)
|
423
427
|
handle.type_text(text, delay: delay)
|
424
428
|
handle.dispose
|
425
429
|
end
|
@@ -318,17 +318,19 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
318
318
|
Puppeteer::QueryHandlerManager.instance
|
319
319
|
end
|
320
320
|
|
321
|
-
# `$()` in JavaScript.
|
321
|
+
# `$()` in JavaScript.
|
322
322
|
# @param selector [String]
|
323
|
-
def
|
323
|
+
def query_selector(selector)
|
324
324
|
query_handler_manager.detect_query_handler(selector).query_one(self)
|
325
325
|
end
|
326
|
+
alias_method :S, :query_selector
|
326
327
|
|
327
|
-
# `$$()` in JavaScript.
|
328
|
+
# `$$()` in JavaScript.
|
328
329
|
# @param selector [String]
|
329
|
-
def
|
330
|
+
def query_selector_all(selector)
|
330
331
|
query_handler_manager.detect_query_handler(selector).query_all(self)
|
331
332
|
end
|
333
|
+
alias_method :SS, :query_selector_all
|
332
334
|
|
333
335
|
class ElementNotFoundError < StandardError
|
334
336
|
def initialize(selector)
|
@@ -336,12 +338,12 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
336
338
|
end
|
337
339
|
end
|
338
340
|
|
339
|
-
# `$eval()` in JavaScript.
|
341
|
+
# `$eval()` in JavaScript.
|
340
342
|
# @param selector [String]
|
341
343
|
# @param page_function [String]
|
342
344
|
# @return [Object]
|
343
|
-
def
|
344
|
-
element_handle =
|
345
|
+
def eval_on_selector(selector, page_function, *args)
|
346
|
+
element_handle = query_selector(selector)
|
345
347
|
unless element_handle
|
346
348
|
raise ElementNotFoundError.new(selector)
|
347
349
|
end
|
@@ -350,22 +352,24 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
350
352
|
|
351
353
|
result
|
352
354
|
end
|
355
|
+
alias_method :Seval, :eval_on_selector
|
353
356
|
|
354
|
-
define_async_method :
|
357
|
+
define_async_method :async_eval_on_selector
|
355
358
|
|
356
|
-
# `$$eval()` in JavaScript.
|
359
|
+
# `$$eval()` in JavaScript.
|
357
360
|
# @param selector [String]
|
358
361
|
# @param page_function [String]
|
359
362
|
# @return [Object]
|
360
|
-
def
|
363
|
+
def eval_on_selector_all(selector, page_function, *args)
|
361
364
|
handles = query_handler_manager.detect_query_handler(selector).query_all_array(self)
|
362
365
|
result = handles.evaluate(page_function, *args)
|
363
366
|
handles.dispose
|
364
367
|
|
365
368
|
result
|
366
369
|
end
|
370
|
+
alias_method :SSeval, :eval_on_selector_all
|
367
371
|
|
368
|
-
define_async_method :
|
372
|
+
define_async_method :async_eval_on_selector_all
|
369
373
|
|
370
374
|
# `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
371
375
|
# @param expression [String]
|
data/lib/puppeteer/frame.rb
CHANGED
@@ -61,14 +61,15 @@ class Puppeteer::Frame
|
|
61
61
|
|
62
62
|
define_async_method :async_evaluate
|
63
63
|
|
64
|
-
# `$()` in JavaScript.
|
64
|
+
# `$()` in JavaScript.
|
65
65
|
# @param {string} selector
|
66
66
|
# @return {!Promise<?Puppeteer.ElementHandle>}
|
67
|
-
def
|
68
|
-
@main_world.
|
67
|
+
def query_selector(selector)
|
68
|
+
@main_world.query_selector(selector)
|
69
69
|
end
|
70
|
+
alias_method :S, :query_selector
|
70
71
|
|
71
|
-
define_async_method :
|
72
|
+
define_async_method :async_query_selector
|
72
73
|
|
73
74
|
# `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
74
75
|
# @param {string} expression
|
@@ -79,36 +80,39 @@ class Puppeteer::Frame
|
|
79
80
|
|
80
81
|
define_async_method :async_Sx
|
81
82
|
|
82
|
-
# `$eval()` in JavaScript.
|
83
|
+
# `$eval()` in JavaScript.
|
83
84
|
# @param {string} selector
|
84
85
|
# @param {Function|string} pageFunction
|
85
86
|
# @param {!Array<*>} args
|
86
87
|
# @return {!Promise<(!Object|undefined)>}
|
87
|
-
def
|
88
|
-
@main_world.
|
88
|
+
def eval_on_selector(selector, page_function, *args)
|
89
|
+
@main_world.eval_on_selector(selector, page_function, *args)
|
89
90
|
end
|
91
|
+
alias_method :Seval, :eval_on_selector
|
90
92
|
|
91
|
-
define_async_method :
|
93
|
+
define_async_method :async_eval_on_selector
|
92
94
|
|
93
|
-
# `$$eval()` in JavaScript.
|
95
|
+
# `$$eval()` in JavaScript.
|
94
96
|
# @param {string} selector
|
95
97
|
# @param {Function|string} pageFunction
|
96
98
|
# @param {!Array<*>} args
|
97
99
|
# @return {!Promise<(!Object|undefined)>}
|
98
|
-
def
|
99
|
-
@main_world.
|
100
|
+
def eval_on_selector_all(selector, page_function, *args)
|
101
|
+
@main_world.eval_on_selector_all(selector, page_function, *args)
|
100
102
|
end
|
103
|
+
alias_method :SSeval, :eval_on_selector_all
|
101
104
|
|
102
|
-
define_async_method :
|
105
|
+
define_async_method :async_eval_on_selector_all
|
103
106
|
|
104
|
-
# `$$()` in JavaScript.
|
107
|
+
# `$$()` in JavaScript.
|
105
108
|
# @param {string} selector
|
106
109
|
# @return {!Promise<!Array<!Puppeteer.ElementHandle>>}
|
107
|
-
def
|
108
|
-
@main_world.
|
110
|
+
def query_selector_all(selector)
|
111
|
+
@main_world.query_selector_all(selector)
|
109
112
|
end
|
113
|
+
alias_method :SS, :query_selector_all
|
110
114
|
|
111
|
-
define_async_method :
|
115
|
+
define_async_method :async_query_selector_all
|
112
116
|
|
113
117
|
# @return [String]
|
114
118
|
def content
|
data/lib/puppeteer/page.rb
CHANGED
@@ -276,23 +276,25 @@ class Puppeteer::Page
|
|
276
276
|
@timeout_settings.default_timeout = timeout
|
277
277
|
end
|
278
278
|
|
279
|
-
# `$()` in JavaScript.
|
279
|
+
# `$()` in JavaScript.
|
280
280
|
# @param {string} selector
|
281
281
|
# @return {!Promise<?Puppeteer.ElementHandle>}
|
282
|
-
def
|
283
|
-
main_frame.
|
282
|
+
def query_selector(selector)
|
283
|
+
main_frame.query_selector(selector)
|
284
284
|
end
|
285
|
+
alias_method :S, :query_selector
|
285
286
|
|
286
|
-
define_async_method :
|
287
|
+
define_async_method :async_query_selector
|
287
288
|
|
288
|
-
# `$$()` in JavaScript.
|
289
|
+
# `$$()` in JavaScript.
|
289
290
|
# @param {string} selector
|
290
291
|
# @return {!Promise<!Array<!Puppeteer.ElementHandle>>}
|
291
|
-
def
|
292
|
-
main_frame.
|
292
|
+
def query_selector_all(selector)
|
293
|
+
main_frame.query_selector_all(selector)
|
293
294
|
end
|
295
|
+
alias_method :SS, :query_selector_all
|
294
296
|
|
295
|
-
define_async_method :
|
297
|
+
define_async_method :async_query_selector_all
|
296
298
|
|
297
299
|
# @param {Function|string} pageFunction
|
298
300
|
# @param {!Array<*>} args
|
@@ -311,25 +313,27 @@ class Puppeteer::Page
|
|
311
313
|
context.query_objects(prototype_handle)
|
312
314
|
end
|
313
315
|
|
314
|
-
# `$eval()` in JavaScript.
|
316
|
+
# `$eval()` in JavaScript.
|
315
317
|
# @param selector [String]
|
316
318
|
# @param page_function [String]
|
317
319
|
# @return [Object]
|
318
|
-
def
|
319
|
-
main_frame.
|
320
|
+
def eval_on_selector(selector, page_function, *args)
|
321
|
+
main_frame.eval_on_selector(selector, page_function, *args)
|
320
322
|
end
|
323
|
+
alias_method :Seval, :eval_on_selector
|
321
324
|
|
322
|
-
define_async_method :
|
325
|
+
define_async_method :async_eval_on_selector
|
323
326
|
|
324
|
-
# `$$eval()` in JavaScript.
|
327
|
+
# `$$eval()` in JavaScript.
|
325
328
|
# @param selector [String]
|
326
329
|
# @param page_function [String]
|
327
330
|
# @return [Object]
|
328
|
-
def
|
329
|
-
main_frame.
|
331
|
+
def eval_on_selector_all(selector, page_function, *args)
|
332
|
+
main_frame.eval_on_selector_all(selector, page_function, *args)
|
330
333
|
end
|
334
|
+
alias_method :SSeval, :eval_on_selector_all
|
331
335
|
|
332
|
-
define_async_method :
|
336
|
+
define_async_method :async_eval_on_selector_all
|
333
337
|
|
334
338
|
# `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
335
339
|
# @param {string} expression
|
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.30.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-02-
|
11
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|