Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle alert and confirm better #621

Closed
brian-mann opened this issue Sep 6, 2017 · 7 comments
Closed

Handle alert and confirm better #621

brian-mann opened this issue Sep 6, 2017 · 7 comments
Assignees
Labels
type: feature New feature that does not currently exist
Milestone

Comments

@brian-mann
Copy link
Member

As it stands Cypress's current behavior is to auto accept alert and confirm.

We should make the following changes:

Alerts

  • Alerts should at least log in the command log as a page event so you can visually see them
  • Alert command log events should capture the alerted value for debugging purposes
  • We should expose an event which enables you to listen to alerts and receive their values

Confirms

  • Confirms should log in the command log as a page event so you can visually see them
  • Confirms should auto accept by default, and save their values for debugging purposes
  • However we should expose an event which enables you to listen for confirms and return false
  • By returning false we will decline the confirmation as opposed to accept it.

You'll now see and have control over these events.

@brian-mann brian-mann added the type: feature New feature that does not currently exist label Sep 6, 2017
@brian-mann brian-mann self-assigned this Sep 6, 2017
@brian-mann
Copy link
Member Author

This is how they'll appear.

screen shot 2017-09-06 at 3 26 21 pm

This is how the confirm event can be controlled:

it "can turn on and off confirmation", ->
      cy.on "window:confirm", (str) ->
        switch str
          when "foo" then false
          when "bar" then true
          when "baz" then undefined

      cy.window().then (win) ->
        confirmedFoo = win.confirm("foo")
        expect(confirmedFoo).to.be.false

        confirmedBar = win.confirm("bar")
        expect(confirmedBar).to.be.true

        ## undefined is not strictly false
        ## so the confirmation should be true
        confirmedBaz = win.confirm("baz")
        expect(confirmedBaz).to.be.true

@brian-mann
Copy link
Member Author

The code for this is done, but has yet to be released. We'll update this issue and reference the changelog when it's released.

@brian-mann
Copy link
Member Author

Fixed in 0.20.0

@drumbeg
Copy link

drumbeg commented Jan 11, 2019

I realise that confirms originating from an iframe will appear, but is there a way to handle and dismiss them from a test?

@novarichuffman
Copy link

If it is a prompt box Cypress will not automatically accept it.

@FabiGomes
Copy link

Any news about how to working on with a prompt box ? Cypress still not automatically accept it.

@jennifer-shehane
Copy link
Member

@FabiGomes Yes there are examples here: cypress-io/cypress-example-recipes#339

@cypress-io cypress-io locked and limited conversation to collaborators Jan 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests

5 participants