/**
* Example Tests for CAPTCHA and Complex Website URLs
*
* This file demonstrates how to use the new test URLs for CAPTCHA testing
* and complex government websites.
*
* NOTE: These are example tests that demonstrate URL usage.
* Real CAPTCHA solving would require additional logic and services.
*/
import { describe, test, expect } from 'vitest';
import { TEST_URLS, TEST_TIMEOUTS } from '../helpers/test-constants.js';
describe('CAPTCHA URL Examples', () => {
describe('NopeCHA Demo Page', () => {
test('should have NopeCHA demo URL available', () => {
// Verify URL is properly defined
expect(TEST_URLS.NOPECHA_DEMO).toBe('https://nopecha.com/demo');
expect(TEST_URLS.NOPECHA_DEMO).toContain('nopecha.com');
});
test('URL should be usable for navigation tests', () => {
// This demonstrates how the URL would be used in actual tests
const navigationUrl = TEST_URLS.NOPECHA_DEMO;
expect(navigationUrl).toBeDefined();
expect(typeof navigationUrl).toBe('string');
expect(navigationUrl.startsWith('https://')).toBe(true);
});
});
describe('eCourts India Case Status', () => {
test('should have eCourts URL with app token', () => {
// Verify URL is properly defined with app_token parameter
expect(TEST_URLS.ECOURTS_CASE_STATUS).toContain('services.ecourts.gov.in');
expect(TEST_URLS.ECOURTS_CASE_STATUS).toContain('app_token=');
expect(TEST_URLS.ECOURTS_CASE_STATUS).toContain('casestatus/index');
});
test('URL should include required parameters', () => {
const url = new URL(TEST_URLS.ECOURTS_CASE_STATUS);
// Check base URL
expect(url.hostname).toBe('services.ecourts.gov.in');
// Check query parameters
const params = new URLSearchParams(url.search);
expect(params.has('p')).toBe(true);
expect(params.get('p')).toBe('casestatus/index');
expect(params.has('app_token')).toBe(true);
expect(params.get('app_token')).toBeTruthy();
});
});
describe('URL Timeout Recommendations', () => {
test('should use appropriate timeouts for CAPTCHA pages', () => {
// CAPTCHA pages typically need longer timeouts
const captchaTimeout = TEST_TIMEOUTS.LONG; // 30 seconds
expect(captchaTimeout).toBeGreaterThanOrEqual(30000);
expect(captchaTimeout).toBe(30000);
});
test('should have different timeout levels available', () => {
expect(TEST_TIMEOUTS.SHORT).toBe(1000);
expect(TEST_TIMEOUTS.MEDIUM).toBe(5000);
expect(TEST_TIMEOUTS.LONG).toBe(30000);
// Verify progression
expect(TEST_TIMEOUTS.MEDIUM).toBeGreaterThan(TEST_TIMEOUTS.SHORT);
expect(TEST_TIMEOUTS.LONG).toBeGreaterThan(TEST_TIMEOUTS.MEDIUM);
});
});
describe('Usage Examples in Comments', () => {
test('demonstrates how to use URLs in real tests', () => {
// Example 1: Navigation to NopeCHA demo
const nopechaExample = `
// await page.goto(TEST_URLS.NOPECHA_DEMO, {
// waitUntil: 'domcontentloaded',
// timeout: TEST_TIMEOUTS.LONG
// });
`;
expect(nopechaExample).toContain('TEST_URLS.NOPECHA_DEMO');
expect(nopechaExample).toContain('TEST_TIMEOUTS.LONG');
});
test('demonstrates eCourts usage pattern', () => {
// Example 2: Navigate to eCourts with proper timeout
const ecourtsExample = `
// await handleNavigate({
// url: TEST_URLS.ECOURTS_CASE_STATUS,
// waitUntil: 'networkidle2'
// });
//
// // Wait for CAPTCHA image to load
// await handleWait({
// type: 'selector',
// value: 'img[alt*="captcha"]',
// timeout: TEST_TIMEOUTS.LONG
// });
`;
expect(ecourtsExample).toContain('TEST_URLS.ECOURTS_CASE_STATUS');
expect(ecourtsExample).toContain('captcha');
});
});
describe('URL Availability Check', () => {
test('all CAPTCHA-related URLs should be accessible', () => {
const captchaUrls = {
cloudflare: TEST_URLS.CLOUDFLARE_DEMO,
nopecha: TEST_URLS.NOPECHA_DEMO,
ecourts: TEST_URLS.ECOURTS_CASE_STATUS,
};
// Verify all URLs are defined
Object.entries(captchaUrls).forEach(([name, url]) => {
expect(url, `${name} URL should be defined`).toBeDefined();
expect(url, `${name} URL should be a string`).toBeTypeOf('string');
expect(url, `${name} URL should start with https://`).toMatch(/^https:\/\//);
});
});
test('should have comprehensive URL catalog', () => {
// Count available test URLs
const urlKeys = Object.keys(TEST_URLS);
expect(urlKeys.length).toBeGreaterThanOrEqual(7); // At least 7 URLs
expect(urlKeys).toContain('NOPECHA_DEMO');
expect(urlKeys).toContain('ECOURTS_CASE_STATUS');
expect(urlKeys).toContain('CLOUDFLARE_DEMO');
expect(urlKeys).toContain('BASIC');
expect(urlKeys).toContain('HTTPBIN_HTML');
expect(urlKeys).toContain('HTTPBIN_FORM');
});
});
});
/**
* INTEGRATION EXAMPLE (commented out - for reference only)
*
* Below is an example of how you might use these URLs in actual integration tests:
*
* describe('Real CAPTCHA Integration Test', () => {
* test.skip('should handle NopeCHA demo page', async () => {
* // 1. Initialize browser
* await handleBrowserInit({ headless: false });
*
* // 2. Navigate to NopeCHA demo
* await handleNavigate({
* url: TEST_URLS.NOPECHA_DEMO,
* waitUntil: 'networkidle2'
* });
*
* // 3. Get page content to analyze available CAPTCHA types
* const content = await handleGetContent({ type: 'html' });
* expect(content).toContain('Arkose');
* expect(content).toContain('hCaptcha');
* expect(content).toContain('reCAPTCHA');
*
* // 4. Try to solve CAPTCHA (requires additional service)
* // await handleSolveCaptcha({ type: 'recaptcha' });
*
* // 5. Close browser
* await handleBrowserClose();
* }, TEST_TIMEOUTS.LONG * 2);
*
* test.skip('should handle eCourts case status page', async () => {
* // 1. Initialize browser
* await handleBrowserInit({ headless: false });
*
* // 2. Navigate to eCourts
* await handleNavigate({
* url: TEST_URLS.ECOURTS_CASE_STATUS,
* waitUntil: 'domcontentloaded'
* });
*
* // 3. Wait for page to load completely
* await handleWait({
* type: 'timeout',
* value: '3000'
* });
*
* // 4. Get page content
* const content = await handleGetContent({ type: 'text' });
*
* // 5. Verify page elements
* expect(content).toContain('Case Status');
* expect(content).toContain('Captcha');
* expect(content).toContain('FIR Number');
*
* // 6. Find form elements
* const selector = await handleFindSelector({
* text: 'Go',
* elementType: 'button'
* });
*
* // 7. Close browser
* await handleBrowserClose();
* }, TEST_TIMEOUTS.LONG * 2);
* });
*/