externalabstractModalDialog
Hierarchy
Implements
Index
Constructors
externalconstructor
Returns ModalDialog
Methods
staticexternalisPresent
Returns a promise that resolves to
truewhen a modal dialog has been handled, so accepted or dismissed. Returnsfalsefor dialogs that haven't been handled yet.Useful when a JavaScript modal dialog is generated after a delay, e.g. triggered by
setTimeout.Example usage
import { actorCalled, Wait } from '@serenity-js/core'
import { Ensure, equals, isPresent } from '@serenity-js/assertions'
import { ModalDialog } from '@serenity-js/web'
await actorCalled('Nick').attemptsTo(
ModalDialog.acceptNext(),
Wait.until(ModalDialog, isPresent()),
Ensure.that(ModalDialog.lastDialogState(), equals('accepted')),
)Returns Question<Promise<boolean>>
staticexternalacceptNext
Produces an interaction that invokes
ModalDialog.acceptNext.Returns Interaction
staticexternalacceptNextWithValue
Produces an interaction that invokes
ModalDialog.acceptNextWithValue.Parameters
externalvalue: Answerable<string | number>
Returns Interaction
staticexternaldismissNext
Produces an interaction that invokes
ModalDialog.dismissNext.Returns Interaction
staticexternallastDialogMessage
QuestionAdapterthat resolves toModalDialog.messagefor the currentPage.Returns QuestionAdapter<string>
staticexternallastDialogState
QuestionAdapterthat resolves toModalDialog.statefor the currentPage.Returns QuestionAdapter<string>
externalabstractmessage
Returns the message of the last modal dialog handled, or rejects the promise with a
LogicErrorwhen no modal dialogs have been observed yet.Returns Promise<string>
Message of the last handled dialog, or a
Promiserejected with aLogicErrorwhen no dialog has been handled yet.
externalabstractisPresent
Returns a promise that resolves to
truewhen a modal dialog has been handled, so either accepted or dismissed. Returnsfalsefor dialogs that haven't been handled yet.Useful when a JavaScript modal dialog is generated after a delay, e.g. triggered by
setTimeout.Returns Promise<boolean>
externalstate
Returns
acceptedordismissedfor dialogs that have been handled, orabsentfor those that haven't been handled yet.Returns string
Manages interactions with JavaScript modal dialog windows, triggered by window.alert, window.confirm, or
window.prompt, and stores theirmessageso that it can be asserted on once the dialog is handled.Note that in order to make handling modal windows consistent across the various Web integration tools (such as Playwright, Puppeteer, WebdriverIO or Selenium), Serenity/JS works as follows:
ModalDialog.acceptNext,ModalDialog.acceptNextWithValue, orModalDialog.dismissNextbefore the dialog is triggered, as per the below examples.Wait.until(ModalDialog, isPresent())so that you can synchronise your tests with modal dialogs that appear after a delay.Example HTML widget
In the below example widget, clicking on the button results in a confirmation dialog appearing.
Modal dialog gets dismissed by default
Changing modal dialog handler
Learn more
Optional