mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-09-08 21:01:00 +00:00
feat: introduce PlaywrightException (#41)
This commit is contained in:
parent
8258b1ac49
commit
8d8756084e
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 PlaywrightException extends RuntimeException {
|
||||
public PlaywrightException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PlaywrightException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
public void close() {
|
||||
if (isClosedOrClosing) {
|
||||
// TODO: wait close event instead?
|
||||
throw new RuntimeException("Already closing");
|
||||
throw new PlaywrightException("Already closing");
|
||||
}
|
||||
isClosedOrClosing = true;
|
||||
sendMessage("close");
|
||||
@ -105,11 +105,11 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
@Override
|
||||
public void exposeBinding(String name, Page.Binding playwrightBinding, ExposeBindingOptions options) {
|
||||
if (bindings.containsKey(name)) {
|
||||
throw new RuntimeException("Function \"" + name + "\" has been already registered");
|
||||
throw new PlaywrightException("Function \"" + name + "\" has been already registered");
|
||||
}
|
||||
for (PageImpl page : pages) {
|
||||
if (page.bindings.containsKey(name)) {
|
||||
throw new RuntimeException("Function \"" + name + "\" has been already registered in one of the pages");
|
||||
throw new PlaywrightException("Function \"" + name + "\" has been already registered in one of the pages");
|
||||
}
|
||||
}
|
||||
bindings.put(name, playwrightBinding);
|
||||
@ -135,7 +135,7 @@ class BrowserContextImpl extends ChannelOwner implements BrowserContext {
|
||||
@Override
|
||||
public PageImpl newPage() {
|
||||
if (ownerPage != null) {
|
||||
throw new RuntimeException("Please use browser.newContext()");
|
||||
throw new PlaywrightException("Please use browser.newContext()");
|
||||
}
|
||||
JsonObject json = sendMessage("newPage").getAsJsonObject();
|
||||
return connection.getExistingObject(json.getAsJsonObject("page").get("guid").getAsString());
|
||||
|
@ -18,7 +18,7 @@ package com.microsoft.playwright.impl;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.Deferred;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -102,7 +102,7 @@ public class Connection {
|
||||
public <T> T getExistingObject(String guid) {
|
||||
@SuppressWarnings("unchecked") T result = (T) objects.get(guid);
|
||||
if (result == null)
|
||||
throw new RuntimeException("Object doesn't exist: " + guid);
|
||||
throw new PlaywrightException("Object doesn't exist: " + guid);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -129,14 +129,14 @@ public class Connection {
|
||||
if (message.id != 0) {
|
||||
WaitableResult<JsonElement> callback = callbacks.get(message.id);
|
||||
if (callback == null) {
|
||||
throw new RuntimeException("Cannot find command to respond: " + message.id);
|
||||
throw new PlaywrightException("Cannot find command to respond: " + message.id);
|
||||
}
|
||||
callbacks.remove(message.id);
|
||||
// System.out.println("Message: " + message.id + " " + message);
|
||||
if (message.error == null) {
|
||||
callback.complete(message.result);
|
||||
} else {
|
||||
callback.completeExceptionally(new RuntimeException(message.error.toString()));
|
||||
callback.completeExceptionally(new PlaywrightException(message.error.toString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -152,14 +152,14 @@ public class Connection {
|
||||
if (message.method.equals("__dispose__")) {
|
||||
ChannelOwner object = objects.get(message.guid);
|
||||
if (object == null) {
|
||||
throw new RuntimeException("Cannot find object to dispose: " + message.guid);
|
||||
throw new PlaywrightException("Cannot find object to dispose: " + message.guid);
|
||||
}
|
||||
object.dispose();
|
||||
return;
|
||||
}
|
||||
ChannelOwner object = objects.get(message.guid);
|
||||
if (object == null) {
|
||||
throw new RuntimeException("Cannot find object to call " + message.method + ": " + message.guid);
|
||||
throw new PlaywrightException("Cannot find object to call " + message.method + ": " + message.guid);
|
||||
}
|
||||
object.handleEvent(message.method, message.params);
|
||||
}
|
||||
@ -170,7 +170,7 @@ public class Connection {
|
||||
|
||||
ChannelOwner parent = objects.get(parentGuid);
|
||||
if (parent == null) {
|
||||
throw new RuntimeException("Cannot find parent object " + parentGuid + " to create " + guid);
|
||||
throw new PlaywrightException("Cannot find parent object " + parentGuid + " to create " + guid);
|
||||
}
|
||||
JsonObject initializer = params.getAsJsonObject("initializer");
|
||||
ChannelOwner result = null;
|
||||
@ -230,7 +230,7 @@ public class Connection {
|
||||
result = new WorkerImpl(parent, type, guid, initializer);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown type " + type);
|
||||
throw new PlaywrightException("Unknown type " + type);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.DeviceDescriptor;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
class DeviceDescriptorImpl implements DeviceDescriptor {
|
||||
private static class ViewportImpl implements Viewport{
|
||||
@ -72,7 +73,7 @@ class DeviceDescriptorImpl implements DeviceDescriptor {
|
||||
case "chromium": return BrowserType.CHROMIUM;
|
||||
case "firefox": return BrowserType.FIREFOX;
|
||||
case "webkit": return BrowserType.WEBKIT;
|
||||
default: throw new RuntimeException("Unknown type: " + defaultBrowserType);
|
||||
default: throw new PlaywrightException("Unknown type: " + defaultBrowserType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
case "load": return LOAD;
|
||||
case "domcontentloaded": return DOMCONTENTLOADED;
|
||||
case "networkidle": return NETWORKIDLE;
|
||||
default: throw new RuntimeException("Unexpected value: " + value);
|
||||
default: throw new PlaywrightException("Unexpected value: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
try {
|
||||
encoded = Files.readAllBytes(options.path.toPath());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read from file", e);
|
||||
throw new PlaywrightException("Failed to read from file", e);
|
||||
}
|
||||
String content = new String(encoded, StandardCharsets.UTF_8);
|
||||
content += "//# sourceURL=" + options.path.getPath().replace("\n", "");
|
||||
@ -166,7 +166,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
try {
|
||||
encoded = Files.readAllBytes(options.path.toPath());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read from file", e);
|
||||
throw new PlaywrightException("Failed to read from file", e);
|
||||
}
|
||||
String content = new String(encoded, StandardCharsets.UTF_8);
|
||||
content += "/*# sourceURL=" + options.path.getPath().replace("\n", "") + "*/";
|
||||
@ -395,7 +395,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
case DOMCONTENTLOADED: return "domcontentloaded";
|
||||
case LOAD: return "load";
|
||||
case NETWORKIDLE: return "networkidle";
|
||||
default: throw new RuntimeException("Unexpected value: " + waitUntil);
|
||||
default: throw new PlaywrightException("Unexpected value: " + waitUntil);
|
||||
}
|
||||
}
|
||||
|
||||
@ -552,7 +552,7 @@ public class FrameImpl extends ChannelOwner implements Frame {
|
||||
return;
|
||||
}
|
||||
if (params.has("error")) {
|
||||
exception = new RuntimeException(params.get("error").getAsString());
|
||||
exception = new PlaywrightException(params.get("error").getAsString());
|
||||
} else {
|
||||
if (params.has("newDocument")) {
|
||||
JsonObject jsonReq = params.getAsJsonObject("newDocument").getAsJsonObject("request");
|
||||
|
@ -311,7 +311,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
case NO_PREFERENCE:
|
||||
return "no-preference";
|
||||
default:
|
||||
throw new RuntimeException("Unknown option: " + colorScheme);
|
||||
throw new PlaywrightException("Unknown option: " + colorScheme);
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,10 +336,10 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
@Override
|
||||
public void exposeBinding(String name, Binding playwrightBinding, ExposeBindingOptions options) {
|
||||
if (bindings.containsKey(name)) {
|
||||
throw new RuntimeException("Function \"" + name + "\" has been already registered");
|
||||
throw new PlaywrightException("Function \"" + name + "\" has been already registered");
|
||||
}
|
||||
if (browserContext.bindings.containsKey(name)) {
|
||||
throw new RuntimeException("Function \"" + name + "\" has been already registered in the browser context");
|
||||
throw new PlaywrightException("Function \"" + name + "\" has been already registered in the browser context");
|
||||
}
|
||||
bindings.put(name, playwrightBinding);
|
||||
|
||||
@ -492,7 +492,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
@Override
|
||||
public byte[] pdf(PdfOptions options) {
|
||||
if (!browserContext.browser().isChromium()) {
|
||||
throw new RuntimeException("Page.pdf only supported in headless Chromium");
|
||||
throw new PlaywrightException("Page.pdf only supported in headless Chromium");
|
||||
}
|
||||
if (options == null) {
|
||||
options = new PdfOptions();
|
||||
@ -794,7 +794,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public Event<EventType> get() {
|
||||
throw new RuntimeException("Navigating frame was detached");
|
||||
throw new PlaywrightException("Navigating frame was detached");
|
||||
}
|
||||
}
|
||||
|
||||
@ -838,7 +838,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public R get() {
|
||||
throw new RuntimeException(errorMessage);
|
||||
throw new PlaywrightException(errorMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,6 +23,7 @@ import com.google.gson.JsonObject;
|
||||
import com.microsoft.playwright.BrowserType;
|
||||
import com.microsoft.playwright.DeviceDescriptor;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -43,7 +44,7 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
|
||||
PlaywrightImpl playwright = (PlaywrightImpl)connection.waitForObjectWithKnownName("Playwright");
|
||||
return playwright;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new PlaywrightException("Failed to launch driver", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class Serialization {
|
||||
|
||||
private static SerializedValue serializeValue(Object value, List<JSHandleImpl> handles, int depth) {
|
||||
if (depth > 100) {
|
||||
throw new RuntimeException("Maximum argument depth exceeded");
|
||||
throw new PlaywrightException("Maximum argument depth exceeded");
|
||||
}
|
||||
SerializedValue result = new SerializedValue();
|
||||
if (value instanceof JSHandleImpl) {
|
||||
@ -97,7 +97,7 @@ class Serialization {
|
||||
}
|
||||
result.a = list.toArray(new SerializedValue[0]);
|
||||
} else {
|
||||
throw new RuntimeException("Unsupported type of argument: " + value);
|
||||
throw new PlaywrightException("Unsupported type of argument: " + value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -142,7 +142,7 @@ class Serialization {
|
||||
case "NaN":
|
||||
return (T) Double.valueOf(Double.NaN);
|
||||
default:
|
||||
throw new RuntimeException("Unexpected value: " + value.v);
|
||||
throw new PlaywrightException("Unexpected value: " + value.v);
|
||||
}
|
||||
}
|
||||
if (value.a != null) {
|
||||
@ -159,7 +159,7 @@ class Serialization {
|
||||
}
|
||||
return (T) map;
|
||||
}
|
||||
throw new RuntimeException("Unexpected result: " + new Gson().toJson(value));
|
||||
throw new PlaywrightException("Unexpected result: " + new Gson().toJson(value));
|
||||
}
|
||||
|
||||
static String toProtocol(Mouse.Button button) {
|
||||
@ -167,7 +167,7 @@ class Serialization {
|
||||
case LEFT: return "left";
|
||||
case RIGHT: return "right";
|
||||
case MIDDLE: return "middle";
|
||||
default: throw new RuntimeException("Unexpected value: " + button);
|
||||
default: throw new PlaywrightException("Unexpected value: " + button);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
@ -43,7 +45,7 @@ public class Transport {
|
||||
try {
|
||||
outgoing.put(message);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Failed to send message", e);
|
||||
throw new PlaywrightException("Failed to send message", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +53,7 @@ public class Transport {
|
||||
try {
|
||||
return incoming.poll(timeout.toMillis(), TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Failed to read message", e);
|
||||
throw new PlaywrightException("Failed to read message", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package com.microsoft.playwright.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.microsoft.playwright.FileChooser;
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
@ -104,7 +105,7 @@ class Utils {
|
||||
try {
|
||||
mimeType = Files.probeContentType(file.toPath());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to determine mime type", e);
|
||||
throw new PlaywrightException("Failed to determine mime type", e);
|
||||
}
|
||||
if (mimeType == null) {
|
||||
mimeType = "application/octet-stream";
|
||||
@ -113,7 +114,7 @@ class Utils {
|
||||
try {
|
||||
buffer = Files.readAllBytes(file.toPath());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read from file", e);
|
||||
throw new PlaywrightException("Failed to read from file", e);
|
||||
}
|
||||
payloads.add(new FileChooser.FilePayload(file.getName(), mimeType, buffer));
|
||||
}
|
||||
@ -125,14 +126,14 @@ class Utils {
|
||||
if (dir != null) {
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkdirs()) {
|
||||
throw new RuntimeException("Failed to create parent directory: " + dir.getPath());
|
||||
throw new PlaywrightException("Failed to create parent directory: " + dir.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
try (DataOutputStream out = new DataOutputStream(new FileOutputStream(path));) {
|
||||
out.write(buffer);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to write to file", e);
|
||||
throw new PlaywrightException("Failed to write to file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
class WaitableResult<T> implements Waitable<T> {
|
||||
private T result;
|
||||
private RuntimeException exception;
|
||||
@ -45,7 +47,7 @@ class WaitableResult<T> implements Waitable<T> {
|
||||
@Override
|
||||
public T get() {
|
||||
if (exception != null) {
|
||||
throw new RuntimeException(exception);
|
||||
throw new PlaywrightException(exception.getMessage(), exception);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package com.microsoft.playwright.impl;
|
||||
|
||||
import com.microsoft.playwright.PlaywrightException;
|
||||
|
||||
class WaitableTimeout<T> implements Waitable<T> {
|
||||
private final long deadline;
|
||||
private final int timeout;
|
||||
@ -32,7 +34,7 @@ class WaitableTimeout<T> implements Waitable<T> {
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
throw new RuntimeException("Timeout " + timeout + "ms exceeded");
|
||||
throw new PlaywrightException("Timeout " + timeout + "ms exceeded");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,7 @@ public class TestBrowser {
|
||||
try {
|
||||
page.context().newPage();
|
||||
fail("newPage should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Please use browser.newContext()"));
|
||||
}
|
||||
page.close();
|
||||
|
@ -60,7 +60,7 @@ public class TestBrowserContextExposeFunction extends TestBase {
|
||||
try {
|
||||
context.exposeFunction("foo", args -> null);
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Function \"foo\" has been already registered"));
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ public class TestBrowserContextExposeFunction extends TestBase {
|
||||
try {
|
||||
page.exposeFunction("foo", args -> null);
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Function \"foo\" has been already registered in the browser context"));
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class TestBrowserContextExposeFunction extends TestBase {
|
||||
try {
|
||||
context.exposeFunction("baz", args -> null);
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Function \"baz\" has been already registered in one of the pages"));
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ public class TestClick extends TestBase {
|
||||
Exception exception = null;
|
||||
try {
|
||||
page.click("button", new Page.ClickOptions().withForce(true));
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
exception = e;
|
||||
}
|
||||
assertNotNull(exception);
|
||||
|
@ -63,7 +63,7 @@ public class TestElementHandleClick extends TestBase {
|
||||
try {
|
||||
button.click();
|
||||
fail("click should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Element is not attached to the DOM"));
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ public class TestElementHandleClick extends TestBase {
|
||||
try {
|
||||
button.click(new ElementHandle.ClickOptions().withForce(true));
|
||||
fail("click should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Element is not visible"));
|
||||
}
|
||||
}
|
||||
@ -89,7 +89,7 @@ public class TestElementHandleClick extends TestBase {
|
||||
try {
|
||||
button.click(new ElementHandle.ClickOptions().withForce(true));
|
||||
fail("click should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Element is not visible"));
|
||||
}
|
||||
}
|
||||
@ -101,7 +101,7 @@ public class TestElementHandleClick extends TestBase {
|
||||
try {
|
||||
br.click(new ElementHandle.ClickOptions().withForce(true));
|
||||
fail("click should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Element is outside of the viewport"));
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class TestElementHandleWaitForElementState extends TestBase {
|
||||
try {
|
||||
result.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout 1000ms exceeded"));
|
||||
}
|
||||
}
|
||||
@ -69,7 +69,7 @@ public class TestElementHandleWaitForElementState extends TestBase {
|
||||
try {
|
||||
promise.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Element is not attached to the DOM"));
|
||||
}
|
||||
}
|
||||
@ -121,7 +121,7 @@ public class TestElementHandleWaitForElementState extends TestBase {
|
||||
try {
|
||||
promise.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Element is not attached to the DOM"));
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class TestEvalOnSelector extends TestBase {
|
||||
try {
|
||||
page.evalOnSelector("section", "e => e.id");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("failed to find element matching selector \"section\""));
|
||||
}
|
||||
}
|
||||
@ -169,7 +169,7 @@ public class TestEvalOnSelector extends TestBase {
|
||||
try {
|
||||
page.evalOnSelector("*css=div >> *css=span", "e => e.outerHTML");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Only one of the selectors can capture using * modifier"));
|
||||
}
|
||||
}
|
||||
@ -179,7 +179,7 @@ public class TestEvalOnSelector extends TestBase {
|
||||
try {
|
||||
page.evalOnSelector("*=div", "e => e.outerHTML");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Unknown engine \"\" while parsing selector *=div"));
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class TestFrameNavigate extends TestBase {
|
||||
String url = server.PREFIX + "/frames/child-redirect.html";
|
||||
try {
|
||||
page.navigate(url, new Page.NavigateOptions().withTimeout(5000).withWaitUntil(NETWORKIDLE));
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout 5000ms exceeded."));
|
||||
assertTrue(e.getMessage().contains("navigating to \"" + url +"\", waiting until \"networkidle\""));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class TestPageBasic extends TestBase {
|
||||
try {
|
||||
newPage.evaluate("() => new Promise(r => {})");
|
||||
fail("evaluate should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Protocol error"));
|
||||
}
|
||||
}
|
||||
@ -108,14 +108,14 @@ public class TestPageBasic extends TestBase {
|
||||
try {
|
||||
request.get();
|
||||
fail("get() should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Page closed"));
|
||||
assertFalse(e.getMessage().contains("Timeout"));
|
||||
}
|
||||
try {
|
||||
response.get();
|
||||
fail("get() should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Page closed"));
|
||||
assertFalse(e.getMessage().contains("Timeout"));
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public class TestPageExposeFunction extends TestBase {
|
||||
try {
|
||||
page.exposeFunction("foo", args -> null);
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Function \"foo\" has been already registered"));
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ public class TestPageExposeFunction extends TestBase {
|
||||
" return window['logme'](1, 2);\n" +
|
||||
"}");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("exposeBindingHandle supports a single argument, 2 received"));
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class TestPageFill extends TestBase {
|
||||
try {
|
||||
page.fill("input", "");
|
||||
fail("fill should throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("input of type \"" + type + "\" cannot be filled"), e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,7 @@ public class TestPageFill extends TestBase {
|
||||
try {
|
||||
page.fill("input", "2020-13-05");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Malformed value"));
|
||||
}
|
||||
}
|
||||
@ -94,7 +94,7 @@ public class TestPageFill extends TestBase {
|
||||
try {
|
||||
page.fill("input", "25:05");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Malformed value"));
|
||||
}
|
||||
}
|
||||
@ -113,7 +113,7 @@ public class TestPageFill extends TestBase {
|
||||
try {
|
||||
page.fill("input", "abc");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Malformed value"));
|
||||
}
|
||||
}
|
||||
@ -158,7 +158,7 @@ public class TestPageFill extends TestBase {
|
||||
try {
|
||||
page.fill("body", "");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Element is not an <input>"));
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ public class TestPageFill extends TestBase {
|
||||
try {
|
||||
page.fill("input", "abc");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Cannot type text into input[type=number]"));
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public class TestPageSelectOption extends TestBase {
|
||||
try {
|
||||
page.selectOption("body", "");
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Element is not a <select> element."));
|
||||
}
|
||||
}
|
||||
@ -180,7 +180,7 @@ public class TestPageSelectOption extends TestBase {
|
||||
try {
|
||||
page.selectOption("select", new String[]{"blue", null, "black","magenta"});
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("options.get(1): expected object, got null"));
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
Deferred<Event<Page.EventType>> event = page.waitForEvent(Page.EventType.FILECHOOSER, new Page.WaitForEventOptions().withTimeout(1));
|
||||
event.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout 1ms exceeded"));
|
||||
}
|
||||
}
|
||||
@ -141,7 +141,7 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
Deferred<Event<Page.EventType>> event = page.waitForEvent(Page.EventType.FILECHOOSER);
|
||||
event.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout 1ms exceeded"));
|
||||
}
|
||||
}
|
||||
@ -154,7 +154,7 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
try {
|
||||
event.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout 1ms exceeded"));
|
||||
}
|
||||
}
|
||||
@ -259,7 +259,7 @@ public class TestPageSetInputFiles extends TestBase {
|
||||
try {
|
||||
fileChooser.setFiles(new File[]{FILE_TO_UPLOAD, new File("src/test/resources/pptr.png")});
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Non-multiple file input can only accept single file"));
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class TestPageWaitForNavigation extends TestBase {
|
||||
try {
|
||||
promise.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
// assertTrue(e.getMessage().contains("page.waitForNavigation: Timeout 5000ms exceeded."));
|
||||
assertTrue(e.getMessage().contains("Timeout 5000ms exceeded"));
|
||||
// assertTrue(e.getMessage().contains("waiting for navigation to '**/frame.html' until 'load'"));
|
||||
@ -75,7 +75,7 @@ public class TestPageWaitForNavigation extends TestBase {
|
||||
page.click("a");
|
||||
event.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains(expectedSSLError(browserType.name())), e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -226,7 +226,7 @@ public class TestPageWaitForNavigation extends TestBase {
|
||||
"}\n");
|
||||
response.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
// assertTrue(e.getMessage().contains("waiting for navigation until \"load\""));
|
||||
assertTrue(e.getMessage().contains("frame was detached"));
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class TestPdf extends TestBase {
|
||||
return;
|
||||
}
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertFalse(e.getMessage().contains("did not throw"));
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class TestQuerySelector extends TestBase {
|
||||
try {
|
||||
page.querySelector(null);
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("selector: expected string, got undefined"));
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
try {
|
||||
result.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout 1000ms exceeded"));
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
try {
|
||||
page.waitForFunction("() => { throw new Error('oh my'); }").get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("oh my"));
|
||||
}
|
||||
}
|
||||
@ -123,7 +123,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
" return window['counter'] === 5 ? 'result' : false;\n" +
|
||||
"}").get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Bad counter!"));
|
||||
}
|
||||
}
|
||||
@ -133,7 +133,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
try {
|
||||
page.waitForFunction("() => globalVar === 123").get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("globalVar"));
|
||||
}
|
||||
}
|
||||
@ -157,7 +157,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
try {
|
||||
page.waitForFunction("() => !!document.body", null, new Page.WaitForFunctionOptions().withPollingInterval(-10)).get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Cannot poll with non-positive interval"));
|
||||
}
|
||||
}
|
||||
@ -186,7 +186,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
try {
|
||||
page.waitForFunction("false", null, new Page.WaitForFunctionOptions().withTimeout(10)).get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout 10ms exceeded"));
|
||||
}
|
||||
}
|
||||
@ -197,7 +197,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
try {
|
||||
page.waitForFunction("false").get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout 1ms exceeded"));
|
||||
}
|
||||
}
|
||||
@ -296,7 +296,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
"}");
|
||||
result.get();
|
||||
fail("did not throw");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("waitForFunction1"));
|
||||
}
|
||||
page.reload();
|
||||
@ -305,7 +305,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
" console.log('waitForFunction2');\n" +
|
||||
" throw new Error('waitForFunction2');\n" +
|
||||
"}").get();
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("waitForFunction2"));
|
||||
}
|
||||
page.reload();
|
||||
@ -314,7 +314,7 @@ public class TestWaitForFunction extends TestBase {
|
||||
" console.log('waitForFunction3');\n" +
|
||||
" throw new Error('waitForFunction3');\n" +
|
||||
"}").get();
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("waitForFunction3"));
|
||||
}
|
||||
assertEquals(asList("waitForFunction1", "waitForFunction2", "waitForFunction3"), messages);
|
||||
|
@ -48,7 +48,7 @@ public class TestWorkers extends TestBase {
|
||||
assertEquals(worker, workerDestroyedPromise.get().data());
|
||||
try {
|
||||
workerThisObj.getProperty("self");
|
||||
} catch (RuntimeException e) {
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Most likely the worker has been closed."));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user