Selenium no such session error in ChromeDriver

Often I am getting no such session error when I am running the scripts from Jenkins. What's the cause for it? Is there any connection failure or is it due to someother reason (I am running around 26 scripts and out of it atleast one script has no such session error)

The scripts are different scripts and no such session error is not again repeated for the same scripts


I met this kind of case sometimes. I use ChromeDriver with Laravel Dusk, rather than Selenium. However, I believe the cause is on ChromeDriver, not Selenium

ChromeDriver will create some cache files in folder: C:Users(yourAccountName)AppDataLocalTemp . In this folder, you will see many cache folders that look like scoped_dir1234_5678 . Each folder occupied around 10mb. If Jenkins runs ChromeDriver much frequently, ChromeDriver can overpopulate the cache file in the temp folder. You should think of 30-50GB cache files on your C drive and make full of your C driver.

When my C drive is out of the space, ChromeDriver will not be able to start, and then return me the error message "FacebookWebDriverExceptionNoSuchDriverException: no such session".

The solution:

  • go to the temp folder, remove all the ChromeDriver Cache folders can clean up C space.
  • create the script which can remove/clean up the Cache folder of ChromeDriver.
  • --UPDATE--

    Find another situation to cause the issue.

    If your run same script to start ChromeDriver in two different instance at same time on same OS, when one instance is finished and shut down the chromedriver, the other chrome browser instance might be closed as well.

    for example you open the two console and excute chromedriver scrpit, or you Jenkins project start in the same time.

    I believe even if you run different script but require chromedriver at same time. one of the script will have "no such session" due to the chrome broswer instance shutdown.

    solution:

  • install the build blocker in jenkins
  • set up project in the build blocker ,which target project need to wait it until it finished.
  • My case is using Laravel Dusk without selenium. I am not sure if it will make different when test go through selenium server


    I ran into this issue with my python selenium end to end test using chromediver_binary and selenium . The error was caused by attempting to run driver.close() multiple times.

    I realized that my methods were being called multiple times, and what I really wanted was the setUpClass and tearDownClass . I'll put my final solution because it avoids this error and works for my purposes nicely.

    class SeleniumTestCase(TestCase):
        """
        A wrapper of TestCase which will launch a selenium server, login, and add
        cookies in the setUp phase of each test.
        """
        @classmethod
        def setUpClass(cls, *args, **kwargs):
            cls.driver = webdriver.Chrome(port=4444)
            cls.driver.implicitly_wait(15)
            cls.driver.maximize_window()
            cls.driver.get(HOST)
            # page obect I wrote which accepts the driver and can login to my app
            cls.login = LoginPage(cls.driver)
            cls.login.log_into_app()
    
        @classmethod
        def tearDownClass(cls):
            cls.driver.close()
    

    which allows me to write test which look like this:

    class TestNavigation(SeleniumTestCase):
    
        def setUp(self):
            # Initialize page objects for each test
            self.module1 = Module1Page(self.driver)
            self.module2 = Module2Page(self.driver)
            # launch page
            self.driver.get(HOST)
    
        def test_module1(self):
            self.module1.nav_link.click()
            self.assertEqual(self.module1.title.text, 'Module One')
    
        def test_module2(self):
            self.module2.nav_link.click()
            self.assertEqual(self.module2.title.text, 'Module Two')
    

    In which the initial login I did in SeleniumTestCase persist through all of my test that I run so I can write test methodsdf to target a single feature as I'm used to doing.

    链接地址: http://www.djcxy.com/p/95818.html

    上一篇: 在DTor之前删除静态对象创建的线程?

    下一篇: Selenium在ChromeDriver中没有这样的会话错误