|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +const email = process.env.EMAIL; |
| 4 | + |
| 5 | +if (!email) { |
| 6 | + throw new Error('EMAIL environment variable must be set.'); |
| 7 | + } |
| 8 | + |
| 9 | +test.describe('Signing In, Sending mail, Replying to a mail', () => { |
| 10 | + test('should send and reply to an email in the same session', async ({ page }) => { |
| 11 | + await page.goto('/mail/inbox'); |
| 12 | + await page.waitForLoadState('domcontentloaded'); |
| 13 | + console.log('Successfully accessed mail inbox'); |
| 14 | + |
| 15 | + await page.waitForTimeout(2000); |
| 16 | + try { |
| 17 | + const welcomeModal = page.getByText('Welcome to Zero Email!'); |
| 18 | + if (await welcomeModal.isVisible({ timeout: 2000 })) { |
| 19 | + console.log('Onboarding modal detected, clicking outside to dismiss...'); |
| 20 | + await page.locator('body').click({ position: { x: 100, y: 100 } }); |
| 21 | + await page.waitForTimeout(1500); |
| 22 | + console.log('Modal successfully dismissed'); |
| 23 | + } |
| 24 | + } catch { |
| 25 | + console.log('No onboarding modal found, proceeding...'); |
| 26 | + } |
| 27 | + |
| 28 | + await expect(page.getByText('Inbox')).toBeVisible(); |
| 29 | + console.log('Mail inbox is now visible'); |
| 30 | + |
| 31 | + console.log('Starting email sending process...'); |
| 32 | + await page.getByText('New email').click(); |
| 33 | + await page.waitForTimeout(2000); |
| 34 | + |
| 35 | + await page.locator('input').first().fill(email); |
| 36 | + console.log('Filled To: field'); |
| 37 | + |
| 38 | + await page.getByRole('button', { name: 'Send' }).click(); |
| 39 | + console.log('Clicked Send button'); |
| 40 | + await page.waitForTimeout(3000); |
| 41 | + console.log('Email sent successfully!'); |
| 42 | + |
| 43 | + console.log('Waiting for email to arrive...'); |
| 44 | + await page.waitForTimeout(10000); |
| 45 | + |
| 46 | + console.log('Looking for the first email in the list...'); |
| 47 | + await page.locator('[data-thread-id]').first().click(); |
| 48 | + console.log('Clicked on email (PM/AM area).'); |
| 49 | + |
| 50 | + console.log('Looking for Reply button to confirm email is open...'); |
| 51 | + await page.waitForTimeout(2000); |
| 52 | + |
| 53 | + const replySelectors = [ |
| 54 | + 'button:has-text("Reply")', |
| 55 | + '[data-testid*="reply"]', |
| 56 | + 'button[title*="Reply"]', |
| 57 | + 'button:text-is("Reply")', |
| 58 | + 'button:text("Reply")' |
| 59 | + ]; |
| 60 | + |
| 61 | + let replyClicked = false; |
| 62 | + for (const selector of replySelectors) { |
| 63 | + try { |
| 64 | + await page.locator(selector).first().click({ force: true }); |
| 65 | + console.log(`Clicked Reply button using: ${selector}`); |
| 66 | + replyClicked = true; |
| 67 | + break; |
| 68 | + } catch { |
| 69 | + console.log(`Failed to click with ${selector}`); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + if (!replyClicked) { |
| 74 | + console.log('Could not find Reply button'); |
| 75 | + } |
| 76 | + |
| 77 | + await page.waitForTimeout(2000); |
| 78 | + |
| 79 | + console.log('Sending reply...'); |
| 80 | + await page.getByRole('button', { name: 'Send' }).click(); |
| 81 | + await page.waitForTimeout(3000); |
| 82 | + console.log('Reply sent successfully!'); |
| 83 | + |
| 84 | + console.log('Entire email flow completed successfully!'); |
| 85 | + }); |
| 86 | +}); |
0 commit comments