Skip to content

Commit 98f5147

Browse files
Update yields of prompt
1 parent 31387ad commit 98f5147

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

docs/api/commands/prompt.mdx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,29 @@ cy.prompt(
6666

6767
<HeaderYields />
6868

69-
- `cy.prompt()` yields `null`.
69+
`cy.prompt()` yields the value yielded by the last Cypress command executed in the prompt. In most cases, this will be an element, but it depends on the last command executed in the prompt.
70+
71+
```javascript
72+
cy.prompt([
73+
// Executes cy.visit('/user-management')
74+
'visit https://cloud.cypress.io/login',
75+
// Executes cy.get('#login-button').click()
76+
'click the login button',
77+
]) // yields <button> since .click() yields the same subject it was originally given.
78+
.closest('form')
79+
.submit()
80+
```
81+
82+
In the example below, the last command executed in the prompt is `.visit()`, so the yielded value is the window object.
83+
84+
```javascript
85+
cy.prompt([
86+
// Executes cy.visit('/user-management')
87+
'visit https://cloud.cypress.io/login',
88+
]) // yields window object since .visit() yields window object
89+
.its('navigator.language')
90+
.should('equal', 'en-US')
91+
```
7092

7193
## How it works
7294

0 commit comments

Comments
 (0)