1

I am writing some BDD automation test using Cucumber in combination with Serenity framework. And I need some timeout mechanism in my BDD test so that if a Cucumber scenario or a Step in Serenity is taking too long, it will time out and test will fail.

I found some information in the link below: https://groups.google.com/forum/#!topic/cukes/QaPvVMnqDvE

So for Cucumber, it seems the following setup in Step Definition should do the work:

@When(value="^I request web authentication$", timeout=1000) 
public myfunc(){
}

For Serenity, I did not found any setting for timeout, but I guess it's just that I have not found it yet.

However, when I tried the timeout=xxx for Cucumber, it does not seem to work. Even though myfunc() hangs for a long time in my test, the test is not stopped, just hanging.

Anyone knows if there are additional setups for this timeout=xxx to work?

Also is Serenity having any similar timeout mechanism of its own to be used?

Finally I am using maven clean install to drive the test, maybe I am missing some maven setup for this to work?

Any hint will be very appreciated.

user1559625
  • 2,583
  • 5
  • 37
  • 75

3 Answers3

3

Timeout for Serenity can be handled by the following properties:

  1. webdriver.timeouts.implicitlywait
  2. webdriver.wait.for.timeout
  3. serenity.timeout

You can also get more information about Serenity timeouts in

http://thucydides.info/docs/serenity-staging/#_working_with_timeouts https://github.com/serenity-bdd/serenity-documentation/blob/master/src/asciidoc/system-props.adoc

Sarabjit Singh
  • 786
  • 4
  • 4
1

Instead of directly using only Maven install to drive the tests, use Junit or TestNG along with it to do that. If you use Junit, timeout could be done as:

@Test(timeout = 20)
public void try() {
    while(true);
}

TestNG also works almost the same way:

@Test(timeOut = 10000)
public void try() {
    while(true);
}

Cucumber has dependencies available which are compatible with both JUnit and TestNG.


The Cucumber timeout you tried will work only if:

  • the thread being used is at sleep for the number of milliseconds presented in the timeout you specified. To overcome this you can create a separate thread for separate tests so that your thread (for the test that hangs) sleeps. But this might no be really what you are looking for.
  • the thread becomes uninterruptible, then it will be stopped after twice the specified timeout.

As mentioned by @aslakhellesoy @here

Timeout stops threads if they are uninterruptible. …

If a thread does not respond to interrupt() we'll try to stop() it after twice the specified timeout.

This uses the deprecated Thread.stop() method, but for a testing tool like Cucumber that should be ok.

Ref #343.

So you have to lower your timeout time by half.

Star
  • 101
  • 1
  • 4
0

Or, if you need a delay after each step, you can use the property:

serenity.step.delay={time in ms}

Bogdan Pisarenko
  • 357
  • 1
  • 5
  • 17