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:
Examples:
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)),
);
See also:
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:
Name | Type | Attribute | Description |
newApiUrl | Answerable<string> |
Public Constructors
public constructor(newApiUrl: Answerable<string>) source
Params:
Name | Type | Attribute | Description |
newApiUrl | Answerable<string> |
Public Methods
public performAs(actor: UsesAbilities & CollectsArtifacts & AnswersQuestions): Promise<void> source
Makes the provided Actor perform this Interaction.
Params:
Name | Type | Attribute | Description |
actor | UsesAbilities & CollectsArtifacts & AnswersQuestions |
Returns:
Promise<void> |