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("
\n" + @@ -116,4 +117,11 @@ public class TestPageDrag extends TestBase { Object json = eventsHandle.jsonValue(); assertJsonEquals("[{type: \"mousedown\", x: 34, y: 7},{type: \"mouseup\", x: 10, y: 20}]", json); } + + @Test + void shouldWorkWithLocators() { + page.navigate(server.PREFIX + "/drag-n-drop.html"); + page.locator("#source").dragTo(page.locator("#target")); + assertEquals(true, page.evalOnSelector("#target", "target => target.contains(document.querySelector('#source'))")); + } } diff --git a/scripts/CLI_VERSION b/scripts/CLI_VERSION index cd90ba1c..651b77e1 100644 --- a/scripts/CLI_VERSION +++ b/scripts/CLI_VERSION @@ -1 +1 @@ -1.18.0-alpha-1637368835000 +1.18.0-alpha-nov-29-2021 diff --git a/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java b/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java index 27d0112a..28a9022a 100644 --- a/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java +++ b/tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java @@ -270,8 +270,10 @@ class TypeRef extends Element { customTypeNames.put("Page.setInputFiles.files", "FilePayload"); customTypeNames.put("FormData.set.value", "FilePayload"); + customTypeNames.put("Locator.dragTo.options.sourcePosition", "Position"); customTypeNames.put("Page.dragAndDrop.options.sourcePosition", "Position"); customTypeNames.put("Frame.dragAndDrop.options.sourcePosition", "Position"); + customTypeNames.put("Locator.dragTo.options.targetPosition", "Position"); customTypeNames.put("Page.dragAndDrop.options.targetPosition", "Position"); customTypeNames.put("Frame.dragAndDrop.options.targetPosition", "Position"); } @@ -648,12 +650,12 @@ class Method extends Element { if ("PlaywrightAssertions.assertThat".equals(jsonPath)) { writeJavadoc(params, output, offset); String originalName = jsonElement.getAsJsonObject().get("originalName").getAsString(); - if ("assertThatPage".equals(originalName)) { + if ("expectPage".equals(originalName)) { output.add(offset + "static PageAssertions assertThat(Page page) {"); output.add(offset + " return new PageAssertionsImpl(page);"); output.add(offset + "}"); output.add(""); - } else if ("assertThatLocator".equals(originalName)) { + } else if ("expectLocator".equals(originalName)) { output.add(offset + "static LocatorAssertions assertThat(Locator locator) {"); output.add(offset + " return new LocatorAssertionsImpl(locator);"); output.add(offset + "}");