@@ -9,32 +9,79 @@ import { expect, test } from '@playwright/test';
99import { asyncEvents } from './utils/async-events.js' ;
1010import { username , password } from './utils/demo-user.js' ;
1111
12- test . skip ( 'Test happy paths on test page ', async ( { page } ) => {
13- const { clickButton , navigate } = asyncEvents ( page ) ;
14- await navigate ( '/?journey=TEST_Protect' ) ;
12+ test . describe ( 'PingOne Protect Journey ', ( ) => {
13+ test ( 'should complete journey with Protect initialization and evaluation' , async ( { page } ) => {
14+ const { clickButton } = asyncEvents ( page ) ;
1515
16- const messageArray : string [ ] = [ ] ;
16+ const messageArray : string [ ] = [ ] ;
1717
18- // Listen for events on page
19- page . on ( 'console' , async ( msg ) => {
20- messageArray . push ( msg . text ( ) ) ;
21- return Promise . resolve ( true ) ;
22- } ) ;
18+ // Listen for console messages
19+ page . on ( 'console' , async ( msg ) => {
20+ messageArray . push ( msg . text ( ) ) ;
21+ return Promise . resolve ( true ) ;
22+ } ) ;
23+
24+ // Navigate to PingOne Protect journey
25+ // Use 'load' instead of 'networkidle' because Protect SDK makes continuous requests
26+ await page . goto ( '/?journey=TEST_LoginPingProtect&clientId=basic' , { waitUntil : 'load' } ) ;
27+
28+ // Step 1: Wait for Protect initialization to display and complete
29+ await expect ( page . getByText ( 'Initializing PingOne Protect...' ) ) . toBeVisible ( { timeout : 10000 } ) ;
30+
31+ // Wait for initialization success message
32+ await expect ( page . getByText ( 'PingOne Protect initialized successfully!' ) ) . toBeVisible ( {
33+ timeout : 15000 ,
34+ } ) ;
35+
36+ // Submit the form to proceed to next step
37+ await page . getByRole ( 'button' , { name : 'Submit' } ) . click ( ) ;
38+
39+ // Wait for the journey to progress
40+ await page . waitForTimeout ( 2000 ) ;
41+
42+ // Debug: Print console messages
43+ console . log ( 'Console messages so far:' , messageArray ) ;
44+
45+ // Step 2: Perform login with username and password
46+ await expect ( page . getByLabel ( 'User Name' ) ) . toBeVisible ( { timeout : 15000 } ) ;
47+ await page . getByLabel ( 'User Name' ) . fill ( username ) ;
48+ await page . getByLabel ( 'Password' ) . fill ( password ) ;
2349
24- // Perform basic login
25- await page . getByLabel ( 'User Name' ) . fill ( username ) ;
26- await page . getByLabel ( 'Password' ) . fill ( password ) ;
27- await clickButton ( 'Submit' , '/authenticate' ) ;
50+ // Wait a bit to ensure input events have been processed
51+ await page . waitForTimeout ( 500 ) ;
2852
29- await expect ( page . getByText ( 'Collecting protect data' ) ) . toBeVisible ( ) ;
53+ await clickButton ( 'Submit' , '/authenticate' ) ;
3054
31- await expect ( page . getByText ( 'Complete' ) ) . toBeVisible ( ) ;
55+ // Step 3: Wait for Protect evaluation to display and complete
56+ await expect ( page . getByText ( 'Evaluating risk assessment...' ) ) . toBeVisible ( { timeout : 10000 } ) ;
3257
33- // Perform logout
34- await clickButton ( 'Logout' , '/authenticate' ) ;
58+ // Wait for evaluation success message
59+ await expect ( page . getByText ( 'Risk assessment completed successfully!' ) ) . toBeVisible ( {
60+ timeout : 15000 ,
61+ } ) ;
3562
36- // Test assertions
37- expect ( messageArray . includes ( 'Protect data collected successfully' ) ) . toBe ( true ) ;
38- expect ( messageArray . includes ( 'Journey completed successfully' ) ) . toBe ( true ) ;
39- expect ( messageArray . includes ( 'Logout successful' ) ) . toBe ( true ) ;
63+ // Submit the form to complete the journey
64+ await page . getByRole ( 'button' , { name : 'Submit' } ) . click ( ) ;
65+
66+ // Wait for the journey to complete
67+ await page . waitForTimeout ( 2000 ) ;
68+
69+ // Step 4: Verify journey completion
70+ await expect ( page . getByText ( 'Complete' ) ) . toBeVisible ( { timeout : 10000 } ) ;
71+
72+ // Verify session token is present
73+ const sessionToken = await page . locator ( '#sessionToken' ) . textContent ( ) ;
74+ expect ( sessionToken ) . toBeTruthy ( ) ;
75+
76+ // Step 5: Perform logout
77+ await clickButton ( 'Logout' , '/authenticate' ) ;
78+
79+ // Verify we're back at the beginning
80+ await expect ( page . getByText ( 'Initializing PingOne Protect...' ) ) . toBeVisible ( { timeout : 10000 } ) ;
81+
82+ // Test console log assertions
83+ expect ( messageArray . some ( ( msg ) => msg . includes ( 'Protect initialized successfully' ) ) ) . toBe ( true ) ;
84+ expect ( messageArray . some ( ( msg ) => msg . includes ( 'Protect data collected successfully' ) ) ) . toBe ( true ) ;
85+ expect ( messageArray . some ( ( msg ) => msg . includes ( 'Logout successful' ) ) ) . toBe ( true ) ;
86+ } ) ;
4087} ) ;
0 commit comments