Skip to content

Commit e7b9470

Browse files
Add viewport support to prompt (#6312)
* document viewport support * lint
1 parent 565a3e9 commit e7b9470

File tree

1 file changed

+54
-26
lines changed

1 file changed

+54
-26
lines changed

docs/api/commands/prompt.mdx

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ If Cypress cannot interpret a step, you'll see a dialog prompting you to refine
282282
'confirm that the code frame includes HTML "<span class="token">'
283283
```
284284

285+
### Change the viewport
286+
287+
```javascript
288+
'set the viewport to 400x600'
289+
```
290+
285291
### Wait
286292

287293
```javascript
@@ -671,49 +677,71 @@ cy.origin('https://cloud.cypress.io/login', () => {
671677
### Mixed with traditional Cypress
672678

673679
```javascript
674-
const electronicsCount = 25
680+
const electronicsCount = Cypress.env('staging') === true ? 5 : 25
675681

676-
// Confirm the UI works in desktop view
677-
cy.viewport(1024, 768)
682+
// Confirm the UI works in staging environment
683+
cy.task('seedStagingDB')
678684
cy.visit(`${Cypress.env('stagingUrl')}/products`)
679-
cy.prompt([
680-
'filter by category "Electronics"',
681-
'sort by price high to low',
682-
`verify the product count is ${electronicsCount}`,
683-
'verify the sort indicator is "Price: High to Low"',
684-
])
685+
cy.prompt(
686+
[
687+
'filter by category "Electronics"',
688+
'sort by price high to low',
689+
`verify the product count is {{electronicsCount}}`,
690+
'verify the sort indicator is "Price: High to Low"',
691+
],
692+
{
693+
placeholders: {
694+
electronicsCount,
695+
},
696+
}
697+
)
685698

686-
// Confirm the UI works in mobile view
687-
cy.viewport(400, 600)
688-
cy.visit(`${Cypress.env('stagingUrl')}/products`)
689-
cy.prompt([
690-
'filter by category "Electronics"',
691-
'sort by price high to low',
692-
`verify the product count is ${electronicsCount}`,
693-
'verify the sort indicator is "Price: High to Low"',
694-
])
699+
// Confirm the UI works in production environment
700+
cy.task('seedProductionDB')
701+
cy.visit(`${Cypress.env('productionUrl')}/products`)
702+
cy.prompt(
703+
[
704+
'filter by category "Electronics"',
705+
'sort by price high to low',
706+
`verify the product count is {{electronicsCount}}`,
707+
'verify the sort indicator is "Price: High to Low"',
708+
],
709+
{
710+
placeholders: {
711+
electronicsCount,
712+
},
713+
}
714+
)
695715
```
696716

697717
Or to further clean up the `cy.prompt` call:
698718

699719
```javascript
700-
const electronicsCount = 25
720+
const electronicsCount = Cypress.env('staging') === true ? 5 : 25
701721
const electronicsFilterPrompt = [
702722
'filter by category "Electronics"',
703723
'sort by price high to low',
704-
`verify the product count is ${electronicsCount}`,
724+
`verify the product count is {{electronicsCount}}`,
705725
'verify the sort indicator is "Price: High to Low"',
706726
]
707727

708-
// Confirm the UI works in desktop view
709-
cy.viewport(1024, 768)
728+
// Confirm the UI works in staging environment
729+
cy.task('seedStagingDB')
710730
cy.visit(`${Cypress.env('stagingUrl')}/products`)
711-
cy.prompt(electronicsFilterPrompt)
731+
cy.prompt(electronicsFilterPrompt, {
732+
placeholders: {
733+
electronicsCount,
734+
},
735+
})
712736

713-
// Confirm the UI works in mobile view
714-
cy.viewport(400, 600)
737+
// Confirm the UI works in production environment
738+
cy.task('seedProductionDB')
715739
cy.visit(`${Cypress.env('stagingUrl')}/products`)
716-
cy.prompt(electronicsFilterPrompt)
740+
cy.prompt(electronicsFilterPrompt, {
741+
placeholders: {
742+
electronicsCount,
743+
},
744+
})
717745
```
718746

719747
## Limitations

0 commit comments

Comments
 (0)