Chromedriver closing after test

别来无恙 提交于 2020-05-15 08:37:09

问题


So my understanding is that calling driver.quit or close is the the proper way to close the driver and associated window.

However when running my tests, it seems that even without calling driver.quit and instead calling pass, that the window still closes.

I'm using python with unittest test cases excuted via pytest. I've also run standard unitests via Pycharm. In all scenarios, the browser closes as described. I want the browser to stay open to where I can debug tests. I could just call sleep(9000) but that seems dumb.

Furthermore, the browser stays open when commenting out quit on some machines, but not on others with the same chromedriver, Chrome version, and code.

Analyzing the chromedriver logs, it seems it registers a QuitAll command, but I have no idea where it could be getting it from. Could the pyc file not be overwritten?

Code for quit:

def tearDown(self):
    pass
    # self.driver.quit()

回答1:


The service will stop once your script ends due to the code here.

If you want chrome and chromedriver to stay open afterward, you can add the detach option when starting chromedriver:

from selenium.webdriver import ChromeOptions, Chrome
opts = ChromeOptions()
opts.add_experimental_option("detach", True)
driver = Chrome(chrome_options=opts)


来源:https://stackoverflow.com/questions/43612340/chromedriver-closing-after-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!