I have a feature file which has many scenarios. When I run, every time it's initializing the new browser.It's performing every scenario in the new browser.

I am using @before and @after


    public void statUp() throws IOException {
        KnowsTestContext.driver = utils.getDriver(reader.properties().getProperty("browser"));


   public void tearDown(Scenario scenario) {

Is there any way to run all my scenarios on one browser?

3 Answers 3


You need to rework your utils.getDriver to make it producing a Singleton. You also should not invoke quit() method since it "destroys" the webdriver.


There would be lot of development activity required to achieve this and I would not recommend this way of designing your test harness.

However to give a glimpse of how it can be achieved,

  • First you need to understand the internal architecture of webdriver and how it implements the json wire protocol.
  • In short, each command like webelement.click() is mapped to some REST endpoint like /session/{sessionID}/element/{elementID}/click with a http POST.
  • The session id is the critical part here which tells webdriver to perform action on which browser instance.
  • So, in order to make use of the existing webdriver instance for the further runs, you have to store the sessionID and then pass that to the REST endpoint to perform that action.

I hope this made things clear.


You can check condition like, open browser only if driver is null, else use existing one.

@Before public void setup() {
    if (driver == null) {
       KnowsTestContext.driver = utils.getDriver(reader.properties().getProperty("browser"));

Refer this post for more- https://stackoverflow.com/questions/40720548/how-to-use-hooks-in-cucumber

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.