mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-09-08 21:01:00 +00:00
chore(api): extract Position to top level class (#51)
This commit is contained in:
parent
a721ef2456
commit
c79ad7ba08
@ -478,6 +478,10 @@ class Field extends Element {
|
||||
super(parent, jsonElement);
|
||||
this.name = name;
|
||||
this.type = new TypeRef(this, jsonElement.getAsJsonObject().get("type"));
|
||||
|
||||
if (name.equals("position")) {
|
||||
System.out.println(jsonPath + " " + type.jsonName);
|
||||
}
|
||||
}
|
||||
|
||||
void writeTo(List<String> output, String offset, String access) {
|
||||
@ -531,6 +535,25 @@ class Field extends Element {
|
||||
output.add(offset + "}");
|
||||
return;
|
||||
}
|
||||
if (asList("Page.click.options.position",
|
||||
"Page.dblclick.options.position",
|
||||
"Page.hover.options.position",
|
||||
"Frame.click.options.position",
|
||||
"Frame.dblclick.options.position",
|
||||
"Frame.hover.options.position",
|
||||
"ElementHandle.click.options.position",
|
||||
"ElementHandle.dblclick.options.position",
|
||||
"ElementHandle.hover.options.position").contains(jsonPath)) {
|
||||
output.add(offset + "public " + parentClass + " withPosition(Position position) {");
|
||||
output.add(offset + " this.position = position;");
|
||||
output.add(offset + " return this;");
|
||||
output.add(offset + "}");
|
||||
output.add(offset + "public " + parentClass + " withPosition(int x, int y) {");
|
||||
output.add(offset + " return withPosition(new Position(x, y));");
|
||||
output.add(offset + "}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (jsonPath.equals("Route.continue.overrides.postData")) {
|
||||
output.add(offset + "public ContinueOverrides withPostData(String postData) {");
|
||||
output.add(offset + " this.postData = postData.getBytes(StandardCharsets.UTF_8);");
|
||||
|
@ -208,6 +208,16 @@ class Types {
|
||||
add("Page.goto.options", "Object", "NavigateOptions");
|
||||
add("Frame.goto.options", "Object", "NavigateOptions");
|
||||
|
||||
add("Page.click.options.position", "Object", "Position", new Empty());
|
||||
add("Page.dblclick.options.position", "Object", "Position", new Empty());
|
||||
add("Page.hover.options.position", "Object", "Position", new Empty());
|
||||
add("Frame.click.options.position", "Object", "Position", new Empty());
|
||||
add("Frame.dblclick.options.position", "Object", "Position", new Empty());
|
||||
add("Frame.hover.options.position", "Object", "Position", new Empty());
|
||||
add("ElementHandle.click.options.position", "Object", "Position", new Empty());
|
||||
add("ElementHandle.dblclick.options.position", "Object", "Position", new Empty());
|
||||
add("ElementHandle.hover.options.position", "Object", "Position", new Empty());
|
||||
|
||||
// The method has custom signatures
|
||||
add("BrowserContext.cookies", "Promise<Array<Object>>", "Cookie");
|
||||
add("BrowserContext.cookies.sameSite", "\"Lax\"|\"None\"|\"Strict\"", "SameSite", new Empty());
|
||||
|
@ -66,25 +66,6 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
}
|
||||
class ClickOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public ClickOptions done() {
|
||||
return ClickOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Mouse.Button button;
|
||||
public Integer clickCount;
|
||||
public Integer delay;
|
||||
@ -106,9 +87,12 @@ public interface ElementHandle extends JSHandle {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public ClickOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public ClickOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public ClickOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
@ -128,25 +112,6 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
}
|
||||
class DblclickOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public DblclickOptions done() {
|
||||
return DblclickOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Mouse.Button button;
|
||||
public Integer delay;
|
||||
public Position position;
|
||||
@ -163,9 +128,12 @@ public interface ElementHandle extends JSHandle {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public DblclickOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public DblclickOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public DblclickOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
@ -198,33 +166,17 @@ public interface ElementHandle extends JSHandle {
|
||||
}
|
||||
}
|
||||
class HoverOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public HoverOptions done() {
|
||||
return HoverOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Position position;
|
||||
public Set<Keyboard.Modifier> modifiers;
|
||||
public Boolean force;
|
||||
public Integer timeout;
|
||||
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public HoverOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public HoverOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public HoverOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
|
@ -83,25 +83,6 @@ public interface Frame {
|
||||
}
|
||||
}
|
||||
class ClickOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public ClickOptions done() {
|
||||
return ClickOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Mouse.Button button;
|
||||
public Integer clickCount;
|
||||
public Integer delay;
|
||||
@ -123,9 +104,12 @@ public interface Frame {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public ClickOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public ClickOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public ClickOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
@ -145,25 +129,6 @@ public interface Frame {
|
||||
}
|
||||
}
|
||||
class DblclickOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public DblclickOptions done() {
|
||||
return DblclickOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Mouse.Button button;
|
||||
public Integer delay;
|
||||
public Position position;
|
||||
@ -180,9 +145,12 @@ public interface Frame {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public DblclickOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public DblclickOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public DblclickOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
@ -257,33 +225,17 @@ public interface Frame {
|
||||
}
|
||||
}
|
||||
class HoverOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public HoverOptions done() {
|
||||
return HoverOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Position position;
|
||||
public Set<Keyboard.Modifier> modifiers;
|
||||
public Boolean force;
|
||||
public Integer timeout;
|
||||
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public HoverOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public HoverOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public HoverOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
|
@ -166,25 +166,6 @@ public interface Page {
|
||||
}
|
||||
}
|
||||
class ClickOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public ClickOptions done() {
|
||||
return ClickOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Mouse.Button button;
|
||||
public Integer clickCount;
|
||||
public Integer delay;
|
||||
@ -206,9 +187,12 @@ public interface Page {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public ClickOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public ClickOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public ClickOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
@ -228,25 +212,6 @@ public interface Page {
|
||||
}
|
||||
}
|
||||
class DblclickOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public DblclickOptions done() {
|
||||
return DblclickOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Mouse.Button button;
|
||||
public Integer delay;
|
||||
public Position position;
|
||||
@ -263,9 +228,12 @@ public interface Page {
|
||||
this.delay = delay;
|
||||
return this;
|
||||
}
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public DblclickOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public DblclickOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public DblclickOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
@ -389,33 +357,17 @@ public interface Page {
|
||||
}
|
||||
}
|
||||
class HoverOptions {
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
Position() {
|
||||
}
|
||||
public HoverOptions done() {
|
||||
return HoverOptions.this;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public Position position;
|
||||
public Set<Keyboard.Modifier> modifiers;
|
||||
public Boolean force;
|
||||
public Integer timeout;
|
||||
|
||||
public Position setPosition() {
|
||||
this.position = new Position();
|
||||
return this.position;
|
||||
public HoverOptions withPosition(Position position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
public HoverOptions withPosition(int x, int y) {
|
||||
return withPosition(new Position(x, y));
|
||||
}
|
||||
public HoverOptions withModifiers(Keyboard.Modifier... modifiers) {
|
||||
this.modifiers = new HashSet<>(Arrays.asList(modifiers));
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class Position {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public Position() {
|
||||
}
|
||||
|
||||
public Position(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Position withX(int x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
public Position withY(int y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -311,7 +311,7 @@ public class TestClick extends TestBase {
|
||||
void shouldClickTheButtonWithPxBorderWithOffset() {
|
||||
page.navigate(server.PREFIX + "/input/button.html");
|
||||
page.evalOnSelector("button", "button => button.style.borderWidth = '8px'");
|
||||
page.click("button", new Page.ClickOptions().setPosition().withX(20).withY(10).done());
|
||||
page.click("button", new Page.ClickOptions().withPosition(20, 10));
|
||||
assertEquals(page.evaluate("result"), "Clicked");
|
||||
// Safari reports border-relative offsetX/offsetY.
|
||||
assertEquals(isWebKit ? 20 + 8 : 20, page.evaluate("offsetX"));
|
||||
@ -323,7 +323,7 @@ public class TestClick extends TestBase {
|
||||
page.navigate(server.PREFIX + "/input/button.html");
|
||||
page.evalOnSelector("button", "button => button.style.borderWidth = '2em'");
|
||||
page.evalOnSelector("button", "button => button.style.fontSize = '12px'");
|
||||
page.click("button", new Page.ClickOptions().setPosition().withX(20).withY(10).done());
|
||||
page.click("button", new Page.ClickOptions().withPosition(20, 10));
|
||||
assertEquals("Clicked", page.evaluate("result"));
|
||||
// Safari reports border-relative offsetX/offsetY.
|
||||
assertEquals(isWebKit ? 12 * 2 + 20 : 20, page.evaluate("offsetX"));
|
||||
@ -335,7 +335,7 @@ public class TestClick extends TestBase {
|
||||
page.navigate(server.PREFIX + "/input/button.html");
|
||||
page.evalOnSelector("button", "button => button.style.borderWidth = '8px'");
|
||||
page.evalOnSelector("button", "button => button.style.height = button.style.width = '2000px'");
|
||||
page.click("button", new Page.ClickOptions().setPosition().withX(1900).withY(1910).done());
|
||||
page.click("button", new Page.ClickOptions().withPosition(1900, 1910));
|
||||
assertEquals("Clicked", page.evaluate("() => window['result']"));
|
||||
// Safari reports border-relative offsetX/offsetY.
|
||||
assertEquals(isWebKit ? 1900 + 8 : 1900, page.evaluate("offsetX"));
|
||||
@ -356,7 +356,7 @@ public class TestClick extends TestBase {
|
||||
" button.style.width = '2000px';\n" +
|
||||
" button.style.borderWidth = '8px';\n" +
|
||||
"}");
|
||||
page.click("button", new Page.ClickOptions().setPosition().withX(1900).withY(1910).done());
|
||||
page.click("button", new Page.ClickOptions().withPosition(1900, 1910));
|
||||
assertEquals("Clicked", page.evaluate("() => window['result']"));
|
||||
// Safari reports border-relative offsetX/offsetY.
|
||||
assertEquals(isWebKit ? 1900 + 8 : 1900, page.evaluate("offsetX"));
|
||||
@ -375,7 +375,7 @@ public class TestClick extends TestBase {
|
||||
" button.style.borderWidth = '8px';\n" +
|
||||
" document.body.style.margin = '0';\n" +
|
||||
"}");
|
||||
page.click("button", new Page.ClickOptions().setPosition().withX(20).withY(10).done());
|
||||
page.click("button", new Page.ClickOptions().withPosition(20, 10));
|
||||
assertEquals("Clicked", page.evaluate("result"));
|
||||
// 20;10 + 8px of border in each direction
|
||||
int expectedX = 28;
|
||||
|
Loading…
x
Reference in New Issue
Block a user