import {ModalDialog} from '@serenity-js/protractor/lib/screenplay/questions'
public class | source

ModalDialog

Represents a modal dialog window created using Window.alert(), Window.prompt() or Window.confirm().

Check out the examples below, as well as the unit tests demonstrating the usage.

Examples:

Example widget
 <button
     data-test="trigger"
     onclick="alert('Hello!')">Trigger Alert</button>
Lean Page Object
 import { Target } from '@serenity-js/protractor';
 import { browser, by } from 'protractor';

 class Widget {
     static trigger = Target.the('trigger button')
         .located(by.css('[data-test="trigger"]'));
 }

Tests:

Static Method Summary

Static Public Methods
public static

hasPoppedUp(): Question<Promise<boolean>>

Resolves to true if the modal dialog window is present, or false if it's not.

public static

message(): Question<Promise<string>>

Resolves to the message displayed in the modal dialog window.

public static

A modal dialog window that could be Accepted or Dismissed.

Static Public Methods

public static hasPoppedUp(): Question<Promise<boolean>> source

Resolves to true if the modal dialog window is present, or false if it's not.

Returns:

Question<Promise<boolean>>

Examples:

Verifying if a modal dialog window is present
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Click, ModalDialog } from '@serenity-js/protractor';
 import { Ensure, isFalse, isTrue } from '@serenity-js/assertions';
 import { protractor } from 'protractor';

 actorCalled('Nick')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Ensure.that(ModalDialog.hasPoppedUp(), isFalse()),
         Click.on(Widget.trigger),
         Ensure.that(ModalDialog.hasPoppedUp(), isTrue()),
     );
Waiting for a modal dialog window
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Click, Dismiss, ModalDialog, Wait } from '@serenity-js/protractor';
 import { isTrue } from '@serenity-js/assertions';
 import { protractor } from 'protractor';

 actorCalled('Nick')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Click.on(Widget.trigger),
         Wait.until(ModalDialog.hasPoppedUp(), isTrue()),
         Dismiss.the(ModalDialog.window()),
     );

public static message(): Question<Promise<string>> source

Resolves to the message displayed in the modal dialog window.

Returns:

Question<Promise<string>>

Examples:

Verifying the message
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Click, ModalDialog } from '@serenity-js/protractor';
 import { Ensure, equals } from '@serenity-js/assertions';
 import { protractor } from 'protractor';

 actorCalled('Nick')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Click.on(Widget.trigger),
         Ensure.that(ModalDialog.message(), equals('Hello!')),
     );

public static window(): Question<AlertPromise> source

A modal dialog window that could be Accepted or Dismissed.

If the window was created using Window.prompt() you can use the Interaction to Enter with it too.

Examples:

Accepting an alert
 import { actorCalled } from '@serenity-js/core';
 import { Accept, BrowseTheWeb, Click, ModalDialog } from '@serenity-js/protractor';
 import { protractor } from 'protractor';

 actorCalled('Nick')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Click.on(Widget.trigger),
         Accept.the(ModalDialog.window()),
     );