2

I am using a Selenium-Cucumber-Java framework for automation. I need to restrict the run duration of my scenarios in such a way that max 30 mins should be taken for any scenario and fail the scenario if it takes more time than that.

I found this answer in SO which helps in giving a timeout for a step. Cucumber Stopping Execution after Time in Steps

But I don't want to change all my existing steps to include this time out. Is there a way to provide a default time out for all my steps? Or Is there a way to configure the timeout at a scenario level?

SP.
  • 85
  • 3
  • 13

2 Answers2

2

You're trying to combine two different things. Terminating the test after 30 minutes and failing the test if the duration of the test is 30 minutes or longer. The former is impossible to achieve, the latter is easy to do with @Before and @After hooks.

You set the start time in the before hook, and check the total duration in the after hook. Then throw an exception if it took too long.

MikeJRamsey56
  • 2,779
  • 1
  • 20
  • 34
M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
1

I added this in my E2EWorld.

import { setDefaultTimeout } from 'cucumber';


const DEFAULT_TIMEOUT = 10000;


setDefaultTimeout(DEFAULT_TIMEOUT);
Francis Robitaille
  • 575
  • 1
  • 5
  • 18