|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +test('Verify Calendar Functionality', async ({ page }) => { |
| 4 | + // Test Data |
| 5 | + const targeturl = 'https://qa-practice.netlify.app/calendar'; |
| 6 | + const rangeStartDate = '1'; |
| 7 | + const rangeEndDate = '10'; |
| 8 | + const expectedRangeValue = '01/01/2018 - 01/10/2018'; |
| 9 | + |
| 10 | + // Get today's date |
| 11 | + const today = new Date(); |
| 12 | + const todayDate = today.getDate().toString(); |
| 13 | + const todayMonthYear = today.toLocaleString('default', { month: 'long', year: 'numeric' }); // Month and year (e.g., "January 2025") |
| 14 | + |
| 15 | + // Format today's date to MM/DD/YYYY |
| 16 | + const formattedTodayDate = `${String(today.getMonth() + 1).padStart(2, '0')}/${String(today.getDate()).padStart(2, '0')}/${today.getFullYear()}`; |
| 17 | + |
| 18 | + // Navigate to the calendar page |
| 19 | + await page.goto(targeturl); |
| 20 | + |
| 21 | + // Range Date Picker Example |
| 22 | + await page.locator('#range-date-calendar').click(); |
| 23 | + await page.getByRole('cell', { name: rangeStartDate, exact: true }).first().click(); |
| 24 | + await page.getByRole('cell', { name: rangeEndDate }).first().click(); |
| 25 | + await page.getByRole('button', { name: 'Apply' }).click(); |
| 26 | + |
| 27 | + // Basic Date Picker Example |
| 28 | + await page.getByPlaceholder('Pick a date').click(); |
| 29 | + await page.locator('div').filter({ hasText: todayMonthYear }).first().click(); |
| 30 | + await page.getByRole('cell', { name: todayDate }).click(); |
| 31 | + |
| 32 | + // Validate date picker interactions |
| 33 | + await expect(page.getByPlaceholder('Pick a date')).toHaveValue(formattedTodayDate); |
| 34 | + |
| 35 | + // Assert the selected range date values |
| 36 | + await expect(page.locator('#range-date-calendar')).toHaveValue(expectedRangeValue); |
| 37 | +}); |
0 commit comments