I am already using implicit and fluent wait, but want to use thread.sleep, so want to know the syntax of it
-
it's just `Thread.sleep(time)` – globalworming May 25 '20 at 09:01
-
Thanks for the answer but I was looking for something specific in screenplay syntax as Thread.sleep is traditional java thing – Praney Bajaj May 26 '20 at 11:58
-
serenity bdd is java :) it uses thread.sleep when waiting for stuff and you can use it too as is – globalworming May 26 '20 at 14:16
2 Answers
Using Thread.sleep()
is discouraged and there is no Performable
for that in serenity.
Many testers pepper their web tests with Thread.sleep() statements, but this is the sub-optimal at best. It slows down the tests, makes them more brittle, and can hide genuine application issues. More insidiously, when our steps are artificially slowed by sleep statements, it takes longer not only to run and troubleshoot existing tests, but also to develop new ones.
https://johnfergusonsmart.com/handling-waits-and-asynchronous-pages-in-serenity-bdd/

- 757
- 1
- 5
- 33
-
Agree and I am using the same but want to use Thread.sleep intentionally :) – Praney Bajaj May 29 '20 at 08:37
I know my reply is very late and it's a very bad practice but I am posting here just for the sake of if it can be done. Also from your question it seems like you want to make a task of it. To do this you can make a anonymous task. For example
Integer wait = 500;
Task.where("{0} uses thread sleep",(actor)-> {
try {
Thread.sleep(wait);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
You can wrap it inside a function or assign it to a Task variable. Just if you are wandering Task class have a overloaded method named where
which takes a Consumer<Actor>
as second argument instead of Performable
.
Also you can make a normal task class by implementing Task and use thread sleep in performAs method.
But again considering you are using serenity I doubt it will come to the point where you would have to use Thread.sleep.

- 72
- 12