externalabstractModalDialog
Hierarchy
Implements
Index
Constructors
externalconstructor
Returns ModalDialog
Methods
staticexternalisPresent
Returns a promise that resolves to
true
when a modal dialog has been handled, so accepted or dismissed. Returnsfalse
for 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
QuestionAdapter
that resolves toModalDialog.message
for the currentPage
.Returns QuestionAdapter<string>
staticexternallastDialogState
QuestionAdapter
that resolves toModalDialog.state
for the currentPage
.Returns QuestionAdapter<string>
externalabstractmessage
Returns the message of the last modal dialog handled, or rejects the promise with a
LogicError
when no modal dialogs have been observed yet.Returns Promise<string>
Message of the last handled dialog, or a
Promise
rejected with aLogicError
when no dialog has been handled yet.
externalabstractisPresent
Returns a promise that resolves to
true
when a modal dialog has been handled, so either accepted or dismissed. Returnsfalse
for 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
accepted
ordismissed
for dialogs that have been handled, orabsent
for 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 theirmessage
so 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.dismissNext
before 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