|
1 |
| -import { test, expect } from '@playwright/test'; |
| 1 | +import { test, expect, BrowserContext, Page } from '@playwright/test'; |
2 | 2 |
|
3 |
| -test('has title', async ({ page }) => { |
4 |
| - await page.goto('http://localhost:3001'); |
| 3 | +const TEST_URL = 'http://localhost:3001'; |
5 | 4 |
|
6 |
| - await expect(page).toHaveTitle(/Parseable | Login/); |
| 5 | +test.describe('Login Page', () => { |
| 6 | + let context: BrowserContext; |
| 7 | + let page: Page; |
| 8 | + |
| 9 | + test.beforeEach(async ({ browser }) => { |
| 10 | + context = await browser.newContext(); |
| 11 | + page = await context.newPage(); |
| 12 | + }); |
| 13 | + |
| 14 | + test.afterEach(async () => { |
| 15 | + await context.close(); |
| 16 | + }); |
| 17 | + // Test for title of the page |
| 18 | + test('has title', async ({ page }) => { |
| 19 | + await page.goto(TEST_URL); |
| 20 | + await expect(page).toHaveTitle(/Parseable | Login/); |
| 21 | + }); |
| 22 | + |
| 23 | + // Test to ensure login form works with valid credentials |
| 24 | + test('login with valid credentials', async ({ page }) => { |
| 25 | + await page.goto(TEST_URL); |
| 26 | + |
| 27 | + await page.fill('input[placeholder="J.Doe"]', 'admin'); |
| 28 | + await page.fill('input[placeholder="**********"]', 'admin'); |
| 29 | + |
| 30 | + await page.click('button[type="submit"]'); |
| 31 | + |
| 32 | + await expect(page).toHaveTitle(/Parseable | Streams/); |
| 33 | + }); |
| 34 | + |
| 35 | + // Test to ensure login button is disabled when form is invalid |
| 36 | + test('login button is disabled when form is invalid', async ({ page }) => { |
| 37 | + await page.goto(TEST_URL); |
| 38 | + |
| 39 | + const loginButton = page.locator('button[type="submit"]'); |
| 40 | + |
| 41 | + await expect(loginButton).toBeDisabled(); |
| 42 | + |
| 43 | + await page.fill('input[placeholder="J.Doe"]', 'admin'); |
| 44 | + |
| 45 | + await expect(loginButton).toBeDisabled(); |
| 46 | + }); |
| 47 | + |
| 48 | + // Test to check login with invalid credentials |
| 49 | + test('login with invalid credentials', async ({ page }) => { |
| 50 | + await page.goto(TEST_URL); |
| 51 | + |
| 52 | + await page.fill('input[placeholder="J.Doe"]', 'invalidUser'); |
| 53 | + await page.fill('input[placeholder="**********"]', 'invalidPassword'); |
| 54 | + |
| 55 | + await page.click('button[type="submit"]'); |
| 56 | + |
| 57 | + const errorMessage = await page.locator('text=Bad Request, Invalid Redirect URL!').first(); |
| 58 | + await expect(errorMessage).toBeVisible(); |
| 59 | + }); |
| 60 | + |
| 61 | + // Test to check OAuth login button functionality |
| 62 | + // test('OAuth login button works', async ({ page }) => { |
| 63 | + // await page.goto(TEST_URL); |
| 64 | + // await page.getByRole('link', { name: 'Login with OAuth' }).click(); |
| 65 | + |
| 66 | + // const pageOrigin = new URL(page.url()).origin; |
| 67 | + // const expectedOAuthURL = `${pageOrigin}/api/v1/o/login?redirect=${TEST_URL}`; |
| 68 | + |
| 69 | + // await page.waitForURL(expectedOAuthURL); |
| 70 | + |
| 71 | + // await expect(page).toHaveURL(expectedOAuthURL); |
| 72 | + // }); |
7 | 73 | });
|
0 commit comments