16
16
17
17
package cas .example ;
18
18
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 ;
22
22
import org .junit .jupiter .api .AfterEach ;
23
- import org .junit .jupiter .api .BeforeAll ;
23
+ import org .junit .jupiter .api .BeforeEach ;
24
24
import org .junit .jupiter .api .Test ;
25
- import org .openqa .selenium .By ;
26
25
import org .testcontainers .containers .BindMode ;
27
26
import org .testcontainers .containers .GenericContainer ;
28
27
import org .testcontainers .containers .wait .strategy .Wait ;
@@ -54,6 +53,10 @@ class CasLoginApplicationTests {
54
53
BindMode .READ_WRITE )
55
54
.waitingFor (Wait .forLogMessage (".*Ready to process requests.*" , 1 ));
56
55
56
+ Playwright playwright ;
57
+
58
+ Browser browser ;
59
+
57
60
@ DynamicPropertySource
58
61
static void casProperties (DynamicPropertyRegistry registry ) {
59
62
String casUrl = String .format ("http://%s:%s/cas" , casServer .getHost (), casServer .getMappedPort (8080 ));
@@ -62,42 +65,42 @@ static void casProperties(DynamicPropertyRegistry registry) {
62
65
registry .add ("cas.logout.url" , () -> casUrl + "/logout" );
63
66
}
64
67
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 ();
74
72
}
75
73
76
74
@ AfterEach
77
75
void setup () {
78
- Selenide .closeWindow ();
76
+ this .browser .close ();
77
+ this .playwright .close ();
79
78
}
80
79
81
80
@ Test
82
81
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
+ }
93
86
}
94
87
95
88
@ Test
96
89
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 ;
101
104
}
102
105
103
106
}
0 commit comments