You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`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.
15
15
16
16
:::note
17
17
18
18
<strong>Before you start coding with `cy.prompt`</strong>
19
19
20
-
20
+
-[Choosing your workflow](#choose-your-workflow) — how to use `cy.prompt` in your project
21
21
-[How it works](#how-it-works) — code generation, caching, and self-healing
22
22
-[Writing effective prompts](#writing-effective-prompts) — patterns that work best
23
23
-[Selectors](#how-selectors-are-chosen) — how Cypress selects elements automatically
@@ -68,9 +68,10 @@ cy.prompt([
68
68
-`cy.prompt()` yields `null`.
69
69
70
70
71
+
71
72
## How it works
72
73
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:
74
75
75
76
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.
76
77
@@ -80,10 +81,76 @@ When you call `cy.prompt`, Cypress performs a multi-step process:
80
81
81
82
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.
82
83
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
84
95
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
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
+
```
87
154
88
155
## Writing Effective Prompts
89
156
@@ -172,20 +239,6 @@ If Cypress cannot interpret a step, you'll see a dialog prompting you to refine
172
239
'wait 5 seconds'
173
240
```
174
241
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.
0 commit comments