Upload sample_test.spec.js with huggingface_hub
Browse files- sample_test.spec.js +91 -0
sample_test.spec.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// The The-internet E2E Test
|
| 2 |
+
// Automated test for The-internet
|
| 3 |
+
// Auto-generated from crawl data on 2025-04-10 21:25:36
|
| 4 |
+
|
| 5 |
+
import { test, expect } from '@playwright/test';
|
| 6 |
+
|
| 7 |
+
test('The The-internet E2E Test', async ({ page }) => {
|
| 8 |
+
// Configure viewport for better element visibility
|
| 9 |
+
await page.setViewportSize({ width: 1280, height: 800 });
|
| 10 |
+
|
| 11 |
+
// Helper function for safer element interactions
|
| 12 |
+
async function safeClick(selector, description) {
|
| 13 |
+
console.log(`Attempting to click ${description}...`);
|
| 14 |
+
try {
|
| 15 |
+
// First check if element exists and is visible
|
| 16 |
+
const element = page.locator(selector);
|
| 17 |
+
const isVisible = await element.isVisible().catch(() => false);
|
| 18 |
+
|
| 19 |
+
if (!isVisible) {
|
| 20 |
+
console.log(`Element ${description} is not visible, skipping`);
|
| 21 |
+
return false;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
// Always scroll before clicking - critical for elements outside viewport
|
| 25 |
+
await element.scrollIntoViewIfNeeded();
|
| 26 |
+
await page.waitForTimeout(500); // Small wait after scrolling
|
| 27 |
+
|
| 28 |
+
// Now click the element
|
| 29 |
+
await element.click();
|
| 30 |
+
console.log(`Successfully clicked ${description}`);
|
| 31 |
+
await page.waitForTimeout(1000); // Wait after click
|
| 32 |
+
return true;
|
| 33 |
+
} catch (e) {
|
| 34 |
+
console.log(`Could not click ${description}: ${e.message}`);
|
| 35 |
+
return false;
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// Navigate to the application
|
| 40 |
+
console.log('Navigating to application...');
|
| 41 |
+
await page.goto('https://the-internet.herokuapp.com/login');
|
| 42 |
+
|
| 43 |
+
// Verify the page loaded correctly
|
| 44 |
+
await expect(page).toHaveTitle(/^The.*$/);
|
| 45 |
+
|
| 46 |
+
// Login process
|
| 47 |
+
console.log('Performing login...');
|
| 48 |
+
await page.fill("input[type='text'][name*='user']", "tomsmith");
|
| 49 |
+
await page.fill("input[type='password']", "SuperSecretPassword!");
|
| 50 |
+
// Click the submit button with safety checks
|
| 51 |
+
await safeClick("button[type='submit']", "login button");
|
| 52 |
+
|
| 53 |
+
// Verify successful login
|
| 54 |
+
await page.waitForTimeout(2000); // Wait for navigation
|
| 55 |
+
try {
|
| 56 |
+
// Look for common login success indicators
|
| 57 |
+
// 1. URL changes to include secure, account, dashboard, profile, etc.
|
| 58 |
+
const currentUrl = page.url();
|
| 59 |
+
console.log('Post-login URL: ' + currentUrl);
|
| 60 |
+
// 2. Text indicating successful login (welcome, logged in, etc.)
|
| 61 |
+
const pageContent = await page.content();
|
| 62 |
+
const loggedInIndicators = ['welcome', 'logged in', 'sign out', 'logout', 'account'];
|
| 63 |
+
let foundIndicator = false;
|
| 64 |
+
for (const indicator of loggedInIndicators) {
|
| 65 |
+
if (pageContent.toLowerCase().includes(indicator)) {
|
| 66 |
+
foundIndicator = true;
|
| 67 |
+
console.log('Found login success indicator: ' + indicator);
|
| 68 |
+
break;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
// If found indicators, assert successful login
|
| 72 |
+
if (foundIndicator) {
|
| 73 |
+
expect(true).toBeTruthy(); // Successfully found login indicators
|
| 74 |
+
} else {
|
| 75 |
+
console.log('Warning: Could not find clear login success indicators');
|
| 76 |
+
}
|
| 77 |
+
} catch (e) {
|
| 78 |
+
console.log('Error checking login status: ' + e);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// Explore the application - click on main menu items
|
| 82 |
+
console.log('Exploring application navigation...');
|
| 83 |
+
// Interact with Login
|
| 84 |
+
await safeClick("form#login > button", "Login");
|
| 85 |
+
|
| 86 |
+
// Interact with Elemental Selenium
|
| 87 |
+
await safeClick("div#page-footer > div > div > a", "Elemental Selenium");
|
| 88 |
+
|
| 89 |
+
// Take a screenshot for verification
|
| 90 |
+
await page.screenshot({ path: 'test-result-screenshot.png' });
|
| 91 |
+
});
|