0

I am working on a test automation framework for school. Everything works great except when I set a driver for a different version of the browser. I am unable to quit it.

Fe. I have Chrome 83 and I tried to run my tests with a driver for Chrome 84. Java gives the following error:

org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 84

I know that you are not allowed to use different versions of Chromedrivers with different of Chrome, but what if somebody did it and wants to replace the driver afterwards?

Apparently, driver = null when the incorrect version is loaded. I can not quit it in the code and it keeps running in the background. Therefore it is not possible to replace or remove the driver in the project. I just want to find a way to programmatically quit the driver whenever the 'SessionNotCreatedException' is thrown instead of force-quitting it in Task Manager.

@BeforeEach
public void beforeSuite() throws MalformedURLException, IOException {           

    String browser = configProperties.getProperty("browser");

    switch(browser.toLowerCase()) {
        case "chrome":
            System.setProperty("webdriver.chrome.driver", configProperties.getProperty("chromepath"));
            driver = new ChromeDriver();
            break;
}

@AfterEach
public void afterSuite() {
    driver.quit();
}
JordyM
  • 1
  • 1
  • Different version of chromedriver is not allowed to use with the different version of chrome browser. First fix that and issue and then if you face any issue then let me know – UnknownBeast Jun 05 '20 at 17:34
  • @UnknownBeast I know that. But w have to make our framework 'as user friendly as possible'. I just want to find a way to quit the driver whenever the version is incorrect. Now I always have to forecequit it in Task Manager before I can replace the driver. – JordyM Jun 05 '20 at 18:24
  • Then handle the NullPointerException and use following code to remove the chromedriver. Runtime.getRuntime().exec("taskkill /IM chromedriver.exe /F"); – UnknownBeast Jun 06 '20 at 02:00
  • @UnknownBeast Thank you! This is exactly what I needed. – JordyM Jun 06 '20 at 07:54
  • Anytime my friend. Keep learning ☺️ – UnknownBeast Jun 06 '20 at 14:24

0 Answers0