0

I am usung qaf bdd2 framework for test automation. I have a requirement where I need to run the test cases in specific port so I have implemented below as qaf listeners

options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");

Now the issue is when I run any multiple scenerios I expect the browser to open at beginning of scenerio and close at end of scenerio and it should continue the same way while running other scenerios. After implementing to run chrome in specific port the browser opens but not closing at all. When new scenerio runs, the browser opening a new tab and running the test which I don't want to run in same tab. When test completed the browser is not closing automatically I need to close it manually.

Question: how to implement driver.quit() and where in qaf I need to apply to close browser for every scenerio?

Satish A
  • 83
  • 6

2 Answers2

1

You can use selenium.singletone framework property to set driver tear down behavior. To close browser for every scenario you need to set it methods

selenium.singletone=methods

EDIT:

If driver Quit doesn't kill's browser and you need to forcefully kill browser, you can have driver after command listener. For example,

public class KillDriverListener extends QAFListenerAdapter {

    @Override
    public void afterCommand(QAFExtendedWebDriver driver, CommandTracker commandTracker) {
        if (DriverCommand.QUIT.equalsIgnoreCase(commandTracker.getCommand())) {
            //kill driver
        }
    }
}

register listener when required using qaf.listeners property.

user861594
  • 5,733
  • 3
  • 29
  • 45
  • I have put this selenium.singleton=methods in application.properties file. Despite that I have issue mention in my original query. – Satish A Oct 07 '21 at 03:51
1

I found the answer. I forcing the chrome driver by using taskkill and calling it on finish using ItestListeners.

Code: taskkill /f /im chromedriver.exe

Satish A
  • 83
  • 6
  • if above works and you want to call it on driver's quite method, you can have driver after command [listener](https://qmetry.github.io/qaf/latest/qaf_listeners.html#webdriver-listener). For example, ` @Override public void afterCommand(QAFExtendedWebDriver driver, CommandTracker commandTracker) { if (DriverCommand.QUIT.equalsIgnoreCase(commandTracker.getCommand())) { //kill browser } } ` – user861594 Oct 08 '21 at 15:47
  • Got it... I will try this as well. Thanks – Satish A Oct 09 '21 at 04:34