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

ChangeApiUrl

Changes the base URL the CallAnApi Ability has been configured with. Useful when we don't know the URL before the test is started, for example when the URL is dynamically generated and needs to be read from the website under test.

Extends:

Interaction → ChangeApiUrl
this class was deprecated. Use ChangeApiConfig.setUrlTo(newUrl) instead

Examples:

Changing the API URL
import { Actor } from '@serenity-js/core';
import { Navigate, Target, Text } from '@serenity-js/protractor';
import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
import { protractor, by } from 'protractor';

import axios  from 'axios';

const actor = Actor.named('Apisit').whoCan(
    BrowseTheWeb.using(protractor.browser),

    // Note: no default base URL is given when the axios instance is created
    CallAnApi.using(axios.create()),
);

// Let's imagine that the website under test displays
// a dynamically generated API URL we'd like to use
const ApiDetailsWidget = {
    Url: Target.the('API URL').located(by.id('api-url')),
}

actor.attemptsTo(
    Navigate.to('/profile'),

    // We change the API URL based on the text displayed in the widget
    // (although we could change it to some arbitrary string too).
    ChangeApiUrl.to(Text.of(ApiDetailsWidget.Url)),

    // Any subsequent request will be sent to the newly set URL
    Send.a(GetRequest.to('/projects')),
    Ensure.that(LastResponse.status(), equals(200)),
);

Static Method Summary

Static Public Methods
public static

to(newApiUrl: Answerable<string>): Interaction

Instantiates a new ChangeApiUrl Interaction.

Constructor Summary

Public Constructor
public

constructor(newApiUrl: Answerable<string>)

Method Summary

Public Methods
public

performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void>

Makes the provided Actor perform this Interaction.

public

toString(): string

Generates a description to be used when reporting this Activity.

Static Public Methods

public static to(newApiUrl: Answerable<string>): Interaction source

Instantiates a new ChangeApiUrl Interaction.

Params:

NameTypeAttributeDescription
newApiUrl Answerable<string>

Returns:

Interaction

Public Constructors

public constructor(newApiUrl: Answerable<string>) source

Params:

NameTypeAttributeDescription
newApiUrl Answerable<string>

Public Methods

public performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> source

Makes the provided Actor perform this Interaction.

Params:

NameTypeAttributeDescription
actor UsesAbilities & CollectsArtifacts & AnswersQuestions

Returns:

Promise<void>

public toString(): string source

Generates a description to be used when reporting this Activity.

Returns:

string