How to use cy.prompt in Cypress; this blog introduces cy.prompt, an experimental tool from Cypress designed to simplify web automation by allowing users to write tests using natural language descriptions rather than complex CSS selectors. By leveraging artificial intelligence, the platform enables self-healing capabilities; as a result, tests automatically adapt to UI changes like renamed buttons without failing the entire build. This innovation significantly accelerates test authoring and maintenance, empowering team members without deep coding knowledge to participate in the quality assurance process. Furthermore, the system avoids the limitations of typical AI “black boxes” by providing transparent debugging logs and the option to export AI-generated steps into standard code for long-term stability and peer review.Ultimately, this technology promotes broader team participation by allowing non-technical members to contribute to the testing process without deep knowledge of JavaScript.
In 2025, the release of cy.prompt() fundamentally shifted how teams approach end-to-end testing by introducing a native, AI-powered way to write tests in plain English. This experimental feature, introduced in Cypress 15.4.0, allows you to describe user journeys in natural language, which Cypress then translates into executable commands.
Why use cy.prompt()?
- Reduced Maintenance: If a UI change (like a renamed ID) breaks a test, cy.prompt() can automatically regenerate selectors through its self-healing capability.
- Faster Test Creation: As a result, you can go from a business requirement to a running test in seconds without writing manual JavaScript or hunting for selectors.
- Democratized Testing: Consequently, product managers and non-technical stakeholders are empowered to contribute to automation through Gherkin-style steps in the test suite.
- Generate and Eject (For Stable Apps):To start, use cy.prompt() to scaffold your test. Once generated, click the “Code” button in the Command Log and save the static code to your spec file; this approach is ideal for CI/CD pipelines that require strictly deterministic, frozen code.
- Continuous Self-Healing (For Fast-Paced Development): Keep the cy.prompt() commands in your repository. Cypress will use intelligent caching to run at near-native speeds on subsequent runs, only re-calling the AI if the UI changes significantly.
Why it’s “Smart”:
Self-Healing: If a developer changes a class to a test-id, cy.prompt() won’t fail; it re-evaluates the page to find the most logical element.
Speed: It uses Intelligent Caching. The AI is only invoked on the first run; subsequent runs use the cached selector paths, maintaining the lightning-fast speed Cypress is known for.
How to Get Started? How to use cy.prompt in Cypress?
1. Prerequisites and Setup
How to use cy.prompt in Cypress? for AI-driven end-to-end testing with self-healing selectors and faster test creation. Before you can run a program with cy.prompt(), you must configure your environment:
- Version Requirement: Ensure you are using Cypress 15.4.0 or newer.
- Enable the Feature: Open your cypress.config.js (or .ts) file and set the experimentalPromptCommand flag to true within the e2e configuration.
const { defineConfig } = require('cypress');
module.exports = defineConfig({
projectId: 'abc',
e2e: {
experimentalPromptCommand: true,
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});- Authenticate with Cypress Cloud: cy.prompt() requires a connection to Cypress Cloud to access the AI models.
- Local development: Log in to Cypress Cloud directly within the cypress app.
- CI/CD: Use your record key with the –record –key flag.
2. Writing Your First Test
- The command accepts an array of strings representing your test steps.
describe('Prompt command test', () => {
it('runs prompt sequence', () => {
cy.prompt([
"Visit https://aicotravel.co",
"Type 'Paris' in the destination field",
"Click on the first search result",
"Select 4 days from the duration dropdown",
"Press the **Create Itinerary** button"
])
})
})The “smart” way to use cy.prompt() is to combine it with standard commands for a hybrid, high-reliability approach.
describe('User Checkout Flow', () => {
it('should complete a purchase using AI prompts', () => {
cy.visit('/store');
// Simple natural language commands
cy.prompt('Search for "Wireless Headphones" and click the first result');
// Using placeholders for sensitive data to ensure privacy
cy.prompt('Log in with {{email}} and {{password}}', {
placeholders: {
email: 'testuser@example.com',
password: 'SuperSecretPassword123'
}
});
// Verify UI state without complex assertions
cy.prompt('Ensure the "Add to Cart" button is visible and green');
cy.get('.cart-btn').click();
});
});3. The “Smart” Workflow: Prompt-to-Code
Most professional way to use cy.prompt() is as a code generator.
- Drafting: Write your test using cy.prompt().
- Execution: Run the test in the Cypress Open mode.
- Conversion: Once the AI successfully finds the elements, use the “Convert to Code” button in the Command Log.



Save to File: Copy the generated code and replace your cy.prompt() call with it. Consequently, this turns the AI-generated test into a stable, version-controlled test that runs without AI dependency.
Commit: However cypress will generate the standard .get().click() code based on the AI’s findings. You can then commit this hard-coded version to your repository to avoid unnecessary AI calls in your CI/CD pipeline.
4. Best Practices:
- Imperative Verbs: Start prompts with “Click,” “Type,” “Select,” or “Verify.”
- Contextual Accuracy: If a page has two “Submit” buttons, be specific: cy.prompt(‘Click the “Submit” button inside the Newsletter section’).
- Security First: However, never pass raw passwords into the prompt string. Therefore, always use the placeholders configuration to keep sensitive strings out of the AI logs.
- Hybrid Strategy: Ultimately, use cy.prompt() where flexibility is needed for complex UI interactions, and fall back to standard cy.get() for stable elements like navigation links.
GitHub:- https://github.com/jjadhav-dj/cypress-demo
Conclusion:
The introduction of cy.prompt() marks the end of “selector hell.” By treating AI as a pair-programmer that handles the tedious task of DOM traversing, we can write tests that are more readable, easier to maintain, and significantly more resilient to UI changes.
Click here to read more blogs like this.

Jyotsna is a Jr SDET which have expertise in manual and automation testing for web and mobile both. She has worked on Python, Selenium, Mysql,
BDD, Git, HTML & CSS. She loves to explore new technologies and products which put impact on future technologies.

