From 1df40e5882b963ccaa44ff5e4c586a50a8517cb8 Mon Sep 17 00:00:00 2001 From: alanv Date: Wed, 10 Jun 2026 12:05:10 -0500 Subject: [PATCH 1/2] LabKeySiteWrapper: add attemptReauth --- src/org/labkey/test/LabKeySiteWrapper.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/org/labkey/test/LabKeySiteWrapper.java b/src/org/labkey/test/LabKeySiteWrapper.java index 90a67cf466..d84c3952eb 100644 --- a/src/org/labkey/test/LabKeySiteWrapper.java +++ b/src/org/labkey/test/LabKeySiteWrapper.java @@ -388,10 +388,17 @@ public void attemptSignIn(String email) public void attemptSignIn(String email, String password) { - if (isSignedIn()) + attemptSignIn(email, password, false); + } + + public void attemptSignIn(String email, String password, boolean isReAuth) + { + if (!isReAuth && isSignedIn()) throw new IllegalStateException("You need to be logged out to log in. Please log out to log in."); - if (!getDriver().getTitle().contains("Sign In")) + boolean onLoginPage = getDriver().getTitle().contains("Sign In"); + + if (!onLoginPage && !isReAuth) { try { @@ -403,13 +410,17 @@ public void attemptSignIn(String email, String password) throw new IllegalStateException("Unable to find \"Sign In\" link on current page.", error); } } + else if (!onLoginPage) + { + throw new IllegalStateException("Unable to Sign In, not already on the Sign In page"); + } assertTitleContains("Sign In"); assertElementPresent(Locator.tagWithName("form", "login")); setFormElement(Locator.id("email"), email); setFormElement(Locator.id("password"), password); - WebElement signInButton = Locator.button("Sign In").findElement(getDriver()); + WebElement signInButton = Locator.byClass("signin-btn").findElement(getDriver()); doAndMaybeWaitForPageToLoad(10_000, () -> { signInButton.click(); shortWait().until(ExpectedConditions.invisibilityOfElementLocated(Locator.byClass("signing-in-msg"))); @@ -420,6 +431,11 @@ public void attemptSignIn(String email, String password) }); } + public void attemptReauth() + { + attemptSignIn(PasswordUtil.getUsername(), PasswordUtil.getPassword(), true); + } + public void signInShouldFail(String email, String password, String... expectedMessages) { attemptSignIn(email, password); From d7ebf6578c47eabad16e83200e27d86fd112e53d Mon Sep 17 00:00:00 2001 From: alanv Date: Wed, 10 Jun 2026 16:34:11 -0500 Subject: [PATCH 2/2] Add SignInPage, use in LabKeySiteWrapper. Remove attemptReauth. --- src/org/labkey/test/LabKeySiteWrapper.java | 36 ++-------- .../test/pages/core/login/SignInPage.java | 70 +++++++++++++++++++ 2 files changed, 74 insertions(+), 32 deletions(-) create mode 100644 src/org/labkey/test/pages/core/login/SignInPage.java diff --git a/src/org/labkey/test/LabKeySiteWrapper.java b/src/org/labkey/test/LabKeySiteWrapper.java index d84c3952eb..41b752d1e6 100644 --- a/src/org/labkey/test/LabKeySiteWrapper.java +++ b/src/org/labkey/test/LabKeySiteWrapper.java @@ -54,6 +54,7 @@ import org.labkey.test.components.ui.navigation.UserMenu; import org.labkey.test.pages.core.admin.CustomizeSitePage; import org.labkey.test.pages.core.admin.ShowAdminPage; +import org.labkey.test.pages.core.login.SignInPage; import org.labkey.test.pages.user.UserDetailsPage; import org.labkey.test.util.APIUserHelper; import org.labkey.test.util.ApiPermissionsHelper; @@ -388,17 +389,10 @@ public void attemptSignIn(String email) public void attemptSignIn(String email, String password) { - attemptSignIn(email, password, false); - } - - public void attemptSignIn(String email, String password, boolean isReAuth) - { - if (!isReAuth && isSignedIn()) + if (isSignedIn()) throw new IllegalStateException("You need to be logged out to log in. Please log out to log in."); - boolean onLoginPage = getDriver().getTitle().contains("Sign In"); - - if (!onLoginPage && !isReAuth) + if (!getDriver().getTitle().contains("Sign In")) { try { @@ -410,30 +404,8 @@ public void attemptSignIn(String email, String password, boolean isReAuth) throw new IllegalStateException("Unable to find \"Sign In\" link on current page.", error); } } - else if (!onLoginPage) - { - throw new IllegalStateException("Unable to Sign In, not already on the Sign In page"); - } - assertTitleContains("Sign In"); - - assertElementPresent(Locator.tagWithName("form", "login")); - setFormElement(Locator.id("email"), email); - setFormElement(Locator.id("password"), password); - WebElement signInButton = Locator.byClass("signin-btn").findElement(getDriver()); - doAndMaybeWaitForPageToLoad(10_000, () -> { - signInButton.click(); - shortWait().until(ExpectedConditions.invisibilityOfElementLocated(Locator.byClass("signing-in-msg"))); - shortWait().until(ExpectedConditions.or( - ExpectedConditions.stalenessOf(signInButton), // Successful login - ExpectedConditions.presenceOfElementLocated(Locators.labkeyError.withText()))); // Error during sign-in - return ExpectedConditions.stalenessOf(signInButton).apply(null); - }); - } - - public void attemptReauth() - { - attemptSignIn(PasswordUtil.getUsername(), PasswordUtil.getPassword(), true); + new SignInPage(getDriver()).signIn(email, password); } public void signInShouldFail(String email, String password, String... expectedMessages) diff --git a/src/org/labkey/test/pages/core/login/SignInPage.java b/src/org/labkey/test/pages/core/login/SignInPage.java new file mode 100644 index 0000000000..df3c77156c --- /dev/null +++ b/src/org/labkey/test/pages/core/login/SignInPage.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2026 LabKey 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 org.labkey.test.pages.core.login; + +import org.labkey.test.Locator; +import org.labkey.test.Locators; +import org.labkey.test.pages.LabKeyPage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + +/** + * Page object for the LabKey "Sign In" page. This object assumes the browser is already on the Sign In page; it does + * not handle navigating to it (e.g. clicking a "Sign In" link). + */ +public class SignInPage extends LabKeyPage +{ + public SignInPage(WebDriver driver) + { + super(driver); + } + + @Override + protected void waitForPage() + { + waitFor(() -> getDriver().getTitle().contains("Sign In") && isElementPresent(Locator.tagWithName("form", "login")), + "Sign In page did not load in time.", WAIT_FOR_PAGE); + } + + public void signIn(String userName, String password) + { + setFormElement(elementCache().emailInput, userName); + setFormElement(elementCache().passwordInput, password); + WebElement signInButton = elementCache().signInButton; + doAndMaybeWaitForPageToLoad(10_000, () -> { + signInButton.click(); + shortWait().until(ExpectedConditions.invisibilityOfElementLocated(Locator.byClass("signing-in-msg"))); + shortWait().until(ExpectedConditions.or( + ExpectedConditions.stalenessOf(signInButton), // Successful login + ExpectedConditions.presenceOfElementLocated(Locators.labkeyError.withText()))); // Error during sign-in + return ExpectedConditions.stalenessOf(signInButton).apply(null); + }); + } + + @Override + protected ElementCache newElementCache() + { + return new ElementCache(); + } + + protected class ElementCache extends LabKeyPage.ElementCache + { + WebElement emailInput = Locator.id("email").findWhenNeeded(getDriver()); + WebElement passwordInput = Locator.id("password").findWhenNeeded(getDriver()); + WebElement signInButton = Locator.byClass("signin-btn").findWhenNeeded(getDriver()); + } +}