How to use a note in a task #2272
-
I am attempting to retrieve text from GUI and inject the info into an API call, but I am getting stuck using the Note in a task. This is my API post request task export class REST_API {
static getData = (item: string): Task =>
Task.where(`#actor get api`,
Send.a(PostRequest.to(`/apiget`)
.using({
headers: {
// 'Authorization': `Basic ${token}`,
}})
.with({
item:item,
})),
Log.the(LastResponse.body()),
Ensure.that(LastResponse.status(), equals(200)),
);
} In my test I am trying to do the following await actorCalled('ui-user').attemptsTo(
Navigate.to(url+'/DefaultScreen'),
notes().set('id',Text.of(ITEM_IN_GUI())),
);
await actorCalled('api').attemptsTo(
REST_API.getData(notes().get('id').toString())
); It looks like the task is reading the note as -- Is there a way to get the value of the Note. I have tried the following options notes().get('id').toString()
notes().get('id').as(String).toString() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Your approach makes sense, and the implementation is almost correct.
That's right, as Similarly, calling I'd suggest making the following improvements:
import { Question, Task } from '@serenity-js/core'
interface MyNotes { // (1)
id: string;
}
export class REST_API {
static getData = (itemId: Answerable<string>): Task => // (2)
Task.where(`#actor gets data`,
Send.a(PostRequest.to(`/apiget`)
.using({
headers: {
// 'Authorization': `Basic ${token}`,
}
})
.with(Question.fromObject({ // (3)
item: itemId,
}))),
Log.the(LastResponse.body()),
Ensure.that(LastResponse.status(), equals(200)),
);
} Then, in your test scenario: await actorCalled('ui-user').attemptsTo(
Navigate.to(url+'/DefaultScreen'),
notes<MyNotes>().set('id', Text.of(ITEM_IN_GUI())),
);
await actorCalled('api').attemptsTo(
REST_API.getData(notes<MyNotes>().get('id'))
); |
Beta Was this translation helpful? Give feedback.
Your approach makes sense, and the implementation is almost correct.
That's right, as
notes().get(name)
returns a dynamicQuestion
which needs to be resolved by anActor
.Calling
notes().get('id').toString()
returns a description of theQuestion
object rather than its value.Similarly, calling
notes().get('id').as(String).toString()
will chain a transformationas(String)
to a dynamic value ofnotes().get('id')
, and then.toString()
returns the description rather than the value.I'd suggest making the following improvements:
Answerable<string>
instead of juststring
…