Test Scenario or step time out setting on Cucumber

3,163 views
Skip to first unread message

Maggie Zhou

unread,
Jul 29, 2014, 7:30:01 PM7/29/14
to cu...@googlegroups.com
Hi, All,

I was wondering if there's a way to set timeout for scenarios or steps? I am using cucumber-jvm. And I saw there's runtime timeout class https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/runtime/Timeout.java

But I don't know how to use it. Could you please give me an example?

my test could be as following, and I 'd like skip the rest steps when any step take >3 secs. 

Scenario Outline: Create a account
Given I provide email and password
When I request create account
Then the response is "Created"
Then the response contains expect information

Thanks a lot

Paolo Ambrosio

unread,
Jul 30, 2014, 3:59:35 AM7/30/14
to cu...@googlegroups.com
On Wed, Jul 30, 2014 at 12:30 AM, Maggie Zhou <zhouch...@gmail.com> wrote:

> Hi, All,
>
> I was wondering if there's a way to set timeout for scenarios or steps? I am
> using cucumber-jvm. And I saw there's runtime timeout class
> https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/runtime/Timeout.java
>
> But I don't know how to use it. Could you please give me an example?

Never used it but in Java it should be...

@Given(value="your regex here", timeout=3000)

You can use it for steps and hooks in the same way. Not sure if there
is a way of setting it globally.

Maggie Zhou

unread,
Jul 30, 2014, 1:09:37 PM7/30/14
to cu...@googlegroups.com
Thanks a lot. I added to one of my step. But the step won't be timeout.this steps takes 20 secs on my box and I didn't get the step timeout. Anything I could do?

 @When(value="^I request web authentication$", timeout=1000)    
    public void I_request_authentication() {
        httpRequest.setRequestPath("/authentication");            
        httpRequest.setRequestBody("");
        httpRequest.sendPostRequest();   
        actualResBody = getResponseStringFromStream(httpRequest.); 

Paolo Ambrosio

unread,
Jul 31, 2014, 4:03:23 PM7/31/14
to cu...@googlegroups.com
On Wed, Jul 30, 2014 at 6:09 PM, Maggie Zhou <zhouch...@gmail.com> wrote:
> Thanks a lot. I added to one of my step. But the step won't be timeout.this
> steps takes 20 secs on my box and I didn't get the step timeout. Anything I
> could do?
>
> @When(value="^I request web authentication$", timeout=1000)
> public void I_request_authentication() {
> httpRequest.setRequestPath("/authentication");
> httpRequest.setRequestBody("");
> httpRequest.sendPostRequest();
> actualResBody = getResponseStringFromStream(httpRequest.);
> }

Are you sure that request is timing out in the step? I wrote a step to
try the timeout settings and it fails with
"java.util.concurrent.TimeoutException: Timed out after 5000ms":

@Given(value="^...$", timeout=5000)
public void myStep() throws InterruptedException {
Thread.sleep(10000);
}

I believe your step executes in less than a second. Try printing debug
statements with timestamps at the beginning and end of it to see how
long it takes to run.

> On Wednesday, 30 July 2014 00:59:35 UTC-7, Paolo Ambrosio wrote:
>>
>> On Wed, Jul 30, 2014 at 12:30 AM, Maggie Zhou <zhouch...@gmail.com> wrote:
>>
>> > Hi, All,
>> >
>> > I was wondering if there's a way to set timeout for scenarios or steps?
>> > I am
>> > using cucumber-jvm. And I saw there's runtime timeout class
>> >
>> > https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/runtime/Timeout.java
>> >
>> > But I don't know how to use it. Could you please give me an example?
>>
>> Never used it but in Java it should be...
>>
>> @Given(value="your regex here", timeout=3000)
>>
>> You can use it for steps and hooks in the same way. Not sure if there
>> is a way of setting it globally.
>>
>> > my test could be as following, and I 'd like skip the rest steps when
>> > any
>> > step take >3 secs.
>> >
>> > Scenario Outline: Create a account
>> > Given I provide email and password
>> > When I request create account
>> > Then the response is "Created"
>> > Then the response contains expect information
>> >
>> > Thanks a lot
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages