From 3bf1bb19ccfc297f93be164097d5ea27ea9d0fd9 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Sat, 6 Jun 2026 11:24:28 -0700 Subject: [PATCH] Give more helpful feedback when remote connection fails --- .../test/util/RemoteConnectionHelper.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/org/labkey/test/util/RemoteConnectionHelper.java b/src/org/labkey/test/util/RemoteConnectionHelper.java index 101218b60c..0eb6d9b41d 100644 --- a/src/org/labkey/test/util/RemoteConnectionHelper.java +++ b/src/org/labkey/test/util/RemoteConnectionHelper.java @@ -53,6 +53,18 @@ public boolean testConnection(String name) return success; } + /** Test the named connection, expecting failure with an error message starting with the given prefix. The full message may include environment-specific exception text. */ + public void testConnectionExpectFailure(String name, String expectedErrorPrefix) + { + WebElement target = findConnectionStrict(name, "test"); + _test.clickAndWait(target, _test.getDefaultWaitForPage()); + _test.assertTextPresent("not successful"); + String error = getDisplayedError(); + Assert.assertNotNull("No error message shown on connection test failure page", error); + Assert.assertTrue("Expected error message to start with '" + expectedErrorPrefix + "' but was: " + error, error.startsWith(expectedErrorPrefix)); + _test.clickAndWait(Locator.linkWithText("Manage Remote Connections")); + } + public void createConnection(String name, String url, String container, String user, String password, String expectedError) { _test.clickAndWait(Locator.linkWithText("Create New Connection")); @@ -61,6 +73,18 @@ public void createConnection(String name, String url, String container, String u verifyExpectedError(expectedError); } + /** Expect the save to fail with an error message starting with the given prefix. The full message may include environment-specific exception text. */ + public void createConnectionExpectErrorPrefix(String name, String url, String container, String user, String password, String expectedErrorPrefix) + { + _test.clickAndWait(Locator.linkWithText("Create New Connection")); + setConnectionProperties(name, url, container, user, password); + _test.clickButton("save"); + String error = getDisplayedError(); + Assert.assertNotNull("No error message shown after attempting to save connection", error); + Assert.assertTrue("Expected error message to start with '" + expectedErrorPrefix + "' but was: " + error, error.startsWith(expectedErrorPrefix)); + _test.clickButton("cancel"); + } + public void editConnection(String name, String newName, String newUrl, String newContainer, String newUser, String newPassword) { editConnection(name, newName, newUrl, newContainer, newUser, newPassword, null); @@ -137,12 +161,17 @@ private void verifyExpectedError(String expectedError) { if (null != expectedError) { - String error = Locators.labkeyError.findOptionalElement(_test.getDriver()).map(WebElement::getText).orElse(null); + String error = getDisplayedError(); Assert.assertEquals("Remote connection error.", expectedError, error); _test.clickButton("cancel"); } } + private String getDisplayedError() + { + return Locators.labkeyError.findOptionalElement(_test.getDriver()).map(WebElement::getText).orElse(null); + } + private WebElement findConnection(String name, String action) { List items = Locator.xpath("//a[contains(text(), '" + action + "')]").findElements(_test.getDriver());