diff --git a/playwright/src/main/java/com/microsoft/playwright/PlaywrightException.java b/playwright/src/main/java/com/microsoft/playwright/PlaywrightException.java new file mode 100644 index 00000000..609d8781 --- /dev/null +++ b/playwright/src/main/java/com/microsoft/playwright/PlaywrightException.java @@ -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); + } +} diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java index 9fd3b2b8..69c626f8 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/BrowserContextImpl.java @@ -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()); diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java b/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java index 3262dfee..7d2226d4 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java @@ -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 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 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; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/DeviceDescriptorImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/DeviceDescriptorImpl.java index 1e125729..09d9e182 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/DeviceDescriptorImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/DeviceDescriptorImpl.java @@ -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); } } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java index 2832b5ad..41390c9c 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java @@ -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"); diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java index 6ab20f5c..b627a5ce 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java @@ -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 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 diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java index 0eb649e5..c784b4de 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PlaywrightImpl.java @@ -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); } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java index be3d7563..cbbf8450 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java @@ -44,7 +44,7 @@ class Serialization { private static SerializedValue serializeValue(Object value, List 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); } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Transport.java b/playwright/src/main/java/com/microsoft/playwright/impl/Transport.java index c96ce003..dc7cd723 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Transport.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Transport.java @@ -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); } } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java index 8955f997..308a9e8d 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java @@ -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); } } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/WaitableResult.java b/playwright/src/main/java/com/microsoft/playwright/impl/WaitableResult.java index 56d40921..baf9f6b5 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/WaitableResult.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/WaitableResult.java @@ -16,6 +16,8 @@ package com.microsoft.playwright.impl; +import com.microsoft.playwright.PlaywrightException; + class WaitableResult implements Waitable { private T result; private RuntimeException exception; @@ -45,7 +47,7 @@ class WaitableResult implements Waitable { @Override public T get() { if (exception != null) { - throw new RuntimeException(exception); + throw new PlaywrightException(exception.getMessage(), exception); } return result; } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/WaitableTimeout.java b/playwright/src/main/java/com/microsoft/playwright/impl/WaitableTimeout.java index 23b93fa9..76558d3a 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/WaitableTimeout.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/WaitableTimeout.java @@ -16,6 +16,8 @@ package com.microsoft.playwright.impl; +import com.microsoft.playwright.PlaywrightException; + class WaitableTimeout implements Waitable { private final long deadline; private final int timeout; @@ -32,7 +34,7 @@ class WaitableTimeout implements Waitable { @Override public T get() { - throw new RuntimeException("Timeout " + timeout + "ms exceeded"); + throw new PlaywrightException("Timeout " + timeout + "ms exceeded"); } @Override diff --git a/playwright/src/test/java/com/microsoft/playwright/TestBrowser.java b/playwright/src/test/java/com/microsoft/playwright/TestBrowser.java index 1bad3bce..07777c45 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestBrowser.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestBrowser.java @@ -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(); diff --git a/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextExposeFunction.java b/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextExposeFunction.java index b1769220..72c5d842 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextExposeFunction.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestBrowserContextExposeFunction.java @@ -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")); } } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestClick.java b/playwright/src/test/java/com/microsoft/playwright/TestClick.java index 9027c719..32767336 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestClick.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestClick.java @@ -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); diff --git a/playwright/src/test/java/com/microsoft/playwright/TestElementHandleClick.java b/playwright/src/test/java/com/microsoft/playwright/TestElementHandleClick.java index 5c8c44db..96fe273e 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestElementHandleClick.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestElementHandleClick.java @@ -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")); } } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestElementHandleWaitForElementState.java b/playwright/src/test/java/com/microsoft/playwright/TestElementHandleWaitForElementState.java index 5364da33..7a969556 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestElementHandleWaitForElementState.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestElementHandleWaitForElementState.java @@ -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")); } } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestEvalOnSelector.java b/playwright/src/test/java/com/microsoft/playwright/TestEvalOnSelector.java index abed9125..af5ed808 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestEvalOnSelector.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestEvalOnSelector.java @@ -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")); } } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestFrameNavigate.java b/playwright/src/test/java/com/microsoft/playwright/TestFrameNavigate.java index 19ec5895..16820a55 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestFrameNavigate.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestFrameNavigate.java @@ -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\"")); } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java b/playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java index 455db550..11ffa08e 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageBasic.java @@ -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")); } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageExposeFunction.java b/playwright/src/test/java/com/microsoft/playwright/TestPageExposeFunction.java index 53bac29f..60aa4fe1 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageExposeFunction.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageExposeFunction.java @@ -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")); } } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageFill.java b/playwright/src/test/java/com/microsoft/playwright/TestPageFill.java index 87859501..44d3a866 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageFill.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageFill.java @@ -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 ")); } } @@ -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]")); } } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageSelectOption.java b/playwright/src/test/java/com/microsoft/playwright/TestPageSelectOption.java index 31381621..a3450cf2 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageSelectOption.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageSelectOption.java @@ -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