Skip to content

Commit 11d5012

Browse files
authored
chore(release-1.14): update driver, support context-level strict (#573)
1 parent d709d9e commit 11d5012

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

playwright/src/main/java/com/microsoft/playwright/Browser.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ class NewContextOptions {
174174
* state.
175175
*/
176176
public Path storageStatePath;
177+
/**
178+
* It specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
179+
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
180+
* more about the strict mode.
181+
*/
182+
public Boolean strictSelectors;
177183
/**
178184
* Changes the timezone of the context. See <a
179185
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
@@ -300,6 +306,10 @@ public NewContextOptions setStorageStatePath(Path storageStatePath) {
300306
this.storageStatePath = storageStatePath;
301307
return this;
302308
}
309+
public NewContextOptions setStrictSelectors(boolean strictSelectors) {
310+
this.strictSelectors = strictSelectors;
311+
return this;
312+
}
303313
public NewContextOptions setTimezoneId(String timezoneId) {
304314
this.timezoneId = timezoneId;
305315
return this;
@@ -435,6 +445,12 @@ class NewPageOptions {
435445
* state.
436446
*/
437447
public Path storageStatePath;
448+
/**
449+
* It specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
450+
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
451+
* more about the strict mode.
452+
*/
453+
public Boolean strictSelectors;
438454
/**
439455
* Changes the timezone of the context. See <a
440456
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
@@ -561,6 +577,10 @@ public NewPageOptions setStorageStatePath(Path storageStatePath) {
561577
this.storageStatePath = storageStatePath;
562578
return this;
563579
}
580+
public NewPageOptions setStrictSelectors(boolean strictSelectors) {
581+
this.strictSelectors = strictSelectors;
582+
return this;
583+
}
564584
public NewPageOptions setTimezoneId(String timezoneId) {
565585
this.timezoneId = timezoneId;
566586
return this;

playwright/src/main/java/com/microsoft/playwright/BrowserType.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ class LaunchPersistentContextOptions {
440440
* Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
441441
*/
442442
public Double slowMo;
443+
/**
444+
* It specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
445+
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
446+
* more about the strict mode.
447+
*/
448+
public Boolean strictSelectors;
443449
/**
444450
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to
445451
* disable timeout.
@@ -628,6 +634,10 @@ public LaunchPersistentContextOptions setSlowMo(double slowMo) {
628634
this.slowMo = slowMo;
629635
return this;
630636
}
637+
public LaunchPersistentContextOptions setStrictSelectors(boolean strictSelectors) {
638+
this.strictSelectors = strictSelectors;
639+
return this;
640+
}
631641
public LaunchPersistentContextOptions setTimeout(double timeout) {
632642
this.timeout = timeout;
633643
return this;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.microsoft.playwright;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.junit.jupiter.api.Assertions.*;
22+
23+
public class TestBrowserContextStrict extends TestBase {
24+
@Override
25+
BrowserContext createContext() {
26+
return browser.newContext(new Browser.NewContextOptions().setStrictSelectors(true));
27+
}
28+
29+
@Test
30+
void shouldNotFailPageTextContentInNonStrictMode() {
31+
try (BrowserContext context = browser.newContext()) {
32+
Page page = context.newPage();
33+
page.setContent("<span>span1</span><div><span>target</span></div>");
34+
assertEquals("span1", page.textContent("span"));
35+
}
36+
}
37+
38+
@Test
39+
void shouldFailPageTextContentInStrictMode() {
40+
page.setContent("<span>span1</span><div><span>target</span></div>");
41+
try {
42+
page.textContent("span");
43+
fail("did not throw");
44+
} catch (PlaywrightException e) {
45+
assertTrue(e.getMessage().contains("strict mode violation"));
46+
}
47+
}
48+
49+
@Test
50+
void shouldOptOutOfStrictMode() {
51+
page.setContent("<span>span1</span><div><span>target</span></div>");
52+
assertEquals("span1", page.textContent("span", new Page.TextContentOptions().setStrict(false)));
53+
}
54+
}

scripts/CLI_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.14.0-1628878084000
1+
1.14.0-1629316514000

0 commit comments

Comments
 (0)