Closed bandophahita closed 2 years ago
In my test suite, we have a few tasks that do something to the effect of:
# tasks/ensure_status_reads:
class EnsureStatusReads:
...
def perform_as(self, the_actor: Actor) -> None:
the_actor.attempts_to(
Click.on_the(ELEMENT_THAT_REFRESHES_STATUS),
See.the(Text.of_the(STATUS_ELEMENT), ReadsExactly(self.status))
)
We can then do this elsewhere:
the_actor.attempts_to(
Eventually(EnsureStatusReads("Updated"))
)
Does this achieve what you're hoping to see from Ensure
? Maybe we could just add an alias for See
?
I've written those as well. I started to call those "combo actions". But I don't think that's the same thing.
From what I can see in the BDD library there are a bunch of convenience methods that do the equivalent of See(question(TARGET), resolution())
just in a different format.
Something like :
Ensure(TARGET).question().resolution()
In general I think this is a language driven pattern. It feels like a very Java-esque way to write it.
Since See
is an Action and should
is an alias for attempts_to
, there's nothing really stopping you from doing this:
Sam.attempts_to(
Enter.the_text("40").into_the(AGE_FIELD).then_hit(Keys.ENTER),
See.the(Text.of_the(AGE_VALUE), ReadsExactly("40")),
DoSomeOtherStuff(),
...
)
We've even got Confirm
as an alias for See
, which is probably more "ensure"-like.
Closing this one as we do have a mechanism to mimic this behavior already in ScreenPy, and i don't like how we'd have to write new methods to handle each of the possible question/resolution pairs.
I discussed this on Discord with @bandophahita and he's cool with closing this issue, though he thinks making dynamic methods sounds like a fun challenge. :P
Serenity BDD has a nifty alternative to make assertions that would make a nice addition to screenpy;
Ensure
Java example:
Special consideration will need to be taken into account to allow expansion of this class since the methods which comprise of resolutions aren't solely in the screenpy package. For instance
screenpy_selenium
hasIsVisibleElement
which would be nice to use for the folks who use selenium but should not be part ofEnsure
in the base package.Perhaps there is some magic to be had here to avoid awkward imports between packages.