webdriver.io afterscenario close browser now working

2.7k Views Asked by At

Using webdriverIO and I am trying to close / quit chrome browser between scenarios. Here is what I have in the conf file:

  afterScenario: function (scenario) {
        console.log("afterScenario quit browser");
        browser.Close();
        ;
    },

Is there a way to close browser or chromedriver after each scenario with wdio?

Thanks

2

There are 2 best solutions below

0
iamdanchiv On BEST ANSWER

Each WebdriverIO process opens a new session (browser.sessionId). Thus, the reload() function is what you are probably looking for.

afterScenario: function (scenario) {
  console.log("After scenario, reload session!");
  browser.reload();
},

!Note: For people running the newer wdio-v5 version, the corresponding API command is reloadSession.

0
Naveen Thiyagarajan On

We have did the other way around. Restarting new browser/chrome session as part scenario whenever required using the below command:

const status = browser.status();
if(status.value.ready){
        browser.reload();
}

And also just to add. browser.close() is used as part of windowHandles. browser.end() is the one which can be used for closing a browser but unfortunately it is supported only on standalone mode.