Files
CompanySite/tests/contact-form.spec.ts
T
Clintchiz d402256547
Deploy to Production / Build & Verify (push) Failing after 5m56s
Ping Search Engines / Notify Search Engines (push) Successful in 2s
Deploy to Production / Pre-Deploy Tests (push) Has been skipped
Deploy to Production / Deploy to Railway (push) Has been skipped
Deploy to Production / Deploy to Render (push) Has been skipped
Deploy to Production / Deploy to VPS (PM2) (push) Has been skipped
Deploy to Production / Deploy to Fly.io (push) Has been skipped
Deploy to Production / Post-Deploy Verification (push) Has been skipped
Deploy to Production / Notify on Failure (push) Successful in 2s
E2E Test Suite / Critical User Journeys (push) Has been skipped
E2E Test Suite / API Integration Tests (push) Has been skipped
E2E Test Suite / Smoke Tests (P0) (push) Failing after 11m26s
E2E Test Suite / Form Interaction Tests (push) Failing after 11m42s
E2E Test Suite / Destructive & Chaos Tests (push) Failing after 12m2s
E2E Test Suite / Cross-Browser Regression (chromium) (push) Failing after 16m14s
E2E Test Suite / Cross-Browser Regression (webkit) (push) Failing after 17m45s
E2E Test Suite / Cross-Browser Regression (firefox) (push) Failing after 25m23s
E2E Test Suite / Security Header Tests (push) Failing after 7m55s
E2E Test Suite / Test Report Summary (push) Failing after 20s
E2E Test Suite / Mobile Device Tests (push) Failing after 2h49m9s
Uptime Monitor / Health & Response Time (push) Failing after 2s
Uptime Monitor / SSL Certificate (push) Successful in 2s
Uptime Monitor / Send Alerts (push) Failing after 3s
Uptime Monitor / Record Uptime Success (push) Has been skipped
First Init
2026-03-21 16:46:46 +05:30

158 lines
6.3 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.describe('Contact Form Tests', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/contact');
});
test('contact form is visible', async ({ page }) => {
// The form might be within the page content
const form = page.locator('form').first();
await expect(form).toBeVisible();
});
test('all form fields are present', async ({ page }) => {
// Check required fields exist
await expect(page.locator('input[name="name"], input[id="name"], input[placeholder*="name" i]').first()).toBeVisible();
await expect(page.locator('input[name="email"], input[id="email"], input[type="email"]').first()).toBeVisible();
await expect(page.locator('textarea[name="message"], textarea[id="message"], textarea').first()).toBeVisible();
});
test('form validates required fields', async ({ page }) => {
// Try to submit empty form
const submitButton = page.locator('button[type="submit"], input[type="submit"]').first();
await submitButton.click();
// Check for validation - either HTML5 validation or custom error messages
const nameInput = page.locator('input[name="name"], input[id="name"], input[placeholder*="name" i]').first();
const isInvalid = await nameInput.evaluate((el: HTMLInputElement) => !el.checkValidity());
// Form should show some validation indicator
expect(isInvalid || await page.locator('[class*="error"], [class*="invalid"], .text-red').count() > 0).toBeTruthy();
});
test('email validation works', async ({ page }) => {
const emailInput = page.locator('input[name="email"], input[id="email"], input[type="email"]').first();
// Enter invalid email
await emailInput.fill('invalid-email');
await emailInput.blur();
// Check for error indication
const hasError = await emailInput.evaluate((el: HTMLInputElement) => !el.checkValidity()) ||
await page.locator('[class*="error"], [class*="invalid"]').count() > 0;
expect(hasError).toBeTruthy();
// Clear and enter valid email
await emailInput.fill('valid@email.com');
const isValid = await emailInput.evaluate((el: HTMLInputElement) => el.checkValidity());
expect(isValid).toBeTruthy();
});
test('form fields accept input', async ({ page }) => {
const nameInput = page.locator('input[name="name"], input[id="name"], input[placeholder*="name" i]').first();
const emailInput = page.locator('input[name="email"], input[id="email"], input[type="email"]').first();
const messageInput = page.locator('textarea[name="message"], textarea[id="message"], textarea').first();
await nameInput.fill('John Doe');
await emailInput.fill('john@example.com');
await messageInput.fill('This is a test message for the contact form.');
await expect(nameInput).toHaveValue('John Doe');
await expect(emailInput).toHaveValue('john@example.com');
await expect(messageInput).toHaveValue('This is a test message for the contact form.');
});
test('phone field accepts valid formats', async ({ page }) => {
const phoneInput = page.locator('input[name="phone"], input[id="phone"], input[type="tel"]').first();
if (await phoneInput.isVisible()) {
// Test different phone formats
const validPhones = ['(555) 123-4567', '555-123-4567', '+1 555 123 4567'];
for (const phone of validPhones) {
await phoneInput.fill(phone);
await expect(phoneInput).toHaveValue(phone);
await phoneInput.clear();
}
}
});
test('subject dropdown works', async ({ page }) => {
const subjectSelect = page.locator('select[name="subject"], select[id="subject"]').first();
if (await subjectSelect.isVisible()) {
// Get all options
const options = await subjectSelect.locator('option').all();
expect(options.length).toBeGreaterThan(1);
// Select an option
await subjectSelect.selectOption({ index: 1 });
const selectedValue = await subjectSelect.inputValue();
expect(selectedValue).not.toBe('');
}
});
test('honeypot field is hidden', async ({ page }) => {
// Look for common honeypot field names
const honeypotLocator = page.locator('input[name="website"], input[name="url"], input[name="honeypot"], input[name="bot"]');
const count = await honeypotLocator.count();
if (count > 0) {
const honeypot = honeypotLocator.first();
// Honeypot should be hidden from users (various techniques)
const isHidden = await honeypot.evaluate((el) => {
const style = window.getComputedStyle(el);
const parentStyle = el.parentElement ? window.getComputedStyle(el.parentElement) : null;
const rect = el.getBoundingClientRect();
// Check various hiding techniques
return style.display === 'none' ||
style.visibility === 'hidden' ||
style.opacity === '0' ||
el.offsetParent === null ||
rect.left < -1000 || // Off-screen positioning (like -left-[9999px])
rect.top < -1000 ||
(parentStyle && (parentStyle.display === 'none' || parentStyle.visibility === 'hidden' || parseFloat(parentStyle.left) < -1000));
});
expect(isHidden).toBeTruthy();
} else {
// No honeypot field found - that's fine, test passes
expect(true).toBeTruthy();
}
});
});
test.describe('Contact Form Accessibility', () => {
test('form fields have labels', async ({ page }) => {
await page.goto('/contact');
const inputs = await page.locator('input:not([type="hidden"]):not([type="submit"]), textarea, select').all();
for (const input of inputs) {
const id = await input.getAttribute('id');
const ariaLabel = await input.getAttribute('aria-label');
const placeholder = await input.getAttribute('placeholder');
// Check if input has associated label
if (id) {
const label = page.locator(`label[for="${id}"]`);
const hasLabel = await label.count() > 0 || ariaLabel || placeholder;
expect(hasLabel).toBeTruthy();
}
}
});
test('submit button is accessible', async ({ page }) => {
await page.goto('/contact');
const submitButton = page.locator('button[type="submit"], input[type="submit"]').first();
await expect(submitButton).toBeVisible();
// Button should be focusable
await submitButton.focus();
await expect(submitButton).toBeFocused();
});
});