Skip to content

Commit ea8566e

Browse files
Iterate on wording
1 parent db437f5 commit ea8566e

File tree

1 file changed

+72
-19
lines changed

1 file changed

+72
-19
lines changed

docs/api/commands/prompt.mdx

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ sidebar_custom_props: { 'new_label': true }
1111

1212
# prompt
1313

14-
`cy.prompt` is an AI-powered Cypress command that turns plain English test steps into executable Cypress code. It offers a fast way to explore new test flows, bootstrap end-to-end coverage, and prototype without writing selectors or commands by hand. It is available on all Cypress Cloud plan types.
14+
`cy.prompt` is an AI-powered Cypress command that turns plain English test steps into executable Cypress code. It's designed to be flexible - you can use it to quickly generate tests and commit them to source control, or keep it running continuously for self-healing tests that adapt to your app's changes. You can choose the workflow that fits your project's needs.
1515

1616
:::note
1717

1818
<strong>Before you start coding with `cy.prompt`</strong>
1919

20-
20+
- [Choosing your workflow](#choose-your-workflow) — how to use `cy.prompt` in your project
2121
- [How it works](#how-it-works) — code generation, caching, and self-healing
2222
- [Writing effective prompts](#writing-effective-prompts) — patterns that work best
2323
- [Selectors](#how-selectors-are-chosen) — how Cypress selects elements automatically
@@ -68,9 +68,10 @@ cy.prompt([
6868
- `cy.prompt()` yields `null`.
6969

7070

71+
7172
## How it works
7273

73-
When you call `cy.prompt`, Cypress performs a multi-step process:
74+
When you call `cy.prompt`, Cypress performs a multi-step process that works for both workflows:
7475

7576
1. **Interpret prompt:** Each string in your `steps[]` array is parsed using an AI model. Cypress maps the intent (e.g. 'click the login button') to Cypress commands (`cy.get(...).click()`) and target elements.
7677

@@ -80,10 +81,76 @@ When you call `cy.prompt`, Cypress performs a multi-step process:
8081

8182
4. **Cache for speed:** Generated code is cached. Re-running the same test does not re-call the AI model unless the prompt or DOM changes in a way that invalidates the cached code.
8283

83-
5. **Self-heal if needed:** If cached selectors fail (element renamed, attributes changed, etc.), Cypress regenerates code for that step. This 'self-healing' happens automatically on future runs.
84+
5. **Self-heal if needed:** If cached selectors fail (element renamed, attributes changed, etc.), Cypress regenerates code for that step. This 'self-healing' happens automatically on future runs.
85+
86+
6. **Choose your workflow:** `cy.prompt` supports two flexible workflows depending on your project needs.
87+
- **Export the code** - Save generated code to your test file for predictable, version-controlled tests
88+
- **Keep it running** - Let `cy.prompt` continue to self-heal and adapt to changes
89+
90+
## Choose your workflow
91+
92+
`cy.prompt` supports two flexible workflows depending on your project needs. Both workflows give you full visibility into what code was generated, so you can always inspect and modify the results.
93+
94+
### Workflow 1: Generate once, commit to source control
8495

85-
6. **Version control (optional):** You can view generated code in the Command Log and save it to your test file for version control. Once saved, the test no longer depends on AI at runtime. This can be ideal for projects that do not want to rely on self-healing or the AI to interpret the prompt on every run.
96+
Use `cy.prompt` to generate tests, then export and commit the code.
97+
98+
#### Why choose this workflow?
99+
100+
- **Predictable execution** - You know exactly what code runs every time
101+
- **Fast test generation** - Use AI to quickly create test skeletons
102+
- **No AI dependency** - Tests run without calling the AI service
103+
- **PR review friendly** - Generated code fits into existing review processes
104+
- **Stable selectors** - Your app has stable, predictable elements
105+
106+
#### Example
107+
108+
```typescript
109+
// Generate the test
110+
cy.prompt([
111+
'visit https://cloud.cypress.io/login',
112+
'type "[email protected]" in the email field',
113+
'type ${password} in the password field',
114+
'click the login button',
115+
'verify we are redirected to the dashboard'
116+
], {
117+
excludeFromAI: ['password']
118+
})
119+
```
86120

121+
Use the **Get code** button to view the generated Cypress code. This will display the generated code in a dialog where you can preview what Cypress generated from your prompt. You can save the code to your test file, commit it to your version control system, or copy it to your clipboard.
122+
123+
<DocsVideo
124+
src="/img/api/prompt/cy-prompt-demo.mp4"
125+
autoPlay={true}
126+
title="cy.prompt written for login screen using Cypress Studio"
127+
/>
128+
129+
130+
131+
### Workflow 2: Continuous AI-powered testing
132+
133+
Keep `cy.prompt` in your tests and let it self-heal and adapt to changes.
134+
135+
#### Why choose this workflow?
136+
137+
- **Self-healing selectors** - Tests adapt when your app changes
138+
- **Less maintenance** - No need to update tests for every UI change
139+
- **Dynamic content friendly** - Works well with changing data
140+
- **Smart regeneration** - AI handles selector failures automatically
141+
- **Rapid iteration** - Perfect for apps in active development
142+
143+
#### Example
144+
145+
```typescript
146+
// Let cy.prompt run on every test execution
147+
cy.prompt([
148+
'visit the product catalog',
149+
'filter by category "Electronics"',
150+
'sort by price high to low',
151+
'verify the product count is 25'
152+
])
153+
```
87154

88155
## Writing Effective Prompts
89156

@@ -172,20 +239,6 @@ If Cypress cannot interpret a step, you'll see a dialog prompting you to refine
172239
'wait 5 seconds'
173240
```
174241

175-
176-
## Reliability and control
177-
178-
Everything within `cy.prompt()` is logged in the Cypress Command Log:
179-
180-
- The **prompt** you wrote
181-
- The **Cypress command(s)** generated
182-
183-
You can use the **Get code** button to view the generated Cypress code. This will display the generated code in a dialog where you can preview what Cypress generated from your prompt. You can save the code to your test file, commit it to your version control system, or copy it to your clipboard.
184-
185-
This allows you to use `cy.prompt` as a starting point for your test, but modify it to fit your needs and commit it to your version control system so that you do not rely on the AI for each run to work.
186-
187-
This can be ideal for projects that do not want to rely on self-healing or the AI to interpret the prompt on every run, or for projects that want to commit the generated code to their version control system.
188-
189242
## Setup
190243

191244
### Enable the command

0 commit comments

Comments
 (0)