Skip to content

Commit 8e41e65

Browse files
Merge branch '6.1.x' into 6.2.x
2 parents f64d122 + 4ab8b84 commit 8e41e65

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

servlet/spring-boot/java/cas/login/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ dependencies {
1818
implementation 'org.springframework.security:spring-security-cas'
1919
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
2020

21-
testImplementation 'net.sourceforge.htmlunit:htmlunit'
2221
testImplementation 'org.springframework.boot:spring-boot-starter-test'
2322
testImplementation 'org.springframework.security:spring-security-test'
2423
testImplementation "org.testcontainers:junit-jupiter"
25-
testImplementation 'com.codeborne:selenide:7.0.2'
26-
testImplementation 'org.seleniumhq.selenium:selenium-chrome-driver'
27-
testImplementation 'org.seleniumhq.selenium:selenium-java'
28-
testImplementation 'io.github.bonigarcia:webdrivermanager:5.6.4'
24+
testImplementation 'com.microsoft.playwright:playwright:1.42.0'
2925
}
3026

3127
tasks.withType(Test).configureEach {

servlet/spring-boot/java/cas/login/src/test/java/cas/example/CasLoginApplicationTests.java

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616

1717
package cas.example;
1818

19-
import com.codeborne.selenide.Configuration;
20-
import com.codeborne.selenide.Selenide;
21-
import io.github.bonigarcia.wdm.WebDriverManager;
19+
import com.microsoft.playwright.Browser;
20+
import com.microsoft.playwright.Page;
21+
import com.microsoft.playwright.Playwright;
2222
import org.junit.jupiter.api.AfterEach;
23-
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.jupiter.api.BeforeEach;
2424
import org.junit.jupiter.api.Test;
25-
import org.openqa.selenium.By;
2625
import org.testcontainers.containers.BindMode;
2726
import org.testcontainers.containers.GenericContainer;
2827
import org.testcontainers.containers.wait.strategy.Wait;
@@ -54,6 +53,10 @@ class CasLoginApplicationTests {
5453
BindMode.READ_WRITE)
5554
.waitingFor(Wait.forLogMessage(".*Ready to process requests.*", 1));
5655

56+
Playwright playwright;
57+
58+
Browser browser;
59+
5760
@DynamicPropertySource
5861
static void casProperties(DynamicPropertyRegistry registry) {
5962
String casUrl = String.format("http://%s:%s/cas", casServer.getHost(), casServer.getMappedPort(8080));
@@ -62,42 +65,42 @@ static void casProperties(DynamicPropertyRegistry registry) {
6265
registry.add("cas.logout.url", () -> casUrl + "/logout");
6366
}
6467

65-
@BeforeAll
66-
static void setUp() {
67-
WebDriverManager.chromedriver()
68-
.clearDriverCache()
69-
.clearResolutionCache()
70-
.browserInDocker()
71-
.browserVersion("114")
72-
.setup();
73-
Configuration.headless = true;
68+
@BeforeEach
69+
void setUp() {
70+
this.playwright = Playwright.create();
71+
this.browser = this.playwright.chromium().launch();
7472
}
7573

7674
@AfterEach
7775
void setup() {
78-
Selenide.closeWindow();
76+
this.browser.close();
77+
this.playwright.close();
7978
}
8079

8180
@Test
8281
void login() {
83-
doLogin();
84-
String lead = Selenide.$(By.className("lead")).text();
85-
assertThat(lead).isEqualTo("You are successfully logged in as casuser");
86-
}
87-
88-
private void doLogin() {
89-
Selenide.open("http://localhost:" + this.port);
90-
Selenide.$(By.name("username")).setValue("casuser");
91-
Selenide.$(By.name("password")).setValue("Mellon");
92-
Selenide.$(By.name("submitBtn")).click();
82+
try (Page page = doLogin()) {
83+
String lead = page.locator(".lead").textContent();
84+
assertThat(lead).isEqualTo("You are successfully logged in as casuser");
85+
}
9386
}
9487

9588
@Test
9689
void loginAndLogout() {
97-
doLogin();
98-
Selenide.$(By.id("rp_logout_button")).click();
99-
String logoutMsg = Selenide.$(By.id("logout-msg")).text();
100-
assertThat(logoutMsg).isEqualTo("You are successfully logged out of the app, but not CAS");
90+
try (Page page = doLogin()) {
91+
page.click("#rp_logout_button");
92+
String logoutMsg = page.locator("#logout-msg").textContent();
93+
assertThat(logoutMsg).isEqualTo("You are successfully logged out of the app, but not CAS");
94+
}
95+
}
96+
97+
private Page doLogin() {
98+
Page page = this.browser.newPage();
99+
page.navigate("http://localhost:" + this.port);
100+
page.fill("//input[@name='username']", "casuser");
101+
page.fill("//input[@name='password']", "Mellon");
102+
page.click("//button[@name='submitBtn']");
103+
return page;
101104
}
102105

103106
}

0 commit comments

Comments
 (0)