Posted in

Writing Playwright Tests Using ChatGPT Agent Mode

Share this:

Playwright is a modern, rapidly evolving end-to-end testing framework developed by Microsoft. It’s becoming increasingly popular among testers and developers for its ability to automate UI interactions across all major browsers.

In this post, I’ll walk you through how I used Agent Mode to create a working Playwright test, without writing a single line of code manually.


What is Agent Mode?

Agent Mode in ChatGPT has recently become available in Poland, and like many curious users, I wanted to see what it’s capable of

Agent Mode lets ChatGPT take control of a virtual browser to interact with websites in real time. Users commonly rely on it to book hotels, order food, or shop online by simply describing what they want to do.

But I wanted to try something different.

Could Agent Mode handle a technical task like building an automated test in Playwright?

Turns out – yes, and impressively well.


Step-by-Step: How I Used Agent Mode

1. Open the Agent

I typed:

Open https://www.automationexercise.com/login create new user and create test in Playwright to login using new created account

I selected Agent Mode from the menu:

Agent Mode launched a browser and navigated to the login page. I watched in real time as it:

  • Entered a new user’s name and email address into the “New User Signup!” section
  • Clicked the “Signup” button and was redirected to the registration form
  • Filled out all required fields on the new page: title, password, date of birth, and address details
  • Submitted the form and successfully created the user account

I could literally see each step being performed in real time inside the Agent’s tool window, along with explanations of what was happening and why. Below some screenshots:


2. Generating Playwright Code

Once the account was created, ChatGPT automatically generated a full Playwright test based on the interaction. Since I hadn’t specified a programming language, it defaulted to Python, but it had no trouble generating the equivalent test in JavaScript or TypeScript when I asked.

The only issue I encountered with the generated test was related to the cookie consent popout. Agent Mode didn’t handle it by default, so the test failed to proceed past the first screen. To make the test work reliably, I needed to add an extra step that clicks the “Accept cookies” button.

Below is an animation where I manually confirm the cookie banner in the browser window to let the test continue:


Below is the Playwright test written in JavaScript, which logs into the Automation Exercise website using the credentials of the newly created user. This script was generated based on the actions taken in Agent Mode:

/**
 * Playwright test script in JavaScript to log into the
 * Automation Exercise website using the account that was just
 * created.  The test navigates to the login page, enters the
 * credentials and verifies that the user is successfully logged
 * in by checking for the "Logged in as" banner.
 *
 * To run this test you need Playwright installed for Node.js
 * along with the browsers.  Install the dependencies and
 * browsers with:
 *
 *   npm install -D @playwright/test
 *   npx playwright install
 *
 * Then execute the test with the Playwright test runner:
 *
 *   npx playwright test login_test.js
 */

const { test, expect } = require('@playwright/test');

// Define the credentials outside of the test for clarity.
const EMAIL = 'testpw20250728@example.com';
const PASSWORD = 'Password123';
const EXPECTED_USERNAME = 'Test Playwright';

test('user can log in with valid credentials', async ({ page }) => {
  // Navigate to the login page directly.  When running in a new
  // browser context the site will present the login form rather
  // than redirecting to the homepage.
  await page.goto('https://www.automationexercise.com/login');

  // Fill in the email and password fields.  The inputs are
  // located using their placeholder attributes which are stable on
  // this practice site.
  await page.fill("input[placeholder='Email Address']", EMAIL);
  await page.fill("input[placeholder='Password']", PASSWORD);

  // Submit the form by clicking the Login button.
  await page.click("button:has-text('Login')");

  // Wait for the logged‑in banner to appear.  Playwright will
  // automatically wait for the selector to match in the DOM.
  await page.waitForSelector('text=Logged in as');

  // Assert that the expected logged‑in username is visible on the page.
  const loggedInSelector = `text=Logged in as ${EXPECTED_USERNAME}`;
  await expect(page.locator(loggedInSelector)).toBeVisible();
});

Agent Mode works also in mobile application. Here’s some examples:

Final Thoughts

Using Agent Mode to create Playwright tests feels like a glimpse into the future of software testing. It acts not just as a chatbot, but as a real assistant capable of interacting with websites and generating working code.

I’m still exploring its capabilities, but I’m genuinely impressed. Watching it fill out forms, submit data, and build a complete test script was fascinating.

Next, I plan to see how Agent Mode can support accessibility testing using my own tool a11y-audit.eu.

At the same time, I’m aware of the challenges this technology brings. As AI tools become more advanced, there is a risk that companies might start relying too much on automation. I hope organizations will continue to value the unique insights, empathy, and responsibility that human testers bring, especially in areas like accessibility and user experience.

AI should enhance our work, not replace it.

I am a Software Tester with over 7 years of experience, specializing in both manual and automated testing, with a strong focus on accessibility. Outside of work, I enjoy low-budget traveling and I’m a proud cat dad to Kimci and Świerzbinka. In my free time, I volunteer by running social media for a group that helps homeless cats find new homes.

Leave a Reply

Your email address will not be published. Required fields are marked *