Skip to content

Commit 84fbaaa

Browse files
committed
In Cucumber, if there is an exception in the beforeScenario handler, the afterScenario is not called. Catch the exception in the beforeScenario and free the device in such a case.
Longer version: For each new test that starts running, ATD marks a device "busy" before creating a new driver instance from the beforeScenario. When running a suite of tests, if there is a problem in the driver initialisation resulting in an exception for each test, eventually all devices end up getting marked as "BUSY" in beforeScenario. Once all the devices are "busy", for subsequent tests, there are no available devices, and the thread ends up in suspended state till some device becomes "free". The solution is to catch the exception when creating the driver, and in this case, free the device before re-throwing the exception.
1 parent c1a26f5 commit 84fbaaa

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/main/java/com/cucumber/listener/CucumberScenarioListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ private AppiumDevice allocateDeviceAndStartDriver(String testMethodName) {
6666
}
6767
return updateAvailableDeviceInformation(availableDevice);
6868
} catch (Exception e) {
69+
LOGGER.error(String.format("Error creating / allocating a driver for test: '%s'%n%s",
70+
testMethodName, e));
6971
e.printStackTrace();
72+
LOGGER.info("Releasing the device that was allocated");
73+
deviceAllocationManager.freeDevice();
7074
throw new RuntimeException(e);
7175
}
7276
}

0 commit comments

Comments
 (0)