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 for all subsequent requests
 import { actorCalled } from '@serenity-js/core';
 import { Navigate, Target, Text } from '@serenity-js/protractor';
 import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
 import { Ensure, equals } from '@serenity-js/assertions';
 import { protractor, by } from 'protractor';

 import axios from 'axios';

 const actor = actorCalled('Apisitt').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 for all subsequent requests
 import { actorCalled } from '@serenity-js/core';
 import { LocalServer, ManageALocalServer, StartLocalServer } from '@serenity-js/local-server';
 import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest'
 import { Ensure, equals } from '@serenity-js/assertions';

 const actor = actorCalled('Apisitt').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)),
 );
Setting a header for all subsequent requests
 import { actorCalled, Question } from '@serenity-js/core';
 import { CallAnApi, ChangeApiConfig, GetRequest, LastResponse, Send } from '@serenity-js/rest';
 import { Ensure, equals } from '@serenity-js/assertions';

 const actor = actorCalled('Apisitt').whoCan(
     CallAnApi.at('http://localhost'),
 );

 // A sample Question reading Node process environment variable
 const EnvVar = (var_name: string) =>
     Question.about(`${ name } environment variable`, actor => process.env[var_name]);

 actor.attemptsTo(
     ChangeApiConfig.setHeader('Authorization', EnvVar('TOKEN')),
     Send.a(GetRequest.to('/api')),
     Ensure.that(LastResponse.status(), equals(200)),
 );

Static Method Summary

Static Public Methods
public static

setHeader(name: Answerable<string>, value: Answerable<string>): Interaction

Instructs the Actor to modify the configuration of the AxiosInstance used by CallAnApi Ability and set a HTTP request header for any subsequent HTTPRequest issued via Send.

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 setHeader(name: Answerable<string>, value: Answerable<string>): Interaction source

Instructs the Actor to modify the configuration of the AxiosInstance used by CallAnApi Ability and set a HTTP request header for any subsequent HTTPRequest issued via Send.

Params:

NameTypeAttributeDescription
name Answerable<string>
value Answerable<string>

Returns:

Interaction

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