1
0
mirror of synced 2026-08-05 23:16:54 +00:00

chore(release-1.14): update driver, support context-level strict (#573)

This commit is contained in:
Yury Semikhatsky
2021-08-18 15:07:29 -07:00
committed by GitHub
parent d709d9e090
commit 11d50120b9
4 changed files with 85 additions and 1 deletions
@@ -174,6 +174,12 @@ public interface Browser extends AutoCloseable {
* state.
*/
public Path storageStatePath;
/**
* It specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
* more about the strict mode.
*/
public Boolean strictSelectors;
/**
* Changes the timezone of the context. See <a
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
@@ -300,6 +306,10 @@ public interface Browser extends AutoCloseable {
this.storageStatePath = storageStatePath;
return this;
}
public NewContextOptions setStrictSelectors(boolean strictSelectors) {
this.strictSelectors = strictSelectors;
return this;
}
public NewContextOptions setTimezoneId(String timezoneId) {
this.timezoneId = timezoneId;
return this;
@@ -435,6 +445,12 @@ public interface Browser extends AutoCloseable {
* state.
*/
public Path storageStatePath;
/**
* It specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
* more about the strict mode.
*/
public Boolean strictSelectors;
/**
* Changes the timezone of the context. See <a
* href="https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1">ICU's
@@ -561,6 +577,10 @@ public interface Browser extends AutoCloseable {
this.storageStatePath = storageStatePath;
return this;
}
public NewPageOptions setStrictSelectors(boolean strictSelectors) {
this.strictSelectors = strictSelectors;
return this;
}
public NewPageOptions setTimezoneId(String timezoneId) {
this.timezoneId = timezoneId;
return this;
@@ -440,6 +440,12 @@ public interface BrowserType {
* Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
*/
public Double slowMo;
/**
* It specified, enables strict selectors mode for this context. In the strict selectors mode all operations on selectors
* that imply single target DOM element will throw when more than one element matches the selector. See {@code Locator} to learn
* more about the strict mode.
*/
public Boolean strictSelectors;
/**
* Maximum time in milliseconds to wait for the browser instance to start. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to
* disable timeout.
@@ -628,6 +634,10 @@ public interface BrowserType {
this.slowMo = slowMo;
return this;
}
public LaunchPersistentContextOptions setStrictSelectors(boolean strictSelectors) {
this.strictSelectors = strictSelectors;
return this;
}
public LaunchPersistentContextOptions setTimeout(double timeout) {
this.timeout = timeout;
return this;
@@ -0,0 +1,54 @@
/*
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.playwright;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class TestBrowserContextStrict extends TestBase {
@Override
BrowserContext createContext() {
return browser.newContext(new Browser.NewContextOptions().setStrictSelectors(true));
}
@Test
void shouldNotFailPageTextContentInNonStrictMode() {
try (BrowserContext context = browser.newContext()) {
Page page = context.newPage();
page.setContent("<span>span1</span><div><span>target</span></div>");
assertEquals("span1", page.textContent("span"));
}
}
@Test
void shouldFailPageTextContentInStrictMode() {
page.setContent("<span>span1</span><div><span>target</span></div>");
try {
page.textContent("span");
fail("did not throw");
} catch (PlaywrightException e) {
assertTrue(e.getMessage().contains("strict mode violation"));
}
}
@Test
void shouldOptOutOfStrictMode() {
page.setContent("<span>span1</span><div><span>target</span></div>");
assertEquals("span1", page.textContent("span", new Page.TextContentOptions().setStrict(false)));
}
}
+1 -1
View File
@@ -1 +1 @@
1.14.0-1628878084000
1.14.0-1629316514000