To validate a URL using @playwright/test, you can create a test that navigates to the desired URL and then checks if the current URL matches the expected one. Here's a step-by-step guide:
First, install the necessary dependencies:
npm install -D @playwright/test
Create a test file, e.g., url-validation.spec.ts
.
Write a test that navigates to the target URL and compares the current URL with the expected one:
import { test, expect } from '@playwright/test';
test('Validate URL', async ({ page }) => {
// Navigate to the target URL
await page.goto('https://ray.run/');
// Get the current URL
const currentUrl = page.url();
// Check if the current URL matches the expected one
expect(currentUrl).toBe('https://ray.run/');
});
Run the test using the playwright test
command:
npx playwright test
This test will navigate to the https://ray.run/
website and verify if the current URL matches the expected one. If the URLs match, the test will pass; otherwise, it will fail.
For more tips and best practices on writing efficient @playwright/test scripts, check out Tips for Writing Efficient Playwright Test Scripts.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].