Skip to content

Commit 98f082e

Browse files
committed
more changes
1 parent 0c42154 commit 98f082e

File tree

4 files changed

+139
-13
lines changed

4 files changed

+139
-13
lines changed

playwright/src/test/java/com/microsoft/playwright/TestElementHandleSelectText.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void shouldSelectTextarea() {
2828
ElementHandle textarea = page.querySelector("textarea");
2929
textarea.evaluate("textarea => textarea.value = 'some value'");
3030
textarea.selectText();
31-
if (isFirefox() || isWebKit()) {
31+
if (isFirefox()) {
3232
assertEquals(0, textarea.evaluate("el => el.selectionStart"));
3333
assertEquals(10, textarea.evaluate("el => el.selectionEnd"));
3434
} else {
@@ -42,7 +42,7 @@ void shouldSelectInput() {
4242
ElementHandle input = page.querySelector("input");
4343
input.evaluate("input => input.value = 'some value'");
4444
input.selectText();
45-
if (isFirefox() || isWebKit()) {
45+
if (isFirefox()) {
4646
assertEquals(0, input.evaluate("el => el.selectionStart"));
4747
assertEquals(10, input.evaluate("el => el.selectionEnd"));
4848
} else {

playwright/src/test/java/com/microsoft/playwright/TestPageRoute.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.microsoft.playwright;
1818

19-
import com.microsoft.playwright.options.Cookie;
19+
import com.microsoft.playwright.options.*;
2020
import org.junit.jupiter.api.Test;
2121
import org.junit.jupiter.api.condition.DisabledIf;
2222

@@ -110,7 +110,7 @@ void shouldUnrouteNonExistentPatternHandler() {
110110
}
111111

112112
@Test
113-
void shouldSupportQuestionMarkInGlobPattern() {
113+
void shouldNotSupportQuestionMarkInGlobPattern() {
114114
server.setRoute("/index", exchange -> {
115115
exchange.sendResponseHeaders(200, 0);
116116
try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) {
@@ -123,6 +123,18 @@ void shouldSupportQuestionMarkInGlobPattern() {
123123
writer.write("index123hello");
124124
}
125125
});
126+
server.setRoute("/index?hello", exchange -> {
127+
exchange.sendResponseHeaders(200, 0);
128+
try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) {
129+
writer.write("index?hello");
130+
}
131+
});
132+
server.setRoute("/index1hello", exchange -> {
133+
exchange.sendResponseHeaders(200, 0);
134+
try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) {
135+
writer.write("index1hello");
136+
}
137+
});
126138

127139
page.route("**/index?hello", route -> {
128140
route.fulfill(new Route.FulfillOptions().setBody("intercepted any character"));
@@ -140,6 +152,7 @@ void shouldSupportQuestionMarkInGlobPattern() {
140152

141153
page.navigate(server.PREFIX + "/index1hello");
142154
assertFalse(page.content().contains("intercepted any character"), page.content());
155+
assertTrue(page.content().contains("index1hello"), page.content());
143156

144157
page.navigate(server.PREFIX + "/index123hello");
145158
assertTrue(page.content().contains("index123hello"), page.content());

playwright/src/test/java/com/microsoft/playwright/TestPageSelectOption.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static java.util.Arrays.asList;
2626
import static java.util.Collections.emptyList;
2727
import static org.junit.jupiter.api.Assertions.*;
28+
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
2829

2930
public class TestPageSelectOption extends TestBase {
3031
@Test
@@ -238,4 +239,64 @@ void shouldWorkWhenReDefiningTopLevelEventClass() {
238239
assertEquals(asList("blue"), page.evaluate("() => window['result'].onChange"));
239240
}
240241

242+
@Test
243+
void shouldWaitForOptionToBeEnabled() {
244+
page.setContent(
245+
"<select disabled>\n" +
246+
" <option>one</option>\n" +
247+
" <option>two</option>\n" +
248+
"</select>\n" +
249+
"\n" +
250+
"<script>\n" +
251+
"function hydrate() {\n" +
252+
" const select = document.querySelector('select');\n" +
253+
" select.removeAttribute('disabled');\n" +
254+
" select.addEventListener('change', () => {\n" +
255+
" window['result'] = select.value;\n" +
256+
" });\n" +
257+
"}\n" +
258+
"</script>");
259+
260+
page.evaluate("() => setTimeout(hydrate, 1000)");
261+
page.locator("select").selectOption("two");
262+
263+
assertEquals("two", page.evaluate("window['result']"));
264+
assertThat(page.locator("select")).hasValue("two");
265+
}
266+
267+
@Test
268+
void shouldWaitForSelectToBeSwapped() {
269+
page.setContent(
270+
"<select disabled>\n" +
271+
" <option>one</option>\n" +
272+
" <option>two</option>\n" +
273+
"</select>\n" +
274+
"\n" +
275+
"<script>\n" +
276+
"function hydrate() {\n" +
277+
" const select = document.querySelector('select');\n" +
278+
" select.remove();\n" +
279+
"\n" +
280+
" const newSelect = document.createElement('select');\n" +
281+
" const option1 = document.createElement('option');\n" +
282+
" option1.textContent = 'one';\n" +
283+
" newSelect.appendChild(option1);\n" +
284+
" const option2 = document.createElement('option');\n" +
285+
" option2.textContent = 'two';\n" +
286+
" newSelect.appendChild(option2);\n" +
287+
"\n" +
288+
" document.body.appendChild(newSelect);\n" +
289+
"\n" +
290+
" newSelect.addEventListener('change', () => {\n" +
291+
" window['result'] = newSelect.value;\n" +
292+
" });\n" +
293+
"}\n" +
294+
"</script>");
295+
296+
page.evaluate("() => setTimeout(window.hydrate, 1000)");
297+
page.locator("select").selectOption("two");
298+
299+
assertThat(page.locator("select")).hasValue("two");
300+
assertEquals("two", page.evaluate("window['result']"));
301+
}
241302
}

playwright/src/test/java/com/microsoft/playwright/TestSelectorsRole.java

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.microsoft.playwright.options.AriaRole;
2020
import org.junit.jupiter.api.Test;
21+
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
2122

2223
import java.util.regex.Pattern;
2324

@@ -241,6 +242,66 @@ void shouldSupportDisabled() {
241242
), page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setDisabled(false)).evaluateAll("els => els.map(e => e.outerHTML)"));
242243
}
243244

245+
@Test
246+
void shouldInheritDisabledFromTheAncestor() {
247+
page.setContent(
248+
"<span aria-disabled=\"true\">\n" +
249+
" <button>Click me!</button>\n" +
250+
"</span>");
251+
assertThat(page.locator("button")).isDisabled();
252+
253+
page.setContent(
254+
"<span aria-disabled=\"true\">\n" +
255+
" <h1>Heading</h1>\n" +
256+
"</span>");
257+
// Non-control roles do not inherit disabled state
258+
assertThat(page.locator("h1")).isEnabled();
259+
}
260+
261+
@Test
262+
void shouldSupportDisabledFieldset() {
263+
page.setContent(
264+
"<fieldset disabled>\n" +
265+
" <input></input>\n" +
266+
" <button data-testid=\"inside-fieldset-element\">x</button>\n" +
267+
" <legend>\n" +
268+
" <button data-testid=\"inside-legend-element\">legend</button>\n" +
269+
" </legend>\n" +
270+
"</fieldset>\n" +
271+
"\n" +
272+
"<fieldset disabled>\n" +
273+
" <legend>\n" +
274+
" <div>\n" +
275+
" <button data-testid=\"nested-inside-legend-element\">x</button>\n" +
276+
" </div>\n" +
277+
" </legend>\n" +
278+
"</fieldset>\n" +
279+
"\n" +
280+
"<fieldset disabled>\n" +
281+
" <div></div>\n" +
282+
" <legend>\n" +
283+
" <button data-testid=\"first-legend-element\">x</button>\n" +
284+
" </legend>\n" +
285+
" <legend>\n" +
286+
" <button data-testid=\"second-legend-element\">x</button>\n" +
287+
" </legend>\n" +
288+
"</fieldset>\n" +
289+
"\n" +
290+
"<fieldset disabled>\n" +
291+
" <fieldset>\n" +
292+
" <button data-testid=\"deep-button\">x</button>\n" +
293+
" </fieldset>\n" +
294+
"</fieldset>");
295+
296+
assertThat(page.getByTestId("inside-legend-element")).isEnabled();
297+
assertThat(page.getByTestId("nested-inside-legend-element")).isEnabled();
298+
assertThat(page.getByTestId("first-legend-element")).isEnabled();
299+
// Only the first legend is exempt from disabled fieldset
300+
assertThat(page.getByTestId("second-legend-element")).isDisabled();
301+
// Nested fieldsets inherit disabled state
302+
assertThat(page.getByTestId("deep-button")).isDisabled();
303+
}
304+
244305
@Test
245306
void shouldSupportLevel() {
246307
page.setContent("<h1>Hello</h1>\n" +
@@ -357,15 +418,6 @@ void shouldSupportName() {
357418
"<div role=\"button\" aria-label=\"Hallo\"></div>"
358419
), page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("^H[ae]llo$"))).evaluateAll("els => els.map(e => e.outerHTML)"));
359420

360-
assertEquals(asList(
361-
"<div role=\"button\" aria-label=\" Hello \"></div>",
362-
"<div role=\"button\" aria-label=\"Hallo\"></div>"
363-
), page.locator("role=button[name=/h.*o/i]").evaluateAll("els => els.map(e => e.outerHTML)"));
364-
assertEquals(asList(
365-
"<div role=\"button\" aria-label=\" Hello \"></div>",
366-
"<div role=\"button\" aria-label=\"Hallo\"></div>"
367-
), page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(Pattern.compile("h.*o", Pattern.CASE_INSENSITIVE))).evaluateAll("els => els.map(e => e.outerHTML)"));
368-
369421
assertEquals(asList(
370422
"<div role=\"button\" aria-label=\" Hello \"></div>",
371423
"<div role=\"button\" aria-label=\"Hello\" aria-hidden=\"true\"></div>"

0 commit comments

Comments
 (0)