playwright-ruby-client 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/documentation/docs/api/browser.md +8 -2
- data/documentation/docs/api/browser_type.md +1 -0
- data/documentation/docs/api/experimental/android_device.md +1 -0
- data/documentation/docs/api/frame.md +14 -0
- data/documentation/docs/api/keyboard.md +11 -20
- data/documentation/docs/api/page.md +15 -1
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +91 -0
- data/documentation/docs/article/guides/semi_automation.md +4 -0
- data/documentation/docs/include/api_coverage.md +2 -1
- data/lib/playwright/channel_owners/artifact.rb +4 -0
- data/lib/playwright/channel_owners/browser_context.rb +7 -3
- data/lib/playwright/channel_owners/frame.rb +22 -2
- data/lib/playwright/channel_owners/page.rb +24 -14
- data/lib/playwright/download.rb +4 -0
- data/lib/playwright/route_handler_entry.rb +3 -2
- data/lib/playwright/url_matcher.rb +12 -2
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/android_device.rb +2 -1
- data/lib/playwright_api/browser.rb +10 -4
- data/lib/playwright_api/browser_type.rb +2 -1
- data/lib/playwright_api/frame.rb +10 -0
- data/lib/playwright_api/page.rb +11 -1
- data/lib/playwright_api/route.rb +0 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e631604c0af31dc184fd1bfe6953be910d4f19be8613e8a2a11c83a3d5e9049
|
4
|
+
data.tar.gz: b320853082ae065cc09195f09e35f9a5bf18edc3105c729c9bd4a4daeb804948
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ea608b469db2082b899c3b4c10cbfea703f222a79fb255a0d07d03eb46eacbd0274cb98c1c32a9241f120f5059bdb20fbc82a65a072c05e616bdbd4b76586aa
|
7
|
+
data.tar.gz: 50ea41552e79e96add337084c9a38961bae124dfcaf04c9fe3ab61ceb2cd5e8738f0ae6fffdb6e04157416593f351bc7177e03e0da75cf51a80e929e1bce3f42
|
@@ -76,6 +76,7 @@ Returns the newly created browser session.
|
|
76
76
|
```
|
77
77
|
def new_context(
|
78
78
|
acceptDownloads: nil,
|
79
|
+
baseURL: nil,
|
79
80
|
bypassCSP: nil,
|
80
81
|
colorScheme: nil,
|
81
82
|
deviceScaleFactor: nil,
|
@@ -124,6 +125,7 @@ end
|
|
124
125
|
```
|
125
126
|
def new_page(
|
126
127
|
acceptDownloads: nil,
|
128
|
+
baseURL: nil,
|
127
129
|
bypassCSP: nil,
|
128
130
|
colorScheme: nil,
|
129
131
|
deviceScaleFactor: nil,
|
@@ -164,7 +166,9 @@ testing frameworks should explicitly create [Browser#new_context](./browser#new_
|
|
164
166
|
def start_tracing(page: nil, categories: nil, path: nil, screenshots: nil)
|
165
167
|
```
|
166
168
|
|
167
|
-
> NOTE:
|
169
|
+
> NOTE: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool)
|
170
|
+
which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](https://playwright.dev/python/docs/trace-viewer) could be
|
171
|
+
found [here](./tracing).
|
168
172
|
|
169
173
|
You can use [Browser#start_tracing](./browser#start_tracing) and [Browser#stop_tracing](./browser#stop_tracing) to create a trace file that can be
|
170
174
|
opened in Chrome DevTools performance panel.
|
@@ -185,7 +189,9 @@ end
|
|
185
189
|
def stop_tracing
|
186
190
|
```
|
187
191
|
|
188
|
-
> NOTE:
|
192
|
+
> NOTE: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool)
|
193
|
+
which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](https://playwright.dev/python/docs/trace-viewer) could be
|
194
|
+
found [here](./tracing).
|
189
195
|
|
190
196
|
Returns the buffer with trace data.
|
191
197
|
|
@@ -196,6 +196,20 @@ frame.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
|
|
196
196
|
|
197
197
|
|
198
198
|
|
199
|
+
## drag_and_drop
|
200
|
+
|
201
|
+
```
|
202
|
+
def drag_and_drop(
|
203
|
+
source,
|
204
|
+
target,
|
205
|
+
force: nil,
|
206
|
+
noWaitAfter: nil,
|
207
|
+
timeout: nil,
|
208
|
+
trial: nil)
|
209
|
+
```
|
210
|
+
|
211
|
+
|
212
|
+
|
199
213
|
## eval_on_selector
|
200
214
|
|
201
215
|
```
|
@@ -12,35 +12,31 @@ to manually fire events as if they were generated from a real keyboard.
|
|
12
12
|
|
13
13
|
An example of holding down `Shift` in order to select and delete some text:
|
14
14
|
|
15
|
-
```
|
15
|
+
```ruby
|
16
16
|
page.keyboard.type("Hello World!")
|
17
17
|
page.keyboard.press("ArrowLeft")
|
18
18
|
page.keyboard.down("Shift")
|
19
|
-
|
20
|
-
page.keyboard.press("ArrowLeft")
|
19
|
+
6.times { page.keyboard.press("ArrowLeft") }
|
21
20
|
page.keyboard.up("Shift")
|
22
21
|
page.keyboard.press("Backspace")
|
23
22
|
# result text will end up saying "Hello!"
|
24
|
-
|
25
23
|
```
|
26
24
|
|
27
25
|
An example of pressing uppercase `A`
|
28
26
|
|
29
|
-
```
|
27
|
+
```ruby
|
30
28
|
page.keyboard.press("Shift+KeyA")
|
31
29
|
# or
|
32
30
|
page.keyboard.press("Shift+A")
|
33
|
-
|
34
31
|
```
|
35
32
|
|
36
33
|
An example to trigger select-all with the keyboard
|
37
34
|
|
38
|
-
```
|
35
|
+
```ruby
|
39
36
|
# on windows and linux
|
40
37
|
page.keyboard.press("Control+A")
|
41
38
|
# on mac_os
|
42
39
|
page.keyboard.press("Meta+A")
|
43
|
-
|
44
40
|
```
|
45
41
|
|
46
42
|
|
@@ -84,9 +80,8 @@ def insert_text(text)
|
|
84
80
|
|
85
81
|
Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events.
|
86
82
|
|
87
|
-
```
|
83
|
+
```ruby
|
88
84
|
page.keyboard.insert_text("嗨")
|
89
|
-
|
90
85
|
```
|
91
86
|
|
92
87
|
> NOTE: Modifier keys DO NOT effect `keyboard.insertText`. Holding down `Shift` will not type the text in upper case.
|
@@ -114,17 +109,14 @@ texts.
|
|
114
109
|
Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
|
115
110
|
modifier, modifier is pressed and being held while the subsequent key is being pressed.
|
116
111
|
|
117
|
-
```
|
118
|
-
page = browser.new_page()
|
112
|
+
```ruby
|
119
113
|
page.goto("https://keycode.info")
|
120
114
|
page.keyboard.press("a")
|
121
|
-
page.screenshot(path
|
115
|
+
page.screenshot(path: "a.png")
|
122
116
|
page.keyboard.press("ArrowLeft")
|
123
|
-
page.screenshot(path
|
117
|
+
page.screenshot(path: "arrow_left.png")
|
124
118
|
page.keyboard.press("Shift+O")
|
125
|
-
page.screenshot(path
|
126
|
-
browser.close()
|
127
|
-
|
119
|
+
page.screenshot(path: "o.png")
|
128
120
|
```
|
129
121
|
|
130
122
|
Shortcut for [Keyboard#down](./keyboard#down) and [Keyboard#up](./keyboard#up).
|
@@ -139,10 +131,9 @@ Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in t
|
|
139
131
|
|
140
132
|
To press a special key, like `Control` or `ArrowDown`, use [Keyboard#press](./keyboard#press).
|
141
133
|
|
142
|
-
```
|
134
|
+
```ruby
|
143
135
|
page.keyboard.type("Hello") # types instantly
|
144
|
-
page.keyboard.type("World", delay
|
145
|
-
|
136
|
+
page.keyboard.type("World", delay: 100) # types slower, like a user
|
146
137
|
```
|
147
138
|
|
148
139
|
> NOTE: Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
|
@@ -253,6 +253,20 @@ page.dispatch_event("#source", "dragstart", eventInit: { dataTransfer: data_tran
|
|
253
253
|
|
254
254
|
|
255
255
|
|
256
|
+
## drag_and_drop
|
257
|
+
|
258
|
+
```
|
259
|
+
def drag_and_drop(
|
260
|
+
source,
|
261
|
+
target,
|
262
|
+
force: nil,
|
263
|
+
noWaitAfter: nil,
|
264
|
+
timeout: nil,
|
265
|
+
trial: nil)
|
266
|
+
```
|
267
|
+
|
268
|
+
|
269
|
+
|
256
270
|
## emulate_media
|
257
271
|
|
258
272
|
```
|
@@ -1320,7 +1334,7 @@ Performs action and waits for a popup [Page](./page). If predicate is provided,
|
|
1320
1334
|
def expect_request(urlOrPredicate, timeout: nil, &block)
|
1321
1335
|
```
|
1322
1336
|
|
1323
|
-
Waits for the matching request and returns it.
|
1337
|
+
Waits for the matching request and returns it. See [waiting for event](https://playwright.dev/python/docs/events) for more details
|
1324
1338
|
about events.
|
1325
1339
|
|
1326
1340
|
```ruby
|
@@ -0,0 +1,91 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 6
|
3
|
+
---
|
4
|
+
|
5
|
+
# Playwright on Alpine Linux
|
6
|
+
|
7
|
+
**NOTE: This feature is EXPERIMENTAL.**
|
8
|
+
|
9
|
+
Playwright actually requires a permission for shell command execution, and many run-time dependencies for each browser.
|
10
|
+
|
11
|
+
![all-in-one](https://user-images.githubusercontent.com/11763113/124934388-9c9c9100-e03f-11eb-8f13-324afac3be2a.png)
|
12
|
+
|
13
|
+
This all-in-one architecture is reasonable for browser automation in our own computers.
|
14
|
+
|
15
|
+
However we may have trouble with bringing Playwright into:
|
16
|
+
|
17
|
+
* Docker
|
18
|
+
* Alpine Linux
|
19
|
+
* Serverless computing
|
20
|
+
* AWS Lambda
|
21
|
+
* Google Cloud Functions
|
22
|
+
* PaaS
|
23
|
+
* Heroku
|
24
|
+
* Google App Engine
|
25
|
+
|
26
|
+
This article introduces a way to separate environments into client (for executing Playwright script) and server (for working with browsers). The main use-case assumes Docker (using Alpine Linux), however the way can be applied also into other use-cases.
|
27
|
+
|
28
|
+
## Overview
|
29
|
+
|
30
|
+
Playwrignt Ruby client is running on Alpine Linux. It just sends/receives JSON messages of Playwright-protocol via WebSocket.
|
31
|
+
|
32
|
+
Playwright server is running on a container of [official Docker image](https://hub.docker.com/_/microsoft-playwright). It just operates browsers in response to the JSON messages from WebSocket.
|
33
|
+
|
34
|
+
![overview](https://user-images.githubusercontent.com/11763113/124934448-ad4d0700-e03f-11eb-942e-b9f3282bb703.png)
|
35
|
+
|
36
|
+
## Playwright client
|
37
|
+
|
38
|
+
Many example uses `Playwright#create`, which internally uses Pipe (stdin/stdout) transport for Playwright-protocol messaging. Instead, **just use `Playwright#connect_to_playwright_server(endpoint)`** for WebSocket transport.
|
39
|
+
|
40
|
+
```ruby {3}
|
41
|
+
require 'playwright'
|
42
|
+
|
43
|
+
Playwright.connect_to_playwright_server('wss://example.com:8888/ws') do |playwright|
|
44
|
+
playwright.chromium.launch do |browser|
|
45
|
+
page = browser.new_page
|
46
|
+
page.goto('https://github.com/microsoft/playwright')
|
47
|
+
page.screenshot(path: 'github-microsoft-playwright.png')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
`wss://example.com:8888/ws` is an example of endpoint URL of the Playwright server. In local development environment, it is typically `"ws://127.0.0.1:#{port}/ws"`.
|
53
|
+
|
54
|
+
## Playwright server
|
55
|
+
|
56
|
+
With the [official Docker image](https://hub.docker.com/_/microsoft-playwright) or in the local development environment with Node.js, just execute `npx playwright install && npx playwright run-server $PORT`. (`$PORT` is a port number of the server)
|
57
|
+
|
58
|
+
If custom Docker image is preferred, build it as follows:
|
59
|
+
|
60
|
+
```Dockerfile
|
61
|
+
FROM mcr.microsoft.com/playwright:focal
|
62
|
+
|
63
|
+
WORKDIR /root
|
64
|
+
RUN npm install playwright@1.12.3 && ./node_modules/.bin/playwright install
|
65
|
+
|
66
|
+
ENV PORT 8888
|
67
|
+
CMD ["./node_modules/.bin/playwright", "run-server", "$PORT"]
|
68
|
+
```
|
69
|
+
|
70
|
+
## Debugging for connection
|
71
|
+
|
72
|
+
The client and server are really quiet. This chapter shows how to check if the communication on the WebSocket works well or not.
|
73
|
+
|
74
|
+
### Show JSON message on client
|
75
|
+
|
76
|
+
Just set an environment variable `DEBUG=1`.
|
77
|
+
|
78
|
+
```
|
79
|
+
DEBUG=1 bundle exec ruby some-automation-with-playwright.rb
|
80
|
+
```
|
81
|
+
|
82
|
+
|
83
|
+
### Enable verbose logging on server
|
84
|
+
|
85
|
+
Just set an environment variable `DEBUG=pw:*` or `DEBUG=pw:server`
|
86
|
+
|
87
|
+
```
|
88
|
+
DEBUG=pw:* npx playwright run-server 8888
|
89
|
+
```
|
90
|
+
|
91
|
+
See [the official documentation](https://playwright.dev/docs/debug/#verbose-api-logs) for details.
|
@@ -1,3 +1,7 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 5
|
3
|
+
---
|
4
|
+
|
1
5
|
# Semi-automation
|
2
6
|
|
3
7
|
Playwright Browser context is isolated and not persisted by default. But we can also use persistent browser context using [BrowserType#launch_persistent_context](/docs/api/browser_type#launch_persistent_context).
|
@@ -38,7 +38,6 @@
|
|
38
38
|
* abort
|
39
39
|
* continue
|
40
40
|
* fulfill
|
41
|
-
* ~~intercept~~
|
42
41
|
* request
|
43
42
|
|
44
43
|
## WebSocket
|
@@ -138,6 +137,7 @@
|
|
138
137
|
* content
|
139
138
|
* dblclick
|
140
139
|
* dispatch_event
|
140
|
+
* drag_and_drop
|
141
141
|
* eval_on_selector
|
142
142
|
* eval_on_selector_all
|
143
143
|
* evaluate
|
@@ -218,6 +218,7 @@
|
|
218
218
|
* context
|
219
219
|
* dblclick
|
220
220
|
* dispatch_event
|
221
|
+
* drag_and_drop
|
221
222
|
* emulate_media
|
222
223
|
* eval_on_selector
|
223
224
|
* eval_on_selector_all
|
@@ -8,7 +8,7 @@ module Playwright
|
|
8
8
|
|
9
9
|
private def after_initialize
|
10
10
|
@pages = Set.new
|
11
|
-
@routes =
|
11
|
+
@routes = []
|
12
12
|
@bindings = {}
|
13
13
|
@timeout_settings = TimeoutSettings.new
|
14
14
|
|
@@ -210,8 +210,8 @@ module Playwright
|
|
210
210
|
end
|
211
211
|
|
212
212
|
def route(url, handler)
|
213
|
-
entry = RouteHandlerEntry.new(url, handler)
|
214
|
-
@routes
|
213
|
+
entry = RouteHandlerEntry.new(url, base_url, handler)
|
214
|
+
@routes.unshift(entry)
|
215
215
|
if @routes.count >= 1
|
216
216
|
@channel.send_message_to_server('setNetworkInterceptionEnabled', enabled: true)
|
217
217
|
end
|
@@ -275,5 +275,9 @@ module Playwright
|
|
275
275
|
private def has_record_video_option?
|
276
276
|
@options.key?(:recordVideo)
|
277
277
|
end
|
278
|
+
|
279
|
+
private def base_url
|
280
|
+
@options[:baseURL]
|
281
|
+
end
|
278
282
|
end
|
279
283
|
end
|
@@ -71,7 +71,7 @@ module Playwright
|
|
71
71
|
|
72
72
|
predicate =
|
73
73
|
if url
|
74
|
-
matcher = UrlMatcher.new(url)
|
74
|
+
matcher = UrlMatcher.new(url, base_url: @page.context.send(:base_url))
|
75
75
|
->(event) { event['error'] || matcher.match?(event['url']) }
|
76
76
|
else
|
77
77
|
->(_) { true }
|
@@ -99,7 +99,7 @@ module Playwright
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def wait_for_url(url, timeout: nil, waitUntil: nil)
|
102
|
-
matcher = UrlMatcher.new(url)
|
102
|
+
matcher = UrlMatcher.new(url, base_url: @page.context.send(:base_url))
|
103
103
|
if matcher.match?(@url)
|
104
104
|
wait_for_load_state(state: waitUntil, timeout: timeout)
|
105
105
|
else
|
@@ -293,6 +293,26 @@ module Playwright
|
|
293
293
|
nil
|
294
294
|
end
|
295
295
|
|
296
|
+
def drag_and_drop(
|
297
|
+
source,
|
298
|
+
target,
|
299
|
+
force: nil,
|
300
|
+
noWaitAfter: nil,
|
301
|
+
timeout: nil,
|
302
|
+
trial: nil)
|
303
|
+
params = {
|
304
|
+
source: source,
|
305
|
+
target: target,
|
306
|
+
force: force,
|
307
|
+
noWaitAfter: noWaitAfter,
|
308
|
+
timeout: timeout,
|
309
|
+
trial: trial,
|
310
|
+
}.compact
|
311
|
+
@channel.send_message_to_server('dragAndDrop', params)
|
312
|
+
|
313
|
+
nil
|
314
|
+
end
|
315
|
+
|
296
316
|
def dblclick(
|
297
317
|
selector,
|
298
318
|
button: nil,
|
@@ -22,7 +22,7 @@ module Playwright
|
|
22
22
|
end
|
23
23
|
@closed = false
|
24
24
|
@bindings = {}
|
25
|
-
@routes =
|
25
|
+
@routes = []
|
26
26
|
|
27
27
|
@main_frame = ChannelOwners::Frame.from(@initializer['mainFrame'])
|
28
28
|
@main_frame.send(:update_page_from_page, self)
|
@@ -184,15 +184,8 @@ module Playwright
|
|
184
184
|
if name
|
185
185
|
@frames.find { |f| f.name == name }
|
186
186
|
elsif url
|
187
|
-
|
188
|
-
|
189
|
-
when String
|
190
|
-
@frames.find { |f| f.url == url }
|
191
|
-
when Regexp
|
192
|
-
@frames.find { |f| url.match?(f.url) }
|
193
|
-
else
|
194
|
-
raise NotImplementedError.new('Page#frame with url is not completely implemented yet')
|
195
|
-
end
|
187
|
+
matcher = UrlMatcher.new(url, base_url: @browser_context.send(:base_url))
|
188
|
+
@frames.find { |f| matcher.match?(f.url) }
|
196
189
|
else
|
197
190
|
raise ArgumentError.new('Either name or url matcher should be specified')
|
198
191
|
end
|
@@ -377,8 +370,8 @@ module Playwright
|
|
377
370
|
end
|
378
371
|
|
379
372
|
def route(url, handler)
|
380
|
-
entry = RouteHandlerEntry.new(url, handler)
|
381
|
-
@routes
|
373
|
+
entry = RouteHandlerEntry.new(url, @browser_context.send(:base_url), handler)
|
374
|
+
@routes.unshift(entry)
|
382
375
|
if @routes.count >= 1
|
383
376
|
@channel.send_message_to_server('setNetworkInterceptionEnabled', enabled: true)
|
384
377
|
end
|
@@ -463,6 +456,23 @@ module Playwright
|
|
463
456
|
)
|
464
457
|
end
|
465
458
|
|
459
|
+
def drag_and_drop(
|
460
|
+
source,
|
461
|
+
target,
|
462
|
+
force: nil,
|
463
|
+
noWaitAfter: nil,
|
464
|
+
timeout: nil,
|
465
|
+
trial: nil)
|
466
|
+
|
467
|
+
@main_frame.drag_and_drop(
|
468
|
+
source,
|
469
|
+
target,
|
470
|
+
force: force,
|
471
|
+
noWaitAfter: noWaitAfter,
|
472
|
+
timeout: timeout,
|
473
|
+
trial: trial)
|
474
|
+
end
|
475
|
+
|
466
476
|
def dblclick(
|
467
477
|
selector,
|
468
478
|
button: nil,
|
@@ -759,7 +769,7 @@ module Playwright
|
|
759
769
|
predicate =
|
760
770
|
case urlOrPredicate
|
761
771
|
when String, Regexp
|
762
|
-
url_matcher = UrlMatcher.new(urlOrPredicate)
|
772
|
+
url_matcher = UrlMatcher.new(urlOrPredicate, base_url: @browser_context.send(:base_url))
|
763
773
|
-> (req){ url_matcher.match?(req.url) }
|
764
774
|
when Proc
|
765
775
|
urlOrPredicate
|
@@ -778,7 +788,7 @@ module Playwright
|
|
778
788
|
predicate =
|
779
789
|
case urlOrPredicate
|
780
790
|
when String, Regexp
|
781
|
-
url_matcher = UrlMatcher.new(urlOrPredicate)
|
791
|
+
url_matcher = UrlMatcher.new(urlOrPredicate, base_url: @browser_context.send(:base_url))
|
782
792
|
-> (req){ url_matcher.match?(req.url) }
|
783
793
|
when Proc
|
784
794
|
urlOrPredicate
|
data/lib/playwright/download.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Playwright
|
2
2
|
class RouteHandlerEntry
|
3
3
|
# @param url [String]
|
4
|
+
# @param base_url [String|nil]
|
4
5
|
# @param handler [Proc]
|
5
|
-
def initialize(url, handler)
|
6
|
+
def initialize(url, base_url, handler)
|
6
7
|
@url_value = url
|
7
|
-
@url_matcher = UrlMatcher.new(url)
|
8
|
+
@url_matcher = UrlMatcher.new(url, base_url: base_url)
|
8
9
|
@handler = handler
|
9
10
|
end
|
10
11
|
|
@@ -1,19 +1,29 @@
|
|
1
1
|
module Playwright
|
2
2
|
class UrlMatcher
|
3
3
|
# @param url [String|Regexp]
|
4
|
-
|
4
|
+
# @param base_url [String|nil]
|
5
|
+
def initialize(url, base_url:)
|
5
6
|
@url = url
|
7
|
+
@base_url = base_url
|
6
8
|
end
|
7
9
|
|
8
10
|
def match?(target_url)
|
9
11
|
case @url
|
10
12
|
when String
|
11
|
-
|
13
|
+
joined_url == target_url || File.fnmatch?(@url, target_url)
|
12
14
|
when Regexp
|
13
15
|
@url.match?(target_url)
|
14
16
|
else
|
15
17
|
false
|
16
18
|
end
|
17
19
|
end
|
20
|
+
|
21
|
+
private def joined_url
|
22
|
+
if @base_url && !@url.start_with?('*')
|
23
|
+
URI.join(@base_url, @url).to_s
|
24
|
+
else
|
25
|
+
@url
|
26
|
+
end
|
27
|
+
end
|
18
28
|
end
|
19
29
|
end
|
data/lib/playwright/version.rb
CHANGED
@@ -40,6 +40,7 @@ module Playwright
|
|
40
40
|
# Launches Chrome browser on the device, and returns its persistent context.
|
41
41
|
def launch_browser(
|
42
42
|
acceptDownloads: nil,
|
43
|
+
baseURL: nil,
|
43
44
|
bypassCSP: nil,
|
44
45
|
colorScheme: nil,
|
45
46
|
command: nil,
|
@@ -65,7 +66,7 @@ module Playwright
|
|
65
66
|
userAgent: nil,
|
66
67
|
viewport: nil,
|
67
68
|
&block)
|
68
|
-
wrap_impl(@impl.launch_browser(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), command: unwrap_impl(command), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
69
|
+
wrap_impl(@impl.launch_browser(acceptDownloads: unwrap_impl(acceptDownloads), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), command: unwrap_impl(command), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
69
70
|
end
|
70
71
|
|
71
72
|
# Performs a long tap on the widget defined by `selector`.
|
@@ -65,6 +65,7 @@ module Playwright
|
|
65
65
|
# ```
|
66
66
|
def new_context(
|
67
67
|
acceptDownloads: nil,
|
68
|
+
baseURL: nil,
|
68
69
|
bypassCSP: nil,
|
69
70
|
colorScheme: nil,
|
70
71
|
deviceScaleFactor: nil,
|
@@ -91,7 +92,7 @@ module Playwright
|
|
91
92
|
userAgent: nil,
|
92
93
|
viewport: nil,
|
93
94
|
&block)
|
94
|
-
wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
95
|
+
wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
95
96
|
end
|
96
97
|
|
97
98
|
# Creates a new page in a new browser context. Closing this page will close the context as well.
|
@@ -101,6 +102,7 @@ module Playwright
|
|
101
102
|
# [`method: BrowserContext.newPage`] to control their exact life times.
|
102
103
|
def new_page(
|
103
104
|
acceptDownloads: nil,
|
105
|
+
baseURL: nil,
|
104
106
|
bypassCSP: nil,
|
105
107
|
colorScheme: nil,
|
106
108
|
deviceScaleFactor: nil,
|
@@ -127,10 +129,12 @@ module Playwright
|
|
127
129
|
userAgent: nil,
|
128
130
|
viewport: nil,
|
129
131
|
&block)
|
130
|
-
wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
132
|
+
wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
131
133
|
end
|
132
134
|
|
133
|
-
# > NOTE:
|
135
|
+
# > NOTE: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool)
|
136
|
+
# which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](../trace-viewer) could be
|
137
|
+
# found [here](./class-tracing).
|
134
138
|
#
|
135
139
|
# You can use [`method: Browser.startTracing`] and [`method: Browser.stopTracing`] to create a trace file that can be
|
136
140
|
# opened in Chrome DevTools performance panel.
|
@@ -144,7 +148,9 @@ module Playwright
|
|
144
148
|
wrap_impl(@impl.start_tracing(page: unwrap_impl(page), categories: unwrap_impl(categories), path: unwrap_impl(path), screenshots: unwrap_impl(screenshots)))
|
145
149
|
end
|
146
150
|
|
147
|
-
# > NOTE:
|
151
|
+
# > NOTE: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool)
|
152
|
+
# which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](../trace-viewer) could be
|
153
|
+
# found [here](./class-tracing).
|
148
154
|
#
|
149
155
|
# Returns the buffer with trace data.
|
150
156
|
def stop_tracing
|
@@ -96,6 +96,7 @@ module Playwright
|
|
96
96
|
userDataDir,
|
97
97
|
acceptDownloads: nil,
|
98
98
|
args: nil,
|
99
|
+
baseURL: nil,
|
99
100
|
bypassCSP: nil,
|
100
101
|
channel: nil,
|
101
102
|
chromiumSandbox: nil,
|
@@ -135,7 +136,7 @@ module Playwright
|
|
135
136
|
userAgent: nil,
|
136
137
|
viewport: nil,
|
137
138
|
&block)
|
138
|
-
wrap_impl(@impl.launch_persistent_context(unwrap_impl(userDataDir), acceptDownloads: unwrap_impl(acceptDownloads), args: unwrap_impl(args), bypassCSP: unwrap_impl(bypassCSP), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), hasTouch: unwrap_impl(hasTouch), headless: unwrap_impl(headless), httpCredentials: unwrap_impl(httpCredentials), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), timezoneId: unwrap_impl(timezoneId), tracesDir: unwrap_impl(tracesDir), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
139
|
+
wrap_impl(@impl.launch_persistent_context(unwrap_impl(userDataDir), acceptDownloads: unwrap_impl(acceptDownloads), args: unwrap_impl(args), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), hasTouch: unwrap_impl(hasTouch), headless: unwrap_impl(headless), httpCredentials: unwrap_impl(httpCredentials), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), timezoneId: unwrap_impl(timezoneId), tracesDir: unwrap_impl(tracesDir), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
139
140
|
end
|
140
141
|
|
141
142
|
# Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
|
data/lib/playwright_api/frame.rb
CHANGED
@@ -160,6 +160,16 @@ module Playwright
|
|
160
160
|
wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
|
161
161
|
end
|
162
162
|
|
163
|
+
def drag_and_drop(
|
164
|
+
source,
|
165
|
+
target,
|
166
|
+
force: nil,
|
167
|
+
noWaitAfter: nil,
|
168
|
+
timeout: nil,
|
169
|
+
trial: nil)
|
170
|
+
wrap_impl(@impl.drag_and_drop(unwrap_impl(source), unwrap_impl(target), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
171
|
+
end
|
172
|
+
|
163
173
|
# Returns the return value of `expression`.
|
164
174
|
#
|
165
175
|
# The method finds an element matching the specified selector within the frame and passes it as a first argument to
|
data/lib/playwright_api/page.rb
CHANGED
@@ -233,6 +233,16 @@ module Playwright
|
|
233
233
|
wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
|
234
234
|
end
|
235
235
|
|
236
|
+
def drag_and_drop(
|
237
|
+
source,
|
238
|
+
target,
|
239
|
+
force: nil,
|
240
|
+
noWaitAfter: nil,
|
241
|
+
timeout: nil,
|
242
|
+
trial: nil)
|
243
|
+
wrap_impl(@impl.drag_and_drop(unwrap_impl(source), unwrap_impl(target), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
|
244
|
+
end
|
245
|
+
|
236
246
|
# This method changes the `CSS media type` through the `media` argument, and/or the `'prefers-colors-scheme'` media
|
237
247
|
# feature, using the `colorScheme` argument.
|
238
248
|
#
|
@@ -1149,7 +1159,7 @@ module Playwright
|
|
1149
1159
|
wrap_impl(@impl.expect_popup(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
1150
1160
|
end
|
1151
1161
|
|
1152
|
-
# Waits for the matching request and returns it.
|
1162
|
+
# Waits for the matching request and returns it. See [waiting for event](./events.md#waiting-for-event) for more details
|
1153
1163
|
# about events.
|
1154
1164
|
#
|
1155
1165
|
# ```python sync
|
data/lib/playwright_api/route.rb
CHANGED
@@ -51,11 +51,6 @@ module Playwright
|
|
51
51
|
wrap_impl(@impl.fulfill(body: unwrap_impl(body), contentType: unwrap_impl(contentType), headers: unwrap_impl(headers), path: unwrap_impl(path), status: unwrap_impl(status)))
|
52
52
|
end
|
53
53
|
|
54
|
-
# Continues route's request with optional overrides and intercepts response.
|
55
|
-
def intercept(headers: nil, method: nil, postData: nil, url: nil)
|
56
|
-
raise NotImplementedError.new('intercept is not implemented yet.')
|
57
|
-
end
|
58
|
-
|
59
54
|
# A request to be routed.
|
60
55
|
def request
|
61
56
|
wrap_impl(@impl.request)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playwright-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -243,6 +243,7 @@ files:
|
|
243
243
|
- documentation/docs/article/guides/_category_.yml
|
244
244
|
- documentation/docs/article/guides/download_playwright_driver.md
|
245
245
|
- documentation/docs/article/guides/launch_browser.md
|
246
|
+
- documentation/docs/article/guides/playwright_on_alpine_linux.md
|
246
247
|
- documentation/docs/article/guides/rails_integration.md
|
247
248
|
- documentation/docs/article/guides/recording_video.md
|
248
249
|
- documentation/docs/article/guides/semi_automation.md
|