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 May 14, 2024
1 parent 758fdb9 commit a5fb0f2
Show file tree
Hide file tree
Showing 3 changed files with 76 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 @@ -23,22 +21,35 @@ public class LoginPage {
private final static SelenideElement passwordInput = $("#pf-login-password-id");
private final static SelenideElement loginButton = $("button[type='submit']");


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

public void login(String username, String password) {
try {
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)
.doesNotContain("login");
}
}

public void throttling(String username, String invalidPassword) {

Selenide.Wait().until(ExpectedConditions.visibilityOf(loginButton));
loginInput.shouldBe(editable).setValue(username);
passwordInput.shouldBe(editable).setValue(invalidPassword);
loginButton.shouldBe(enabled).click();

}

/**
* Check whether the Login page is open and active
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.hawt.tests.features.stepdefinitions.throttling;

import com.codeborne.selenide.SelenideElement;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.hawt.tests.features.pageobjects.pages.LoginPage;
import io.hawt.tests.features.setup.LoginLogout;

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

public class ThrottlingStepDefs {
private final LoginPage loginPage = new LoginPage();
private final static SelenideElement warning = $("p.pf-c-form__helper-text.pf-m-error");


@Given("User is on Login page")
public void userIsOnLoginPage() {
LoginLogout.logout();
loginPage.loginPageIsOpened();
}

@When("the user attempts to log in with incorrect credentials {int} times")
public void theUserAttemptsToLogInWithIncorrectCredentialsTimes(int attempts) {
for (int i = 0; i < attempts; i++) {
loginPage.throttling("username", "invalid");
}

}

@Then("the user should see a message indicating account lockout")
public void theUserShouldSeeAMessageIndicatingAccountLockout() {
warning.shouldHave(text("Login attempt blocked. Retry after 1 second"));
}

@When("the user attempts to log in with incorrect credential {int} times")
public void theUserAttemptsToLogInWithIncorrectCredentialTimes(int attempts) {
for (int i = 0; i < attempts; i++) {
loginPage.throttling("username", "invalid");
}
}

@Then("the user should see a message indicating account lockout second time")
public void theUserShouldSeeAMessageIndicatingAccountLockoutSecondTime() {
warning.shouldHave(text("Login attempt blocked. Retry after 3 seconds"));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Account Lockout (Throttling)

Scenario: User account gets locked out after multiple failed login attempts
Given User is on Login page
When the user attempts to log in with incorrect credentials 5 times
Then the user should see a message indicating account lockout
When the user attempts to log in with incorrect credential 2 times
Then the user should see a message indicating account lockout second time

0 comments on commit a5fb0f2

Please sign in to comment.