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

Navigate

Allows the Actor to navigate to a specific destination, as well as back and forth in the browser history, or reload the current page.

Tests:

Static Method Summary

Static Public Methods
public static

Instructs the Actor to navigate back one page in the session history.

public static

Instructs the Actor to navigate forward one page in the session history.

public static

Instructs the Actor to reload the current page.

public static

to(url: Answerable<string>): Interaction & { withTimeout: (duration: Answerable<Duration>) => Interaction }

Instructs the Actor to navigate to a given URL.

Static Public Methods

public static back(): Interaction source

Instructs the Actor to navigate back one page in the session history.

Returns:

Interaction

Examples:

Navigate to path relative to baseUrl
 import { actorCalled } from '@serenity-js/core';
 import { Ensure, endsWith } from '@serenity-js/assertions';
 import { BrowseTheWeb, Navigate } from '@serenity-js/protractor';

 actorCalled('Hannu')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Navigate.to('/first'),
         Navigate.to('/second'),

         Navigate.back(),

         Ensure.that(Website.url(), endsWith('/first')),
     );

public static forward(): Interaction source

Instructs the Actor to navigate forward one page in the session history.

Returns:

Interaction

Examples:

Navigate to path relative to baseUrl
 import { actorCalled } from '@serenity-js/core';
 import { Ensure, endsWith } from '@serenity-js/assertions';
 import { BrowseTheWeb, Navigate } from '@serenity-js/protractor';

 actorCalled('Hannu')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Navigate.to('/first'),
         Navigate.to('/second'),

         Navigate.back(),
         Navigate.forward(),

         Ensure.that(Website.url(), endsWith('/second')),
     );

public static reloadPage(): Interaction source

Instructs the Actor to reload the current page.

Returns:

Interaction

Examples:

Navigate to path relative to baseUrl
 import { actorCalled } from '@serenity-js/core';
 import { Ensure, endsWith } from '@serenity-js/assertions';
 import { Navigate, BrowseTheWeb, DeleteCookies } from '@serenity-js/protractor';

 actorCalled('Hannu')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Navigate.to('/login'),
         DeleteCookies.called('session_id'),
         Navigate.reloadPage(),
     );

public static to(url: Answerable<string>): Interaction & { withTimeout: (duration: Answerable<Duration>) => Interaction } source

Instructs the Actor to navigate to a given URL.

The URL can be:

  • absolute, i.e. https://example.org/search
  • relative, i.e. /search

    If the URL is relative, Protractor will append it to baseUrl configured in protractor.conf.js.

Params:

NameTypeAttributeDescription
url Answerable<string>

An absolute URL or path an Actor should navigate to

Returns:

Interaction & { withTimeout: (duration: Answerable<Duration>) => Interaction }

Examples:

protractor.conf.js
 exports.config = {
     baseUrl: 'https://example.org',
     // ...
 }
Navigate to path relative to baseUrl
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Navigate } from '@serenity-js/protractor';

 actorCalled('Hannu')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Navigate.to('/search'),
     );
Navigate to an absolute URL (overrides baseUrl)
 import { actorCalled } from '@serenity-js/core';
 import { BrowseTheWeb, Navigate } from '@serenity-js/protractor';

 actorCalled('Hannu')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Navigate.to('https://mycompany.org/login'),
     );
Navigate to URL with timeout
 import { actorCalled, Duration } from '@serenity-js/core';
 import { BrowseTheWeb, Navigate } from '@serenity-js/protractor';

 actorCalled('Hannu')
     .whoCan(BrowseTheWeb.using(protractor.browser))
     .attemptsTo(
         Navigate.to('/search').withTimeout(Duration.ofSeconds(2)),
     );

See: