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