Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add account lockout test #3406

Draft
wants to merge 1 commit into
base: 4.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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.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.$;

/**
* Represents a Login page.
*/
Expand All @@ -23,22 +24,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,37 @@
package io.hawt.tests.features.stepdefinitions.throttling;

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 org.openqa.selenium.By;

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

public class ThrottlingStepDefs {
private final LoginPage loginPage = new LoginPage();
private static final By WARNING = By.cssSelector("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 for {int} second(s)")
public void theUserShouldSeeAMessageIndicatingAccountLockoutForIntSeconds(int seconds) {
$(WARNING).shouldHave(text("Login attempt blocked. Retry after " + 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 for 1 second
When the user attempts to log in with incorrect credentials 2 times
Then the user should see a message indicating account lockout for 3 seconds