test(e2e): implement login flow tests with valid and invalid credentials

This commit is contained in:
sumit_chaturvedi
2025-06-25 15:24:26 +05:30
parent 498a38634c
commit dc9d5b0bcd
+53
View File
@@ -0,0 +1,53 @@
import { test, expect, request } from '@playwright/test';
// Test credentials
const testEmail = 'test@gmail.com';
const testPassword = 'Testt@123456';
test.beforeAll(async () => {
const apiContext = await request.newContext();
await apiContext.post(`${process.env.API_BASE_URL}users`, {
headers: {
'Content-Type': 'application/vnd.api+json',
'Accept': 'application/vnd.api+json',
},
data: {
data: {
type: 'users',
attributes: {
name: 'testuser',
email: testEmail,
password: testPassword,
company_name: 'test',
},
},
},
});
await apiContext.dispose();
});
test('should show error for invalid credentials', async ({ page }) => {
await page.goto('/sign-in');
await page.fill('input[name="email"]', 'wrong@gmail.com');
await page.fill('input[name="password"]', 'WrongPassword123');
await page.getByRole('button', { name: /log in/i }).click();
await expect(page.getByText(/Invalid email or password/i)).toBeVisible();
});
test('should sign in successfully', async ({ page }) => {
// Go to login page
await page.goto('/sign-in');
// Fill login form
await page.fill('input[name="email"]', testEmail);
await page.fill('input[name="password"]', testPassword);
// Submit the form
await page.getByRole('button', { name: /log in/i }).click();
await page.waitForURL('/', { timeout: 15000 });
await expect(page).toHaveURL('/');
});