Skip to content

Commit

Permalink
Merge branch '6.1.x' into 6.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusdacoregio committed Mar 14, 2024
2 parents f64d122 + 4ab8b84 commit 8e41e65
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
6 changes: 1 addition & 5 deletions servlet/spring-boot/java/cas/login/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ dependencies {
implementation 'org.springframework.security:spring-security-cas'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'

testImplementation 'net.sourceforge.htmlunit:htmlunit'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation "org.testcontainers:junit-jupiter"
testImplementation 'com.codeborne:selenide:7.0.2'
testImplementation 'org.seleniumhq.selenium:selenium-chrome-driver'
testImplementation 'org.seleniumhq.selenium:selenium-java'
testImplementation 'io.github.bonigarcia:webdrivermanager:5.6.4'
testImplementation 'com.microsoft.playwright:playwright:1.42.0'
}

tasks.withType(Test).configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package cas.example;

import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.Selenide;
import io.github.bonigarcia.wdm.WebDriverManager;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
Expand Down Expand Up @@ -54,6 +53,10 @@ class CasLoginApplicationTests {
BindMode.READ_WRITE)
.waitingFor(Wait.forLogMessage(".*Ready to process requests.*", 1));

Playwright playwright;

Browser browser;

@DynamicPropertySource
static void casProperties(DynamicPropertyRegistry registry) {
String casUrl = String.format("http://%s:%s/cas", casServer.getHost(), casServer.getMappedPort(8080));
Expand All @@ -62,42 +65,42 @@ static void casProperties(DynamicPropertyRegistry registry) {
registry.add("cas.logout.url", () -> casUrl + "/logout");
}

@BeforeAll
static void setUp() {
WebDriverManager.chromedriver()
.clearDriverCache()
.clearResolutionCache()
.browserInDocker()
.browserVersion("114")
.setup();
Configuration.headless = true;
@BeforeEach
void setUp() {
this.playwright = Playwright.create();
this.browser = this.playwright.chromium().launch();
}

@AfterEach
void setup() {
Selenide.closeWindow();
this.browser.close();
this.playwright.close();
}

@Test
void login() {
doLogin();
String lead = Selenide.$(By.className("lead")).text();
assertThat(lead).isEqualTo("You are successfully logged in as casuser");
}

private void doLogin() {
Selenide.open("http://localhost:" + this.port);
Selenide.$(By.name("username")).setValue("casuser");
Selenide.$(By.name("password")).setValue("Mellon");
Selenide.$(By.name("submitBtn")).click();
try (Page page = doLogin()) {
String lead = page.locator(".lead").textContent();
assertThat(lead).isEqualTo("You are successfully logged in as casuser");
}
}

@Test
void loginAndLogout() {
doLogin();
Selenide.$(By.id("rp_logout_button")).click();
String logoutMsg = Selenide.$(By.id("logout-msg")).text();
assertThat(logoutMsg).isEqualTo("You are successfully logged out of the app, but not CAS");
try (Page page = doLogin()) {
page.click("#rp_logout_button");
String logoutMsg = page.locator("#logout-msg").textContent();
assertThat(logoutMsg).isEqualTo("You are successfully logged out of the app, but not CAS");
}
}

private Page doLogin() {
Page page = this.browser.newPage();
page.navigate("http://localhost:" + this.port);
page.fill("//input[@name='username']", "casuser");
page.fill("//input[@name='password']", "Mellon");
page.click("//button[@name='submitBtn']");
return page;
}

}

0 comments on commit 8e41e65

Please sign in to comment.