Skip to content

Commit

Permalink
Add account lockout test
Browse files Browse the repository at this point in the history
  • Loading branch information
kariuwu committed Apr 23, 2024
1 parent 67089cf commit 8c4f74b
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package io.hawt.tests.features.pageobjects.pages;

import static com.codeborne.selenide.Condition.editable;
import static com.codeborne.selenide.Condition.enabled;
import static com.codeborne.selenide.Condition.exist;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;

import org.assertj.core.api.Assertions;

import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
import com.codeborne.selenide.WebDriverRunner;
import com.codeborne.selenide.ex.ElementNotFound;
import org.assertj.core.api.Assertions;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.time.Duration;

import static com.codeborne.selenide.Condition.*;
import static com.codeborne.selenide.Selenide.$;

/**
* Represents a Login page.
*/
Expand All @@ -22,16 +20,33 @@ public class LoginPage {
private final static SelenideElement loginInput = $("#pf-login-username-id");
private final static SelenideElement passwordInput = $("#pf-login-password-id");
private final static SelenideElement loginButton = $("button[type='submit']");
private final static SelenideElement warning = $("p.pf-c-form__helper-text.pf-m-error").$("Login attempt blocked");


/**
* Login to hawtio as given user with given password.
*/

public void login(String username, String password) {
try {
String pass = "gojo";
int maxRetries = 7;
int retries = 0;
while (!warning.isDisplayed() && retries < maxRetries) {
Selenide.Wait().until(ExpectedConditions.visibilityOf(loginButton));
loginInput.shouldBe(editable).setValue(username);
passwordInput.shouldBe(editable).setValue(pass);
loginButton.shouldBe(enabled).click();
retries++;
}


Selenide.Wait().until(ExpectedConditions.visibilityOf(loginButton));
loginDiv.shouldBe(visible, Duration.ofSeconds(5)).should(exist);
loginInput.shouldBe(editable).setValue(username);
passwordInput.shouldBe(editable).setValue(password);
loginButton.shouldBe(enabled).click();

} catch (ElementNotFound e) {
Assertions.assertThat(WebDriverRunner.url())
.withFailMessage(() -> "Failed to login on login page: " + e)
Expand Down

0 comments on commit 8c4f74b

Please sign in to comment.