2025-03-10 08:38:21 +01:00
|
|
|
package com.commafeed.e2e;
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
2025-06-26 21:30:29 +02:00
|
|
|
import com.microsoft.playwright.BrowserContext;
|
2025-03-10 08:38:21 +01:00
|
|
|
import com.microsoft.playwright.Locator;
|
|
|
|
|
import com.microsoft.playwright.Page;
|
|
|
|
|
import com.microsoft.playwright.assertions.PlaywrightAssertions;
|
|
|
|
|
import com.microsoft.playwright.options.AriaRole;
|
|
|
|
|
|
2025-06-26 21:30:29 +02:00
|
|
|
import io.quarkiverse.playwright.InjectPlaywright;
|
|
|
|
|
import io.quarkiverse.playwright.WithPlaywright;
|
2025-03-10 08:38:21 +01:00
|
|
|
import io.quarkus.test.junit.QuarkusTest;
|
|
|
|
|
|
|
|
|
|
@QuarkusTest
|
2025-06-26 21:30:29 +02:00
|
|
|
@WithPlaywright
|
2025-03-10 08:38:21 +01:00
|
|
|
class AuthentificationIT {
|
|
|
|
|
|
2025-06-26 21:30:29 +02:00
|
|
|
@InjectPlaywright
|
|
|
|
|
private BrowserContext context;
|
2025-03-10 08:38:21 +01:00
|
|
|
|
|
|
|
|
@AfterEach
|
|
|
|
|
void cleanup() {
|
2025-06-26 21:30:29 +02:00
|
|
|
context.clearCookies();
|
2025-03-10 08:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void loginFail() {
|
2025-06-26 21:30:29 +02:00
|
|
|
Page page = context.newPage();
|
2025-03-10 08:38:21 +01:00
|
|
|
page.navigate(getLoginPageUrl());
|
2025-06-30 08:08:01 +02:00
|
|
|
PlaywrightTestUtils.login(page, "admin", "wrong_password");
|
2025-03-10 08:38:21 +01:00
|
|
|
PlaywrightAssertions.assertThat(page.getByRole(AriaRole.ALERT)).containsText("wrong username or password");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void loginSuccess() {
|
2025-06-26 21:30:29 +02:00
|
|
|
Page page = context.newPage();
|
2025-03-10 08:38:21 +01:00
|
|
|
page.navigate(getLoginPageUrl());
|
|
|
|
|
PlaywrightTestUtils.login(page);
|
|
|
|
|
PlaywrightAssertions.assertThat(page).hasURL("http://localhost:8085/#/app/category/all");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void registerFailPasswordTooSimple() {
|
2025-06-26 21:30:29 +02:00
|
|
|
Page page = context.newPage();
|
2025-03-10 08:38:21 +01:00
|
|
|
page.navigate(getLoginPageUrl());
|
|
|
|
|
page.getByText("Sign up!").click();
|
2025-06-30 08:08:01 +02:00
|
|
|
PlaywrightTestUtils.register(page, "user", "user@domain.com", "pass");
|
2025-03-10 08:38:21 +01:00
|
|
|
|
|
|
|
|
Locator alert = page.getByRole(AriaRole.ALERT);
|
|
|
|
|
PlaywrightAssertions.assertThat(alert).containsText("Password must be 8 or more characters in length.");
|
|
|
|
|
PlaywrightAssertions.assertThat(alert).containsText("Password must contain 1 or more uppercase characters.");
|
|
|
|
|
PlaywrightAssertions.assertThat(alert).containsText("Password must contain 1 or more digit characters.");
|
|
|
|
|
PlaywrightAssertions.assertThat(alert).containsText("Password must contain 1 or more special characters.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void registerSuccess() {
|
2025-06-26 21:30:29 +02:00
|
|
|
Page page = context.newPage();
|
2025-03-10 08:38:21 +01:00
|
|
|
page.navigate(getLoginPageUrl());
|
|
|
|
|
page.getByText("Sign up!").click();
|
2025-06-30 08:08:01 +02:00
|
|
|
PlaywrightTestUtils.register(page, "user", "user@domain.com", "MyPassword1!");
|
2025-03-10 08:38:21 +01:00
|
|
|
PlaywrightAssertions.assertThat(page).hasURL("http://localhost:8085/#/app/category/all");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getLoginPageUrl() {
|
|
|
|
|
return "http://localhost:8085/#/login";
|
|
|
|
|
}
|
|
|
|
|
}
|