|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Ping Identity Corporation. All rights reserved. |
| 3 | + * |
| 4 | + * This software may be modified and distributed under the terms |
| 5 | + * of the MIT license. See the LICENSE file for details. |
| 6 | + */ |
| 7 | +import { expect, test } from '@playwright/test'; |
| 8 | +import { asyncEvents } from './utils/async-events.js'; |
| 9 | +import { password, username } from './utils/demo-user.js'; |
| 10 | + |
| 11 | +test('Test debug log level and custom logger functions', async ({ page }) => { |
| 12 | + const { navigate } = asyncEvents(page); |
| 13 | + const messageArray: string[] = []; |
| 14 | + |
| 15 | + // Listen for events on page |
| 16 | + page.on('console', async (msg) => { |
| 17 | + messageArray.push(msg.text()); |
| 18 | + return Promise.resolve(true); |
| 19 | + }); |
| 20 | + |
| 21 | + await navigate('/?logFn=true'); |
| 22 | + |
| 23 | + expect(page.url()).toBe('http://localhost:5829/?logFn=true'); |
| 24 | + |
| 25 | + await expect(page.getByText('Username/Password Form')).toBeVisible(); |
| 26 | + |
| 27 | + await page.getByLabel('Username').fill(username); |
| 28 | + await page.getByLabel('Password').fill(password); |
| 29 | + |
| 30 | + await page.getByRole('button', { name: 'Sign On' }).click(); |
| 31 | + |
| 32 | + await expect(page.getByText('Complete')).toBeVisible(); |
| 33 | + |
| 34 | + // Just test if the custom debug function is called |
| 35 | + expect( |
| 36 | + messageArray.includes('[DEBUG] This is a custom logger function output.'), |
| 37 | + 'Custom debug function output string should be present', |
| 38 | + ).toBe(true); |
| 39 | +}); |
| 40 | + |
| 41 | +test('Test log level without custom logger', async ({ page }) => { |
| 42 | + const { navigate } = asyncEvents(page); |
| 43 | + const messageArray: string[] = []; |
| 44 | + |
| 45 | + // Listen for events on page |
| 46 | + page.on('console', async (msg) => { |
| 47 | + messageArray.push(msg.text()); |
| 48 | + return Promise.resolve(true); |
| 49 | + }); |
| 50 | + |
| 51 | + await navigate('/'); |
| 52 | + |
| 53 | + expect(page.url()).toBe('http://localhost:5829/'); |
| 54 | + |
| 55 | + await expect(page.getByText('Username/Password Form')).toBeVisible(); |
| 56 | + |
| 57 | + await page.getByLabel('Username').fill(username); |
| 58 | + await page.getByLabel('Password').fill(password); |
| 59 | + |
| 60 | + await page.getByRole('button', { name: 'Sign On' }).click(); |
| 61 | + |
| 62 | + await expect(page.getByText('Complete')).toBeVisible(); |
| 63 | + |
| 64 | + messageArray.forEach((msg) => { |
| 65 | + // Ensure a debug message is present, but don't check the whole contents |
| 66 | + if (msg.includes('DaVinci API Request')) { |
| 67 | + expect(msg).toContain('DaVinci API Response'); |
| 68 | + } |
| 69 | + }); |
| 70 | +}); |
0 commit comments