UI and end-to-end testing with OpenAI Codex OpenAI Codex can draft Playwright end-to-end tests from a user story, but a passing test the agent writes for its own change does not independently verify the intended UI behavior, according to a Momentic guide on wiring Codex into UI testing. The guide recommends placing test conventions in a repository-root AGENTS.md file, connecting Codex to a test runner over MCP, and committing the resulting test to CI so the PR check re-runs it against proposed changes. It warns that Codex can produce a test that passes while missing the requested behavior, citing a saved-address story where the agent asserted only a success message and never checked persistence after a page reload. TL;DR - Codex can turn a user story into Playwright test scaffolding with selectors and assertions. - Codex can run tests when its environment permits, but a passing test it wrote does not independently verify the UI behavior you intended. - Put test conventions in AGENTS.md , then connect Codex to a runner over MCP. Momentic’s setup guide https://momentic.ai/blog/how-to-set-up-momentic-mcp-server covers its MCP server and skills. - Commit the resulting test and run it in CI. The PR check then reports whether that same test passes against the proposed change. What Codex writes well for UI and end-to-end tests Codex can draft useful Playwright tests when you give it the user story and the relevant code. In the CLI, you can point it at a component and its existing tests. In Codex cloud, you can give it the same task against a repository. Codex can use those files and the PR description to choose a route, locate controls, and write assertions for the behavior you described. Suppose the story says that submitting an invalid email on /signup must show “Enter a valid email address.” With the app running and Playwright’s baseURL configured, Codex could draft a test like this. js import { test, expect } from '@playwright/test'; test 'signup shows an error for an invalid email', async { page } = { await page.goto '/signup' ; await page.getByLabel 'Email' .fill 'not-an-email' ; await page.getByRole 'button', { name: 'Sign up' } .click ; await expect page.getByText 'Enter a valid email address' .toBeVisible ; } ; The test expresses the story in browser actions and an observable assertion. Codex still needs to check the rendered form before trusting the label, button name, or error text. Writing a plausible test file does not establish that the test runs or catches a regression. Where Codex stalls on UI testing A coding agent can write a Playwright test that passes while missing the behavior the user requested. Suppose a user story says a saved address must survive a page reload. The agent implements the form, then writes a test that clicks Save and checks for a success message. Both the code and the test pass, but neither checks whether the address persists. The problem is what closes the verification loop https://momentic.ai/blog/verification-belongs-inside-the-agent-loop . When an agent chooses the assertions for its own change, a green result confirms those assertions, not the full user story. An independent check of the saved address after reload would catch the omission. Execution creates a separate failure mode. Codex can run Playwright through a shell, but a test file alone shows no evidence of a browser run. A selector that matches the wrong Save button may also pass locally and fail against another page state. If the test never enters the repository’s CI suite, later PRs cannot use it to catch the same regression. For a useful PR check, the test must exercise the intended behavior in a real browser and run again on subsequent changes. Giving Codex test-writing instructions with AGENTS.md Put test conventions in a repository-root AGENTS.md before asking Codex to implement a UI change. Codex uses the file as project instructions, so you can specify where tests belong and what a test must assert. UI test instructions - Write end-to-end UI tests with @playwright/test in tests/e2e/. - Name test files