How to Use AI Prompts for Test Automation in Cypress
Use Cypress cy.prompt() to turn clear natural-language steps into inspectable test commands. Learn setup, prompt patterns, placeholders, review workflows and fixes.
cy.prompt() lets you describe a Cypress test as an ordered array of natural-language steps. Cypress uses the application’s DOM to generate Cypress commands and execute them; you can inspect those commands in the Command Log. For dependable tests, make each step specific, review the generated behavior, and verify that assertions check the application behavior you actually care about. See the official cy.prompt() API and Cypress guide.
1. Set up Cypress Cloud access
cy.prompt() relies on a secure Cypress Cloud connection to interpret prompts. Cypress documents using it after logging in to Cloud or running a recorded execution with a valid key. The guide says the free Starter plan supports cy.prompt(); paid plans increase usage allowances and hourly limits. Check Cypress’s current plan and setup documentation before relying on a particular limit.
- Install and configure Cypress for your project using the official installation guide.
- Sign in to Cypress Cloud or configure a project record key for recorded runs, following Cypress’s current Cloud setup instructions.
- Run the test in an environment that can reach Cypress Cloud.
- Inspect the commands generated by the prompt in the Cypress Command Log.
The example below is an illustrative spec pattern, not a claim that the example selectors or application behavior have been tested. Replace the URL, test account values, and expected dashboard text with values that match your application.
2. Write a prompt as clear, ordered steps
Use one observable action or check per step. Start with an imperative verb, name the target control, and include context if multiple elements could match. Use an absolute URL when telling Cypress to visit a page. Cypress says English is the optimized prompt language and does not guarantee accuracy or support for prompts in other languages.
describe('sign-in flow', () => {
it('signs in and shows the account dashboard', () => {
const testEmail = Cypress.env('TEST_EMAIL')
const testPassword = Cypress.env('TEST_PASSWORD')
cy.prompt([
'visit https://example.test/login',
'type {{email}} in the email field',
'type {{password}} in the password field',
'click the Sign in button',
'verify the account dashboard is visible',
], {
placeholders: {
email: testEmail,
password: testPassword,
},
})
})
})
Set TEST_EMAIL and TEST_PASSWORD using your project’s normal secret handling, such as environment variables in CI. Do not commit real credentials into the spec. Placeholder values let the prompt refer to changing or sensitive data without putting the values in the natural-language steps.
Cypress documents placeholders and says those values are not sent to the AI and are ignored for cache identity. This means changing a placeholder value does not invalidate the cached generated code. These properties do not replace your broader secret-management practices.
3. Choose whether to commit generated code or retain the prompt
| Workflow | How it works | Trade-off |
|---|---|---|
| Generate once, inspect, export and commit | Use the prompt to produce ordinary Cypress commands, review them, then export and commit the resulting test code. | Execution is easier to review and version control without an AI request on each run. Your team maintains selectors as the interface changes. |
Keep cy.prompt() in the test |
Leave the natural-language steps in the spec so Cypress can regenerate commands when a cached selector fails after UI changes. | This keeps a Cloud-backed AI feature in the test workflow. Inspect regenerated commands and confirm the test still checks the intended behavior. |
Generated commands are inspectable in the Command Log, and Cypress supports exporting them. AI-generated steps are code to review, not proof that the test is correct. In particular, check that the final assertion is meaningful and that the test would fail if the behavior under test were broken.
4. Make prompts easier to interpret
- Name the action and target. “Click the Edit Profile button in the profile section” gives more context than “click button.”
- Use one action per step. Separate navigation, typing, clicking and checking into distinct instructions.
- Disambiguate repeated controls. Identify a section, label, row, or position when several elements have similar names.
- Describe observable outcomes. Ask to verify a specific message or visible dashboard state rather than a vague “check success.”
- Use full URLs for visits. Include the scheme and host in the visit step.
- Put variable data in placeholders. Keep passwords, one-time values and other changing input out of prompt text.
- Keep the prompt in English for the documented optimized path. Cypress does not guarantee accuracy or support for non-English prompts.
Cypress’s guidance summarizes the principle: “Prompt clarity determines reliability.” Treat clarity as a way to reduce ambiguity, not as a guarantee that generated commands preserve test intent after every UI change.
5. Know the options and boundaries
The documented command takes an array of natural-language steps and an options object. The documented placeholders option supplies values referenced with double curly braces, as in {{email}}. Cypress currently documents only force and timeout as supported command options that can be expressed through natural-language prompts. Check the API reference before relying on additional options or phrasing behavior; do not assume every Cypress command option can be set through a prompt.
Use cy.prompt() for natural-language generation and adaptation of test commands. Cypress Studio and Studio AI, AI Skills, cypress tap, Cloud MCP, and Cloud CLI are related tools for recording interactions, agent-assisted authoring, debugging, or Cloud run analysis. They are adjacent workflows rather than alternate names for cy.prompt(). Cypress’s AI overview describes the broader set of options.
6. Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| The prompt cannot be interpreted or the command fails before actions run. | The run lacks the required secure Cypress Cloud connection, login, or valid record key. | Confirm Cloud authentication and the recorded-run configuration. Check the current Cypress setup guide and ensure the run can connect to Cloud. |
| The wrong button or field is selected. | The step is vague or several controls match. | Name the control by its visible label and add its containing section or other distinguishing context. Break compound directions into individual steps. |
| The test visits the wrong page. | The prompt uses an ambiguous or relative destination. | Give the full absolute URL, including scheme and host, and confirm the test environment expects that host. |
| A placeholder is unresolved or the test enters an empty value. | The placeholder name in the step and the placeholders object do not match, or the supplied value is missing. |
Use the same key spelling in both places, confirm the environment variable is available, and fail the test setup clearly if a required value is absent. |
| A generated assertion passes but does not protect the intended behavior. | The outcome was underspecified or the generated check is too weak. | Inspect the Command Log and exported code. State the exact expected message or UI condition and confirm that a broken behavior would fail the check. |
| A UI change causes a prompt-backed test to behave differently. | Regenerated commands may adapt selectors while interpreting the same natural-language steps. | Review the regenerated commands and validate their meaning. If predictable, committed code is preferable, export and maintain the test directly. |
| A non-English prompt is inconsistent. | Cypress optimizes prompts for English and does not guarantee support or accuracy for other languages. | Express the steps in clear English, then inspect and validate the resulting commands. |
| An option described in a prompt is ignored or behaves unexpectedly. | The option may not be supported in natural-language command options. | Limit prompt options to documented support, currently force and timeout, and consult the API reference for updates. |
7. Performance, reliability, privacy and cost
No verified benchmark in the cited Cypress material quantifies time saved, flakiness reduced, or maintenance avoided by cy.prompt(). The practical trade-off is between the Cloud-backed prompt workflow and ordinary committed Cypress commands: generating or adapting steps requires the documented Cloud connection, while exporting reviewed commands makes the resulting test code part of the project’s normal source-controlled workflow. Do not assume a prompt makes a test faster or more reliable without measuring it in your own suite.
For reliability, keep each step narrow, make assertions specific, inspect generated commands, and rerun tests against the application states that matter. A self-healing selector can help after a markup change, but a regenerated command can still target the wrong control or weaken the assertion. Review it like any other code change.
Cypress states in its guide that prompts are not used to train AI models and that AI features can be turned off. These are Cypress’s statements; consult its current data terms and settings for details before using sensitive application context. Use placeholders for sensitive values as documented, and keep secrets in project-managed secret storage.
The guide says the free Starter plan includes cy.prompt() and paid plans increase execution allowance and hourly limits. Exact limits and plan terms may change; confirm them in Cypress Cloud before planning usage.
8. Or skip the browser setup
If your goal is to capture a page for a test fixture, visual review, or an agent workflow, ScreenshotNeo provides a website screenshot API and MCP server. It does not replace Cypress interaction tests; it can return a screenshot or PDF from a single GET request. The API supports PNG, JPEG, WebP, PDF, full-page capture, element capture, device presets, waits, and other capture options. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
- Cookie and consent banners, newsletter popups, and chat widgets are handled before the shot; each cleanup step can be turned off.
- Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Response headers identify the page verdict and billing status.
- An MCP server gives AI agents tools for screenshots, page information, and PDF capture.
- The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is on every plan.
Sign up for 1,000 free screenshots a month, with no card required.
9. FAQ
Can Cypress prompts replace assertions written by the test author?
They can generate an assertion step, but you remain responsible for confirming it checks the intended behavior. Inspect the generated command and validate the test’s failure condition.
Do placeholder values change which generated code is cached?
Cypress says placeholder values are ignored for cache identity, so changing a value does not invalidate cached code.
Does Cypress guarantee prompt accuracy in other languages?
No. Cypress identifies English as the optimized language and does not guarantee accuracy or support for non-English prompts.
Can I use ScreenshotNeo to test a login flow?
ScreenshotNeo captures pages; the provided product facts do not describe interactive login automation. Use Cypress for browser interactions and assertions, and use a screenshot API when you need a rendered image or PDF.


