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

ChangeApiConfig

Changes configuration of the CallAnApi Ability the Actor executing this Interaction has been configured with.

Examples:

Changing API URL
 import { Actor } from '@serenity-js/core';
 import { Navigate, Target, Text } from '@serenity-js/protractor';
 import { CallAnApi, ChangeApiConfig, 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).
     ChangeApiConfig.setUrlTo(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)),
 );
Changing API port
 import { Actor } from '@serenity-js/core';
 import { LocalServer, ManageALocalServer, StartLocalServer } from '@serenity-js/local-server';
 import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'

 const actor = Actor.named('Apisit').whoCan(
     ManageALocalServer.runningAHttpListener(someServer),
     CallAnApi.at(http://localhost),
 );

 actor.attemptsTo(
    StartALocalServer.onRandomPort(),
    ChangeApiConfig.setPortTo(LocalServer.port()),
    Send.a(GetRequest.to('/api')),
    Ensure.that(LastResponse.status(), equals(200)),
 );

Static Method Summary

Static Public Methods
public static

setPortTo(newApiPort: Answerable<string>): Interaction

Instructs the Actor to change the port configured in the base URL of their CallAnApi Ability

public static

setUrlTo(newApiUrl: Answerable<string>): Interaction

Instructs the Actor to change the base URL of their CallAnApi Ability

Static Public Methods

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

Instructs the Actor to change the base URL of their CallAnApi Ability

Params:

NameTypeAttributeDescription
newApiUrl Answerable<string>

Returns:

Interaction