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

Close

Instructs the Actor to close browser tabs or windows.

Examples:

Closing a browser tab or window
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Click, Close, Switch } from '@serenity-js/protractor';
 import { protractor } from 'protractor';

 actorCalled('Caleb')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Click.on(someLinkThatOpensANewWindow),

         Switch.toNewWindow().and(
             // perform activities in the context of the new window
             Close.currentWindow(),
         ),
     );
Closing any new windows after a Jasmine test
 import 'jasmine';

 import { actorInTheSpotlight } from '@serenity-js/core';
 import { Close } from '@serenity-js/protractor';

 after(() =>
     actorInTheSpotlight().attemptsTo(
         Close.anyNewWindows(),
     ));
Closing any new windows after a Mocha test
 import 'mocha';

 import { actorInTheSpotlight } from '@serenity-js/core';
 import { Close } from '@serenity-js/protractor';

 after(() =>
     actorInTheSpotlight().attemptsTo(
         Close.anyNewWindows(),
     ));
Closing any new windows after a Cucumber scenario
 import { actorInTheSpotlight } from '@serenity-js/core';
 import { Close } from '@serenity-js/protractor';
 import { After } from 'cucumber';

 After(() =>
     actorInTheSpotlight().attemptsTo(
         Close.anyNewWindows(),
     ));

Tests:

See also:

Static Method Summary

Static Public Methods
public static

Closes any windows other than the original one that the Actor has Navigated to.

public static

Closes the currently focused browser window.

Static Public Methods

public static anyNewWindows(): Interaction source

Closes any windows other than the original one that the Actor has Navigated to.

When the windows are closed, it switches the context back to the original window.

Returns:

Interaction

See:

public static currentWindow(): Interaction source

Closes the currently focused browser window.

Please note that this interaction should be used to close pop-up windows or any new windows/tabs opened during the test rather than the main window, which is managed by Protractor.

See tests for usage examples.

Returns:

Interaction

See: