diff --git a/README.md b/README.md index bbe5fc68..f224998d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom | | Linux | macOS | Windows | | :--- | :---: | :---: | :---: | -| Chromium 98.0.4708.0 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| Chromium 98.0.4730.0 | :white_check_mark: | :white_check_mark: | :white_check_mark: | | WebKit 15.4 | ✅ | ✅ | ✅ | | Firefox 94.0.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | diff --git a/assertions/src/main/java/com/microsoft/playwright/assertions/PlaywrightAssertions.java b/assertions/src/main/java/com/microsoft/playwright/assertions/PlaywrightAssertions.java index 95a124cb..a3fe7d67 100644 --- a/assertions/src/main/java/com/microsoft/playwright/assertions/PlaywrightAssertions.java +++ b/assertions/src/main/java/com/microsoft/playwright/assertions/PlaywrightAssertions.java @@ -49,6 +49,13 @@ import com.microsoft.playwright.impl.PageAssertionsImpl; *
By default, the timeout for assertions is set to 5 seconds. * *
To use Playwright assertions add the following dependency into the {@code pom.xml} of your Maven project: + *
{@code
+ *
+ * com.microsoft.playwright
+ * assertions
+ * 1.17.0
+ *
+ * }
*/
public interface PlaywrightAssertions {
/**
diff --git a/playwright/src/main/java/com/microsoft/playwright/APIRequest.java b/playwright/src/main/java/com/microsoft/playwright/APIRequest.java
index 2f0e31ae..6a09057a 100644
--- a/playwright/src/main/java/com/microsoft/playwright/APIRequest.java
+++ b/playwright/src/main/java/com/microsoft/playwright/APIRequest.java
@@ -21,7 +21,9 @@ import java.nio.file.Path;
import java.util.*;
/**
- * Exposes API that can be used for the Web API testing.
+ * Exposes API that can be used for the Web API testing. Each Playwright browser context has a APIRequestContext instance
+ * attached which shares cookies with the page context. Its also possible to create a new APIRequestContext instance
+ * manually. For more information see here.
*/
public interface APIRequest {
class NewContextOptions {
diff --git a/playwright/src/main/java/com/microsoft/playwright/Locator.java b/playwright/src/main/java/com/microsoft/playwright/Locator.java
index 85737385..73d336f3 100644
--- a/playwright/src/main/java/com/microsoft/playwright/Locator.java
+++ b/playwright/src/main/java/com/microsoft/playwright/Locator.java
@@ -424,6 +424,107 @@ public interface Locator {
return this;
}
}
+ class DragToOptions {
+ /**
+ * Whether to bypass the actionability checks. Defaults to
+ * {@code false}.
+ */
+ public Boolean force;
+ /**
+ * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
+ * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
+ * inaccessible pages. Defaults to {@code false}.
+ */
+ public Boolean noWaitAfter;
+ /**
+ * Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not
+ * specified, some visible point of the element is used.
+ */
+ public Position sourcePosition;
+ /**
+ * Drops on the target element at this point relative to the top-left corner of the element's padding box. If not
+ * specified, some visible point of the element is used.
+ */
+ public Position targetPosition;
+ /**
+ * Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by
+ * using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout
+ * Page.setDefaultTimeout()} methods.
+ */
+ public Double timeout;
+ /**
+ * When set, this method only performs the actionability
+ * checks and skips the action. Defaults to {@code false}. Useful to wait until the element is ready for the action without
+ * performing it.
+ */
+ public Boolean trial;
+
+ /**
+ * Whether to bypass the actionability checks. Defaults to
+ * {@code false}.
+ */
+ public DragToOptions setForce(boolean force) {
+ this.force = force;
+ return this;
+ }
+ /**
+ * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
+ * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
+ * inaccessible pages. Defaults to {@code false}.
+ */
+ public DragToOptions setNoWaitAfter(boolean noWaitAfter) {
+ this.noWaitAfter = noWaitAfter;
+ return this;
+ }
+ /**
+ * Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not
+ * specified, some visible point of the element is used.
+ */
+ public DragToOptions setSourcePosition(double x, double y) {
+ return setSourcePosition(new Position(x, y));
+ }
+ /**
+ * Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not
+ * specified, some visible point of the element is used.
+ */
+ public DragToOptions setSourcePosition(Position sourcePosition) {
+ this.sourcePosition = sourcePosition;
+ return this;
+ }
+ /**
+ * Drops on the target element at this point relative to the top-left corner of the element's padding box. If not
+ * specified, some visible point of the element is used.
+ */
+ public DragToOptions setTargetPosition(double x, double y) {
+ return setTargetPosition(new Position(x, y));
+ }
+ /**
+ * Drops on the target element at this point relative to the top-left corner of the element's padding box. If not
+ * specified, some visible point of the element is used.
+ */
+ public DragToOptions setTargetPosition(Position targetPosition) {
+ this.targetPosition = targetPosition;
+ return this;
+ }
+ /**
+ * Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by
+ * using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or {@link Page#setDefaultTimeout
+ * Page.setDefaultTimeout()} methods.
+ */
+ public DragToOptions setTimeout(double timeout) {
+ this.timeout = timeout;
+ return this;
+ }
+ /**
+ * When set, this method only performs the actionability
+ * checks and skips the action. Defaults to {@code false}. Useful to wait until the element is ready for the action without
+ * performing it.
+ */
+ public DragToOptions setTrial(boolean trial) {
+ this.trial = trial;
+ return this;
+ }
+ }
class ElementHandleOptions {
/**
* Maximum time in milliseconds, defaults to 30 seconds, pass {@code 0} to disable timeout. The default value can be changed by
@@ -1674,6 +1775,20 @@ public interface Locator {
* @param eventInit Optional event-specific initialization properties.
*/
void dispatchEvent(String type, Object eventInit, DispatchEventOptions options);
+ /**
+ *
+ *
+ * @param target Locator of the element to drag to.
+ */
+ default void dragTo(Locator target) {
+ dragTo(target, null);
+ }
+ /**
+ *
+ *
+ * @param target Locator of the element to drag to.
+ */
+ void dragTo(Locator target, DragToOptions options);
/**
* Resolves given locator to the first matching DOM element. If no elements matching the query are visible, waits for them
* up to a given timeout. If multiple elements match the selector, throws.
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/APIRequestContextImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/APIRequestContextImpl.java
index be9b1370..0f154130 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/APIRequestContextImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/APIRequestContextImpl.java
@@ -108,9 +108,6 @@ class APIRequestContextImpl extends ChannelOwner implements APIRequestContext {
params.addProperty("ignoreHTTPSErrors", options.ignoreHTTPSErrors);
}
JsonObject json = sendMessage("fetch", params).getAsJsonObject();
- if (json.has("error")) {
- throw new PlaywrightException(json.get("error").getAsString());
- }
return new APIResponseImpl(this, json.getAsJsonObject("response"));
}
diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
index 66f91841..90998f62 100644
--- a/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
+++ b/playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java
@@ -95,6 +95,16 @@ class LocatorImpl implements Locator {
frame.dispatchEvent(selector, type, eventInit, convertType(options, Frame.DispatchEventOptions.class).setStrict(true));
}
+ @Override
+ public void dragTo(Locator target, DragToOptions options) {
+ if (options == null) {
+ options = new DragToOptions();
+ }
+ Frame.DragAndDropOptions frameOptions = convertType(options, Frame.DragAndDropOptions.class);
+ frameOptions.setStrict(true);
+ frame.dragAndDrop(selector, ((LocatorImpl) target).selector, frameOptions);
+ }
+
@Override
public ElementHandle elementHandle(ElementHandleOptions options) {
if (options == null) {
diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageDrag.java b/playwright/src/test/java/com/microsoft/playwright/TestPageDrag.java
index e7fadc77..32d210fd 100644
--- a/playwright/src/test/java/com/microsoft/playwright/TestPageDrag.java
+++ b/playwright/src/test/java/com/microsoft/playwright/TestPageDrag.java
@@ -87,6 +87,7 @@ public class TestPageDrag extends TestBase {
assertEquals(true, page.evalOnSelector("#target",
"target => target.contains(document.querySelector('#source'))")); // could not find source in target
}
+
@Test
void shouldAllowSpecifyingThePosition() {
page.setContent("