Selenium在ChromeDriver中没有此类会话错误

时间:2023-01-22 18:25:49

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)

当我从Jenkins运行脚本时,我经常没有遇到这样的会话错误。它的原因是什么?是否有任何连接失败或是由于其他原因(我运行了大约26个脚本,并且至少有一个脚本没有这样的会话错误)

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

脚本是不同的脚本,并且对于相同的脚本不会再次重复此类会话错误

3 个解决方案

#1


7  

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和Laravel Dusk,而不是Selenium。但是,我认为原因在于ChromeDriver,而不是Selenium

ChromeDriver will create some cache files in folder:C:\Users\(yourAccountName)\AppData\Local\Temp. 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.

ChromeDriver将在文件夹中创建一些缓存文件:C:\ Users \(yourAccountName)\ AppData \ Local \ Temp。在此文件夹中,您将看到许多类似于scoped_dir1234_5678的缓存文件夹。每个文件夹大约占用10mb。如果Jenkins经常运行ChromeDriver,ChromeDriver可能会超过temp文件夹中的缓存文件。您应该考虑C驱动器上的30-50GB缓存文件,并充分利用您的C驱动程序。

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

当我的C盘空间不足时,ChromeDriver将无法启动,然后向我返回错误消息“Facebook \ WebDriver \ Exception \ NoSuchDriverException:no such session”。

The solution:

解决方案:

  1. Go to the temp folder, remove all the ChromeDriver cache folders can clean up C space.
  2. 转到temp文件夹,删除所有ChromeDriver缓存文件夹即可清理C空间。
  3. Create the script which can remove/clean up the cache folder of ChromeDriver.
  4. 创建可以删除/清除ChromeDriver缓存文件夹的脚本。

--UPDATE--

--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.

如果您运行相同的脚本以在同一操作系统上同时在两个不同的实例中启动ChromeDriver,则当一个实例完成并关闭chromedriver时,另一个Chrome浏览器实例也可能会关闭。

For example you open the two console and execute chromeDriver script, or your Jenkins project start at the same time.

例如,您打开两个控制台并执行chromeDriver脚本,或者您的Jenkins项目同时启动。

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 browser instance shutdown.

我相信即使您运行不同的脚本但同时需要chromeDriver,由于Chrome浏览器实例关闭,其中一个脚本将“没有此类会话”。

solution:

解:

  1. Install the build blocker in jenkins
  2. 在jenkins中安装构建阻止程序
  3. Set up project in the build blocker, which target project need to wait it until it finished.
  4. 在构建阻止程序中设置项目,目标项目需要等待它直到完成。

My case is using Laravel Dusk without selenium. I am not sure if it will make different when test go through selenium server

我的案例是使用没有硒的Laravel Dusk。当测试通过selenium服务器时,我不确定它是否会有所不同

#2


0  

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.

我使用chromediver_binary和selenium在我的python selenium端到端测试中遇到了这个问题。该错误是由于尝试多次运行driver.close()引起的。

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.

我意识到我的方法被多次调用,我真正想要的是setUpClass和tearDownClass。我会提出我的最终解决方案,因为它避免了这个错误并且很好地适用于我的目的。

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.

我在SeleniumTestCase中进行的初始登录持续通过我运行的所有测试,因此我可以编写测试方法以定位单个功能,就像我以前一样。

#3


0  

In my case it was driver.quit() being called in the wrong location.

在我的情况下,它是在错误的位置调用driver.quit()。

#1


7  

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和Laravel Dusk,而不是Selenium。但是,我认为原因在于ChromeDriver,而不是Selenium

ChromeDriver will create some cache files in folder:C:\Users\(yourAccountName)\AppData\Local\Temp. 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.

ChromeDriver将在文件夹中创建一些缓存文件:C:\ Users \(yourAccountName)\ AppData \ Local \ Temp。在此文件夹中,您将看到许多类似于scoped_dir1234_5678的缓存文件夹。每个文件夹大约占用10mb。如果Jenkins经常运行ChromeDriver,ChromeDriver可能会超过temp文件夹中的缓存文件。您应该考虑C驱动器上的30-50GB缓存文件,并充分利用您的C驱动程序。

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

当我的C盘空间不足时,ChromeDriver将无法启动,然后向我返回错误消息“Facebook \ WebDriver \ Exception \ NoSuchDriverException:no such session”。

The solution:

解决方案:

  1. Go to the temp folder, remove all the ChromeDriver cache folders can clean up C space.
  2. 转到temp文件夹,删除所有ChromeDriver缓存文件夹即可清理C空间。
  3. Create the script which can remove/clean up the cache folder of ChromeDriver.
  4. 创建可以删除/清除ChromeDriver缓存文件夹的脚本。

--UPDATE--

--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.

如果您运行相同的脚本以在同一操作系统上同时在两个不同的实例中启动ChromeDriver,则当一个实例完成并关闭chromedriver时,另一个Chrome浏览器实例也可能会关闭。

For example you open the two console and execute chromeDriver script, or your Jenkins project start at the same time.

例如,您打开两个控制台并执行chromeDriver脚本,或者您的Jenkins项目同时启动。

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 browser instance shutdown.

我相信即使您运行不同的脚本但同时需要chromeDriver,由于Chrome浏览器实例关闭,其中一个脚本将“没有此类会话”。

solution:

解:

  1. Install the build blocker in jenkins
  2. 在jenkins中安装构建阻止程序
  3. Set up project in the build blocker, which target project need to wait it until it finished.
  4. 在构建阻止程序中设置项目,目标项目需要等待它直到完成。

My case is using Laravel Dusk without selenium. I am not sure if it will make different when test go through selenium server

我的案例是使用没有硒的Laravel Dusk。当测试通过selenium服务器时,我不确定它是否会有所不同

#2


0  

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.

我使用chromediver_binary和selenium在我的python selenium端到端测试中遇到了这个问题。该错误是由于尝试多次运行driver.close()引起的。

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.

我意识到我的方法被多次调用,我真正想要的是setUpClass和tearDownClass。我会提出我的最终解决方案,因为它避免了这个错误并且很好地适用于我的目的。

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.

我在SeleniumTestCase中进行的初始登录持续通过我运行的所有测试,因此我可以编写测试方法以定位单个功能,就像我以前一样。

#3


0  

In my case it was driver.quit() being called in the wrong location.

在我的情况下,它是在错误的位置调用driver.quit()。