|
| 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 | +const qrCodeUrl = |
| 12 | + '/?clientId=c12743f9-08e8-4420-a624-71bbb08e9fe1&acr_values=9da1b93991bcd577947da228ad4c741f'; |
| 13 | + |
| 14 | +test('QR code renders after navigating through device registration flow', async ({ page }) => { |
| 15 | + const { navigate } = asyncEvents(page); |
| 16 | + |
| 17 | + await navigate(qrCodeUrl); |
| 18 | + |
| 19 | + // Step 1: Login |
| 20 | + await page.getByRole('button', { name: 'USER_LOGIN' }).click(); |
| 21 | + await page.waitForEvent('requestfinished'); |
| 22 | + |
| 23 | + await page.getByLabel('Username').fill(username); |
| 24 | + await page.getByLabel('Password').fill(password); |
| 25 | + await page.getByRole('button', { name: 'Sign On' }).click(); |
| 26 | + await page.waitForEvent('requestfinished'); |
| 27 | + |
| 28 | + // Step 2: Select device registration |
| 29 | + await page.getByRole('button', { name: 'DEVICE_REGISTRATION' }).click(); |
| 30 | + await page.waitForEvent('requestfinished'); |
| 31 | + |
| 32 | + // Step 3: Choose "Mobile App" from the device selection screen |
| 33 | + await expect(page.getByText('MFA Device Selection - Registration')).toBeVisible(); |
| 34 | + await page.getByRole('button', { name: 'Mobile App' }).click(); |
| 35 | + await page.waitForEvent('requestfinished'); |
| 36 | + |
| 37 | + // Step 4: QR code should now be visible |
| 38 | + const qrImage = page.locator('[data-testid="qr-code-image"]'); |
| 39 | + await expect(qrImage).toBeVisible({ timeout: 10000 }); |
| 40 | + |
| 41 | + // Verify the image has a base64-encoded src |
| 42 | + const src = await qrImage.getAttribute('src'); |
| 43 | + expect(src).toBeTruthy(); |
| 44 | + expect(src).toContain('data:image/png;base64,'); |
| 45 | + |
| 46 | + // Verify fallback text is displayed if present |
| 47 | + const fallback = page.locator('[data-testid="qr-code-fallback"]'); |
| 48 | + const fallbackVisible = await fallback.isVisible(); |
| 49 | + if (fallbackVisible) { |
| 50 | + const fallbackText = await fallback.textContent(); |
| 51 | + expect(fallbackText).toBeTruthy(); |
| 52 | + } |
| 53 | +}); |
0 commit comments