New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I ask a question in a task? #57
Comments
Try to use this:
|
Cheers for response @marktigno - actually, I don't want to perform an expectation here, so after some experimentation I think I need something like:
but still not entirely sure 😄 |
Actually, that didn't work... , I ended up used the following approach (return actor.attemptsTo() was just to appease the compiler so I could run it):
But I received: |
Hey @nbarrett, The regular Serenity/JS Actor Saying Now regarding the second part of your question (no pun intended ;-) ). The below construct won't behave the way you'd like it to. That's because performAs(actor: PerformsTasks & AnswersQuestions): PromiseLike<void> {
actor.toSee(ClassWithQuestion.StaticQuestion).forEach(data => console.log(data));
return actor.attemptsTo()
} What I think you wanted to do is either something along those lines, using the performAs(actor: PerformsTasks & AnswersQuestions): PromiseLike<void> {
return actor.attemptsTo(
// some tasks
See.if(ClassWithQuestion.StaticQuestion, someAssertion)
// some more tasks
);
} The above is useful if you need an intra-flow check. Alternatively, if you want to use the value returned by the question, you can do something like this (here's an example): performAs(actor: PerformsTasks & AnswersQuestions): PromiseLike<void> {
return actor.attemptsTo(
TakeNote.of(ClassWithQuestion.StaticQuestion),
// ... other tasks
CompareNotes.toSeeIf(ClassWithQuestion.SomeOtherQuestion, equals, ClassWithQuestion.StaticQuestion)
);
} Does this help? Jan |
Hi @jan - thanks for comprehensive response. Actually that's not quite what I want to do as there are no expectations to perform in my use use. To be more specific, I want to do something like this (note use of pseudo-code):
It might be worth explaining at this point that I'm writing some production code to create some integration with a 'legacy' web-ui which has no API grrrr 😠 , hence the absence of expectation code.. |
Ah right, screen scraping, huh? 😉 I think you might need a custom task for that as there's no support for logical branching I'm afraid. You'll probably need a construct like this: Check.if(/* question<T> */, verification: (value: T) => boolean).andIfSo(/* list of tasks */).otherwise(/* some other tasks */) For example: Check.if(Text.of(H1), (text: string) => text === 'About us').andIfSo(task1, task2, task3).otherwise(task4, task5); |
Yup no REST for the wicked, so resorting to scrape 🙀 FYI, there is not logical branching required in my use case. I pass the entire |
So.... I remain stuck on this one @jan-molak and I have to say a little confused. In previous comments you said actor.toSee() :
When I look at the interface for AnswersQuestions I see:
Cool, so all I have to do to extract the data is to call |
Right, maybe I misunderstood what you wanted to accomplish. Have a look at performAs(actor: AnswersQuestions): PromiseLike<void> {
return actor.toSee(ClassWithQuestion.StaticQuestion).then(resultOfTheQuestion => {
return actor.attemptsTo(
SomeOtherTask.thatUses(resultOfTheQuestion)
);
});
} Does that help? J |
erm... no as the result |
Gotcha, I think this is caused by the Question interface being defined as: export interface Question<T> {
answeredBy(actor: UsesAbilities): PromiseLike<T>|T;
} Which should probably become: export interface Question<T> {
answeredBy(actor: UsesAbilities): T;
} With this change, some questions could be defined as synchronous, so I'll look into this over the coming days. |
Wahoo! thanks @jan-molak - will look into ASAP 👍 |
Hey @jan-molak - here's something that is stumping me now I am using Serenity in javascript rather than java....
I need to be able ask a question within a task as I need to perform actions based on what I find in the question data (aka: answer). In Java I would normally say
<Question>.answeredBy(actor) -> <data>
, however in the serenity-js I see we pass a different actor interface into the Task:performAs(actor: PerformsTasks):
as opposed to the question...
answeredBy(actor: UsesAbilities):
So within my task, I'm getting this problem:
I did see in the serenity source this kind of magic
performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<void>
, but I was unable to decipher whether this treatment is applicable to the problem above. Any thoughts please?PS: Thanks for helping us all learn typescript as well as the awesome serenity-js!
The text was updated successfully, but these errors were encountered: