Skip to content
Merged
17 changes: 17 additions & 0 deletions packages/driver/cypress/e2e/commands/prompt/prompt.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
describe('src/cy/commands/prompt', () => {
afterEach(() => {
Cypress.testingType = 'e2e'
})

it('executes the prompt command', () => {
// TODO: (cy.prompt) We will look into supporting other browsers
// as this is rolled out. We will add error messages for other browsers
Expand All @@ -15,4 +19,17 @@ describe('src/cy/commands/prompt', () => {

cy.get('#log').should('contain', 'clicked')
})

it('fails when testingType is component', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.eq('`cy.prompt` is currently only supported in end-to-end tests.')
done()
})

Cypress.testingType = 'component'

cy.visit('http://www.foobar.com:3500/fixtures/prompt.html')

cy.prompt(['Click the "click me" button'])
})
})
10 changes: 10 additions & 0 deletions packages/driver/src/cy/commands/prompt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,15 @@ export default (Commands: Cypress.Cypress['Commands'], Cypress: Cypress.Cypress,
}

Commands.addAll(commands)
} else {
Commands.addAll({
prompt (steps: string[], commandOptions: object = {}) {
if (Cypress.testingType === 'component') {
$errUtils.throwErrByPath('prompt.promptTestingTypeError')
}

$errUtils.throwErrByPath('prompt.experimentalPromptCommandError')
},
})
}
}
8 changes: 8 additions & 0 deletions packages/driver/src/cypress/error_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,14 @@ export default {
docsUrl: 'https://on.cypress.io/prompt-download-error',
}
},
promptTestingTypeError: stripIndent`\
\`cy.prompt\` is currently only supported in end-to-end tests.
`,
experimentalPromptCommandError: stripIndent`\
\`cy.prompt\` cannot be called without the \`experimentalPromptCommand\` being set.

Please set this in your Cypress config file to continue using \`cy.prompt\`.
`,
},

proxy: {
Expand Down
70 changes: 70 additions & 0 deletions system-tests/__snapshots__/prompt_spec.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
exports['e2e prompt / fails when experimentalPromptCommand is not set'] = `

====================================================================================================

(Run Starting)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (prompt.cy.js) │
│ Searched: cypress/e2e/prompt.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

Running: prompt.cy.js (1 of 1)


prompt
1) should fail when experimentalPromptCommand is not set


0 passing
1 failing

1) prompt
should fail when experimentalPromptCommand is not set:
CypressError: \`cy.prompt\` cannot be called without the \`experimentalPromptCommand\` being set.

Please set this in your Cypress config file to continue using \`cy.prompt\`.
[stack trace lines]




(Results)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 0 │
│ Failing: 1 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 1 │
│ Video: false │
│ Duration: X seconds │
│ Spec Ran: prompt.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘


(Screenshots)

- /XXX/XXX/XXX/cypress/screenshots/prompt.cy.js/prompt -- should fail when experim (2560x1440)
entalPromptCommand is not set (failed).png


====================================================================================================

(Run Finished)


Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✖ prompt.cy.js XX:XX 1 - 1 - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 1 of 1 failed (100%) XX:XX 1 - 1 - -


`
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
e2e: {
supportFile: false,
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('prompt', () => {
it('should fail when experimentalPromptCommand is not set', () => {
cy.prompt(['Click the "click me" button'])
})
})
14 changes: 14 additions & 0 deletions system-tests/test/prompt_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import systemTests from '../lib/system-tests'

describe('e2e prompt', () => {
systemTests.setup()

systemTests.it('fails when experimentalPromptCommand is not set', {
browser: 'electron',
project: 'experimentalPromptCommand',
spec: 'prompt.cy.js',
configFile: 'cypress-disabled-prompt-experiment.config.js',
expectedExitCode: 1,
snapshot: true,
})
})
Loading