playwright-ruby-client 1.39.0 → 1.39.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 +9 -13
- data/documentation/docs/api/browser_context.md +32 -51
- data/documentation/docs/api/browser_type.md +7 -12
- data/documentation/docs/api/dialog.md +15 -18
- data/documentation/docs/api/download.md +9 -10
- data/documentation/docs/api/element_handle.md +5 -6
- data/documentation/docs/api/frame.md +24 -54
- data/documentation/docs/api/locator.md +20 -22
- data/documentation/docs/api/locator_assertions.md +642 -0
- data/documentation/docs/api/page.md +48 -101
- data/documentation/docs/api/playwright.md +20 -23
- data/documentation/docs/api/selectors.md +29 -34
- data/documentation/docs/include/api_coverage.md +43 -0
- data/lib/playwright/channel.rb +1 -1
- data/lib/playwright/errors.rb +2 -0
- data/lib/playwright/javascript/value_serializer.rb +1 -1
- data/lib/playwright/locator_assertions_impl.rb +417 -0
- data/lib/playwright/locator_impl.rb +24 -5
- data/lib/playwright/test.rb +68 -0
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/locator.rb +5 -0
- data/lib/playwright_api/locator_assertions.rb +551 -0
- data/sig/playwright.rbs +43 -0
- metadata +6 -2
@@ -12,21 +12,12 @@ instance might have multiple [Page](./page) instances.
|
|
12
12
|
|
13
13
|
This example creates a page, navigates it to a URL, and then saves a screenshot:
|
14
14
|
|
15
|
-
```
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
context = browser.new_context()
|
22
|
-
page = context.new_page()
|
23
|
-
page.goto("https://example.com")
|
24
|
-
page.screenshot(path="screenshot.png")
|
25
|
-
browser.close()
|
26
|
-
|
27
|
-
with sync_playwright() as playwright:
|
28
|
-
run(playwright)
|
29
|
-
|
15
|
+
```ruby
|
16
|
+
playwright.webkit.launch do |browser|
|
17
|
+
page = browser.new_page
|
18
|
+
page.goto('https://example.com/')
|
19
|
+
page.screenshot(path: 'screenshot.png')
|
20
|
+
end
|
30
21
|
```
|
31
22
|
|
32
23
|
The Page class emits various events (described below) which can be handled using any of Node's native
|
@@ -471,29 +462,18 @@ See [BrowserContext#expose_binding](./browser_context#expose_binding) for the co
|
|
471
462
|
|
472
463
|
An example of exposing page URL to all frames in a page:
|
473
464
|
|
474
|
-
```
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
document.querySelector('div').textContent = await window.pageURL();
|
487
|
-
}
|
488
|
-
</script>
|
489
|
-
<button onclick="onClick()">Click me</button>
|
490
|
-
<div></div>
|
491
|
-
""")
|
492
|
-
page.click("button")
|
493
|
-
|
494
|
-
with sync_playwright() as playwright:
|
495
|
-
run(playwright)
|
496
|
-
|
465
|
+
```ruby
|
466
|
+
page.expose_binding("pageURL", ->(source) { source[:page].url })
|
467
|
+
page.content = <<~HTML
|
468
|
+
<script>
|
469
|
+
async function onClick() {
|
470
|
+
document.querySelector('div').textContent = await window.pageURL();
|
471
|
+
}
|
472
|
+
</script>
|
473
|
+
<button onclick="onClick()">Click me</button>
|
474
|
+
<div></div>
|
475
|
+
HTML
|
476
|
+
page.locator("button").click
|
497
477
|
```
|
498
478
|
|
499
479
|
An example of passing an element handle:
|
@@ -537,35 +517,24 @@ See [BrowserContext#expose_function](./browser_context#expose_function) for cont
|
|
537
517
|
|
538
518
|
An example of adding a `sha256` function to the page:
|
539
519
|
|
540
|
-
```
|
541
|
-
|
542
|
-
from playwright.sync_api import sync_playwright, Playwright
|
543
|
-
|
544
|
-
def sha256(text):
|
545
|
-
m = hashlib.sha256()
|
546
|
-
m.update(bytes(text, "utf8"))
|
547
|
-
return m.hexdigest()
|
548
|
-
|
549
|
-
|
550
|
-
def run(playwright: Playwright):
|
551
|
-
webkit = playwright.webkit
|
552
|
-
browser = webkit.launch(headless=False)
|
553
|
-
page = browser.new_page()
|
554
|
-
page.expose_function("sha256", sha256)
|
555
|
-
page.set_content("""
|
556
|
-
<script>
|
557
|
-
async function onClick() {
|
558
|
-
document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');
|
559
|
-
}
|
560
|
-
</script>
|
561
|
-
<button onclick="onClick()">Click me</button>
|
562
|
-
<div></div>
|
563
|
-
""")
|
564
|
-
page.click("button")
|
520
|
+
```ruby
|
521
|
+
require 'digest'
|
565
522
|
|
566
|
-
|
567
|
-
|
523
|
+
def sha256(text)
|
524
|
+
Digest::SHA256.hexdigest(text)
|
525
|
+
end
|
568
526
|
|
527
|
+
page.expose_function("sha256", method(:sha256))
|
528
|
+
page.content = <<~HTML
|
529
|
+
<script>
|
530
|
+
async function onClick() {
|
531
|
+
document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');
|
532
|
+
}
|
533
|
+
</script>
|
534
|
+
<button onclick="onClick()">Click me</button>
|
535
|
+
<div></div>
|
536
|
+
HTML
|
537
|
+
page.locator("button").click
|
569
538
|
```
|
570
539
|
|
571
540
|
## fill
|
@@ -1355,14 +1324,13 @@ Triggers a `change` and `input` event once all the provided options have been se
|
|
1355
1324
|
|
1356
1325
|
**Usage**
|
1357
1326
|
|
1358
|
-
```
|
1359
|
-
#
|
1360
|
-
page.select_option("select#colors", "blue")
|
1327
|
+
```ruby
|
1328
|
+
# single selection matching the value
|
1329
|
+
page.select_option("select#colors", value: "blue")
|
1361
1330
|
# single selection matching both the label
|
1362
|
-
page.select_option("select#colors", label
|
1331
|
+
page.select_option("select#colors", label: "blue")
|
1363
1332
|
# multiple selection
|
1364
|
-
page.select_option("select#colors", value
|
1365
|
-
|
1333
|
+
page.select_option("select#colors", value: ["red", "green", "blue"])
|
1366
1334
|
```
|
1367
1335
|
|
1368
1336
|
## set_checked
|
@@ -1676,20 +1644,9 @@ Returns when the `expression` returns a truthy value. It resolves to a JSHandle
|
|
1676
1644
|
|
1677
1645
|
The [Page#wait_for_function](./page#wait_for_function) can be used to observe viewport size change:
|
1678
1646
|
|
1679
|
-
```
|
1680
|
-
|
1681
|
-
|
1682
|
-
def run(playwright: Playwright):
|
1683
|
-
webkit = playwright.webkit
|
1684
|
-
browser = webkit.launch()
|
1685
|
-
page = browser.new_page()
|
1686
|
-
page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
|
1687
|
-
page.wait_for_function("() => window.x > 0")
|
1688
|
-
browser.close()
|
1689
|
-
|
1690
|
-
with sync_playwright() as playwright:
|
1691
|
-
run(playwright)
|
1692
|
-
|
1647
|
+
```ruby
|
1648
|
+
page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
|
1649
|
+
page.wait_for_function("() => window.x > 0")
|
1693
1650
|
```
|
1694
1651
|
|
1695
1652
|
To pass an argument to the predicate of [Page#wait_for_function](./page#wait_for_function) function:
|
@@ -1857,22 +1814,12 @@ function will throw.
|
|
1857
1814
|
|
1858
1815
|
This method works across navigations:
|
1859
1816
|
|
1860
|
-
```
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
page = browser.new_page()
|
1867
|
-
for current_url in ["https://google.com", "https://bbc.com"]:
|
1868
|
-
page.goto(current_url, wait_until="domcontentloaded")
|
1869
|
-
element = page.wait_for_selector("img")
|
1870
|
-
print("Loaded image: " + str(element.get_attribute("src")))
|
1871
|
-
browser.close()
|
1872
|
-
|
1873
|
-
with sync_playwright() as playwright:
|
1874
|
-
run(playwright)
|
1875
|
-
|
1817
|
+
```ruby
|
1818
|
+
%w[https://google.com https://bbc.com].each do |current_url|
|
1819
|
+
page.goto(current_url, waitUntil: "domcontentloaded")
|
1820
|
+
element = page.wait_for_selector("img")
|
1821
|
+
puts "Loaded image: #{element["src"]}"
|
1822
|
+
end
|
1876
1823
|
```
|
1877
1824
|
|
1878
1825
|
## wait_for_timeout
|
@@ -8,20 +8,19 @@ sidebar_position: 10
|
|
8
8
|
Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
|
9
9
|
to drive automation:
|
10
10
|
|
11
|
-
```
|
12
|
-
|
11
|
+
```ruby
|
12
|
+
require 'playwright'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
page = browser.new_page
|
18
|
-
page.goto(
|
19
|
-
# other actions...
|
20
|
-
browser.close()
|
14
|
+
Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwright|
|
15
|
+
chromium = playwright.chromium # or "firefox" or "webkit".
|
16
|
+
chromium.launch do |browser|
|
17
|
+
page = browser.new_page
|
18
|
+
page.goto('https://example.com/')
|
21
19
|
|
22
|
-
|
23
|
-
run(playwright)
|
20
|
+
# other actions
|
24
21
|
|
22
|
+
end
|
23
|
+
end
|
25
24
|
```
|
26
25
|
|
27
26
|
## chromium
|
@@ -34,22 +33,20 @@ This object can be used to launch or connect to Chromium, returning instances of
|
|
34
33
|
|
35
34
|
Returns a dictionary of devices to be used with [Browser#new_context](./browser#new_context) or [Browser#new_page](./browser#new_page).
|
36
35
|
|
37
|
-
```
|
38
|
-
|
36
|
+
```ruby
|
37
|
+
require 'playwright'
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
browser = webkit.launch()
|
39
|
+
Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwright|
|
40
|
+
iphone = playwright.devices["iPhone 6"]
|
41
|
+
playwright.webkit.launch do |browser|
|
44
42
|
context = browser.new_context(**iphone)
|
45
|
-
page = context.new_page
|
46
|
-
page.goto(
|
47
|
-
# other actions...
|
48
|
-
browser.close()
|
43
|
+
page = context.new_page
|
44
|
+
page.goto('https://example.com/')
|
49
45
|
|
50
|
-
|
51
|
-
run(playwright)
|
46
|
+
# other actions
|
52
47
|
|
48
|
+
end
|
49
|
+
end
|
53
50
|
```
|
54
51
|
|
55
52
|
## firefox
|
@@ -21,38 +21,33 @@ Selectors must be registered before creating the page.
|
|
21
21
|
|
22
22
|
An example of registering selector engine that queries elements based on a tag name:
|
23
23
|
|
24
|
-
```
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
browser.close()
|
54
|
-
|
55
|
-
with sync_playwright() as playwright:
|
56
|
-
run(playwright)
|
57
|
-
|
24
|
+
```ruby
|
25
|
+
tag_selector = <<~JAVASCRIPT
|
26
|
+
{
|
27
|
+
// Returns the first element matching given selector in the root's subtree.
|
28
|
+
query(root, selector) {
|
29
|
+
return root.querySelector(selector);
|
30
|
+
},
|
31
|
+
// Returns all elements matching given selector in the root's subtree.
|
32
|
+
queryAll(root, selector) {
|
33
|
+
return Array.from(root.querySelectorAll(selector));
|
34
|
+
}
|
35
|
+
}
|
36
|
+
JAVASCRIPT
|
37
|
+
|
38
|
+
# Register the engine. Selectors will be prefixed with "tag=".
|
39
|
+
playwright.selectors.register("tag", script: tag_selector)
|
40
|
+
playwright.chromium.launch do |browser|
|
41
|
+
page = browser.new_page
|
42
|
+
page.content = '<div><button>Click me</button></div>'
|
43
|
+
|
44
|
+
# Use the selector prefixed with its name.
|
45
|
+
button = page.locator('tag=button')
|
46
|
+
# Combine it with other selector engines.
|
47
|
+
page.locator('tag=div').get_by_text('Click me').click
|
48
|
+
|
49
|
+
# Can use it in any methods supporting selectors.
|
50
|
+
button_count = page.locator('tag=button').count
|
51
|
+
button_count # => 1
|
52
|
+
end
|
58
53
|
```
|
@@ -527,6 +527,49 @@
|
|
527
527
|
|
528
528
|
* ~~new_context~~
|
529
529
|
|
530
|
+
## LocatorAssertions
|
531
|
+
|
532
|
+
* not_to_be_attached
|
533
|
+
* not_to_be_checked
|
534
|
+
* not_to_be_disabled
|
535
|
+
* not_to_be_editable
|
536
|
+
* not_to_be_empty
|
537
|
+
* not_to_be_enabled
|
538
|
+
* not_to_be_focused
|
539
|
+
* not_to_be_hidden
|
540
|
+
* not_to_be_in_viewport
|
541
|
+
* not_to_be_visible
|
542
|
+
* not_to_contain_text
|
543
|
+
* not_to_have_attribute
|
544
|
+
* not_to_have_class
|
545
|
+
* not_to_have_count
|
546
|
+
* not_to_have_css
|
547
|
+
* not_to_have_id
|
548
|
+
* not_to_have_js_property
|
549
|
+
* not_to_have_text
|
550
|
+
* not_to_have_value
|
551
|
+
* not_to_have_values
|
552
|
+
* to_be_attached
|
553
|
+
* to_be_checked
|
554
|
+
* to_be_disabled
|
555
|
+
* to_be_editable
|
556
|
+
* to_be_empty
|
557
|
+
* to_be_enabled
|
558
|
+
* to_be_focused
|
559
|
+
* to_be_hidden
|
560
|
+
* to_be_in_viewport
|
561
|
+
* to_be_visible
|
562
|
+
* to_contain_text
|
563
|
+
* to_have_attribute
|
564
|
+
* to_have_class
|
565
|
+
* to_have_count
|
566
|
+
* to_have_css
|
567
|
+
* to_have_id
|
568
|
+
* to_have_js_property
|
569
|
+
* to_have_text
|
570
|
+
* to_have_value
|
571
|
+
* to_have_values
|
572
|
+
|
530
573
|
## Android
|
531
574
|
|
532
575
|
* ~~connect~~
|
data/lib/playwright/channel.rb
CHANGED
@@ -48,7 +48,7 @@ module Playwright
|
|
48
48
|
|
49
49
|
private def with_logging(&block)
|
50
50
|
locations = caller_locations
|
51
|
-
first_api_call_location_idx = locations.index { |loc| loc.absolute_path
|
51
|
+
first_api_call_location_idx = locations.index { |loc| loc.absolute_path&.include?('playwright_api') }
|
52
52
|
unless first_api_call_location_idx
|
53
53
|
return block.call(nil)
|
54
54
|
end
|
data/lib/playwright/errors.rb
CHANGED