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

feat: roll driver, support parameter for isEnabled/isEditable (#1049)

This commit is contained in:
Yury Semikhatsky
2022-09-08 13:05:33 -07:00
committed by GitHub
parent cf73a8d525
commit 6e66861db3
9 changed files with 103 additions and 23 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->105.0.5195.52<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Chromium <!-- GEN:chromium-version -->106.0.5249.21<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| WebKit <!-- GEN:webkit-version -->16.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->104.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
@@ -72,11 +72,16 @@ public interface LocatorAssertions {
}
}
class IsEditableOptions {
public Boolean editable;
/**
* Time to retry the assertion for.
*/
public Double timeout;
public IsEditableOptions setEditable(boolean editable) {
this.editable = editable;
return this;
}
/**
* Time to retry the assertion for.
*/
@@ -100,11 +105,16 @@ public interface LocatorAssertions {
}
}
class IsEnabledOptions {
public Boolean enabled;
/**
* Time to retry the assertion for.
*/
public Double timeout;
public IsEnabledOptions setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}
/**
* Time to retry the assertion for.
*/
@@ -456,8 +466,8 @@ public interface LocatorAssertions {
*/
void isFocused(IsFocusedOptions options);
/**
* Ensures the {@code Locator} points to a hidden DOM node, which is the opposite of <a
* href="https://playwright.dev/java/docs/api/actionability#visible">visible</a>.
* Ensures that {@code Locator} either does not resolve to any DOM node, or resolves to a <a
* href="https://playwright.dev/java/docs/api/actionability#visible">non-visible</a> one.
* <pre>{@code
* assertThat(page.locator(".my-element")).isHidden();
* }</pre>
@@ -466,16 +476,16 @@ public interface LocatorAssertions {
isHidden(null);
}
/**
* Ensures the {@code Locator} points to a hidden DOM node, which is the opposite of <a
* href="https://playwright.dev/java/docs/api/actionability#visible">visible</a>.
* Ensures that {@code Locator} either does not resolve to any DOM node, or resolves to a <a
* href="https://playwright.dev/java/docs/api/actionability#visible">non-visible</a> one.
* <pre>{@code
* assertThat(page.locator(".my-element")).isHidden();
* }</pre>
*/
void isHidden(IsHiddenOptions options);
/**
* Ensures the {@code Locator} points to a <a href="https://playwright.dev/java/docs/api/actionability#visible">visible</a> DOM
* node.
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/api/actionability#visible">attached</a>
* and <a href="https://playwright.dev/java/docs/api/actionability#visible">visible</a> DOM node.
* <pre>{@code
* assertThat(page.locator(".my-element")).isVisible();
* }</pre>
@@ -484,8 +494,8 @@ public interface LocatorAssertions {
isVisible(null);
}
/**
* Ensures the {@code Locator} points to a <a href="https://playwright.dev/java/docs/api/actionability#visible">visible</a> DOM
* node.
* Ensures that {@code Locator} points to an <a href="https://playwright.dev/java/docs/api/actionability#visible">attached</a>
* and <a href="https://playwright.dev/java/docs/api/actionability#visible">visible</a> DOM node.
* <pre>{@code
* assertThat(page.locator(".my-element")).isVisible();
* }</pre>
@@ -310,7 +310,9 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
@Override
public void isEditable(IsEditableOptions options) {
expectTrue("to.be.editable", "Locator expected to be editable", convertType(options, FrameExpectOptions.class));
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
boolean editable = options == null || options.editable == null || options.editable == true;
expectTrue(editable ? "to.be.editable" : "to.be.readonly", "Locator expected to be editable", frameOptions);
}
@Override
@@ -320,7 +322,9 @@ public class LocatorAssertionsImpl extends AssertionsBase implements LocatorAsse
@Override
public void isEnabled(IsEnabledOptions options) {
expectTrue("to.be.enabled", "Locator expected to be enabled", convertType(options, FrameExpectOptions.class));
FrameExpectOptions frameOptions = convertType(options, FrameExpectOptions.class);
boolean enabled = options == null || options.enabled == null || options.enabled == true;
expectTrue(enabled ? "to.be.enabled" : "to.be.disabled", "Locator expected to be enabled", frameOptions);
}
@Override
@@ -573,12 +573,9 @@ public class TestBrowserContextFetch extends TestBase {
}
@Test
void shouldThrowWhenDataPassedForUnsupportedRequest() {
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
context.request().fetch(server.EMPTY_PAGE, RequestOptions.create()
.setMethod("GET").setData("bar"));
});
assertTrue(e.getMessage().contains("Method GET does not accept post data"), e.getMessage());
void shouldNotThrowWhenDataPassedForUnsupportedRequest() {
context.request().fetch(server.EMPTY_PAGE, RequestOptions.create()
.setMethod("GET").setData("bar"));
}
@Test
@@ -102,9 +102,8 @@ public class TestDownload extends TestBase {
assertTrue(error[0].getMessage().contains("Download is starting"));
assertEquals("about:blank", page.url());
} else {
assertNotNull(response[0]);
assertEquals(200, response[0].status());
assertEquals(server.PREFIX + "/download", page.url());
assertNotNull(error[0]);
assertTrue(error[0].getMessage().contains("Download is starting"));
}
page.close();
}
@@ -757,6 +757,33 @@ public class TestLocatorAssertions extends TestBase {
assertTrue(e.getMessage().contains("Locator expected not to be editable"), e.getMessage());
}
@Test
void isEditableWithNot() {
page.setContent("<input readonly></input>");
Locator locator = page.locator("input");
assertThat(locator).not().isEditable();
}
@Test
void isEditableWithEditableTrue() {
page.setContent("<input></input>");
Locator locator = page.locator("input");
assertThat(locator).isEditable(new LocatorAssertions.IsEditableOptions().setEditable(true));
}
@Test
void isEditableWithEditableFalse() {
page.setContent("<input readonly></input>");
Locator locator = page.locator("input");
assertThat(locator).isEditable(new LocatorAssertions.IsEditableOptions().setEditable(false));
}
@Test
void isEditableWithNotAndEditableFalse() {
page.setContent("<input></input>");
Locator locator = page.locator("input");
assertThat(locator).not().isEditable(new LocatorAssertions.IsEditableOptions().setEditable(false));
}
@Test
void isEmptyPass() {
@@ -820,6 +847,47 @@ public class TestLocatorAssertions extends TestBase {
assertTrue(e.getMessage().contains("Locator expected not to be enabled"), e.getMessage());
}
@Test
void isEnabledTrue() {
page.setContent("<button>Text</button>");
Locator locator = page.locator("button");
assertThat(locator).isEnabled(new LocatorAssertions.IsEnabledOptions().setEnabled(true));
}
@Test
void isEnabledFalse() {
page.setContent("<button disabled>Text</button>");
Locator locator = page.locator("button");
assertThat(locator).isEnabled(new LocatorAssertions.IsEnabledOptions().setEnabled(false));
}
@Test
void isEnabledEventually() {
page.setContent("<button disabled>Text</button>");
Locator locator = page.locator("button");
locator.evaluate("e => setTimeout(() => {\n" +
" e.removeAttribute('disabled');\n" +
"}, 500);\n");
assertThat(locator).isEnabled();
}
@Test
void isEnabledEventuallyWithNot() {
page.setContent("<button>Text</button>");
Locator locator = page.locator("button");
locator.evaluate("e => setTimeout(() => {\n" +
" e.setAttribute('disabled', '');\n" +
"}, 500);\n");
assertThat(locator).not().isEnabled();
}
@Test
void isEnabledWithNotAndEnabledFalse() {
page.setContent("<button>Text</button>");
Locator locator = page.locator("button");
assertThat(locator).not().isEnabled(new LocatorAssertions.IsEnabledOptions().setEnabled(false));
}
@Test
void isFocusedPass() {
page.setContent("<input></input>");
@@ -224,7 +224,8 @@ public class TestPageRequestFallback extends TestBase {
page.route("**/foo", route -> route.fallback(new Route.FallbackOptions().setUrl(server.PREFIX + "/global-var.html")));
Response response = page.waitForResponse("**/*", () -> page.navigate(server.PREFIX + "/foo"));
assertEquals(server.PREFIX + "/global-var.html", url[0]);
assertEquals(server.PREFIX + "/foo", response.url());
assertEquals(server.PREFIX + "/global-var.html", response.url());
assertEquals(server.PREFIX + "/global-var.html", response.request().url());
assertEquals(123, page.evaluate("() => window['globalVar']"));
assertEquals("GET", request.get().method);
}
@@ -67,7 +67,8 @@ public class TestRequestContinue extends TestBase {
route.resume(new Route.ResumeOptions().setUrl(server.PREFIX + "/global-var.html"));
});
Response response = page.navigate(server.PREFIX + "/foo");
assertEquals(server.PREFIX + "/foo", response.url());
assertEquals(server.PREFIX + "/global-var.html", response.url());
assertEquals(server.PREFIX + "/global-var.html", response.request().url());
assertEquals(123, page.evaluate("window['globalVar']"));
assertEquals("GET", serverRequest.get().method);
}
+1 -1
View File
@@ -1 +1 @@
1.26.0-alpha-1661907180000
1.26.0-alpha-sep-7-2022