19

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Shan
  • 2,822
  • 9
  • 40
  • 61
  • Can you complete your question with more info? What browser and Selenium version are you using? Are you running against a Selenium Grid? If so, how many nodes do you have set on it? – Tom Apr 02 '17 at 14:06
  • I am using Chrome and ChromeDriver with latest selenium version but still the issue exists – Shan Apr 06 '17 at 05:48
  • You can check a long discussion [at Chromium](https://bugs.chromium.org/p/chromedriver/issues/detail?id=732) about it. I'm still having a headache with this too. I'm using Selenium3 with Docker images and could not have a stable behaviour for it. – Tom Apr 06 '17 at 05:57
  • I did check but I don't think it's a memory issue as I am running these on 16GB machine – Shan Apr 07 '17 at 08:01
  • As I said before, your question is poor in details. If running Selenium Grid with Docker (you just said you're running from Jenkins, but this info is not provided in your question or comments), as stated on [Selenium Github page](https://github.com/SeleniumHQ/docker-selenium), you should use `-v /dev/shm:/dev/shm` to run the container (or should do this in a `docker-compose` file setting some size). Anyway, this can be still an intermittent bug as said in Chromium (previous comment). – Tom Apr 07 '17 at 08:17
  • I said it in Question description..I run the testcases on my Jenkins nodes and not sure why this occurs now and then.I am not sure about Docker, need to learn about it and try running inside in it.. – Shan Apr 07 '17 at 09:15

5 Answers5

10

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

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

The solution:

  1. Go to the temp folder, remove all the ChromeDriver cache folders can clean up C space.
  2. 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 execute chromeDriver script, or your Jenkins project start at 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 browser instance shutdown.

solution:

  1. Install the build blocker in jenkins
  2. 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

caoglish
  • 1,343
  • 3
  • 19
  • 29
  • You are right! Don't close the chrome instance before you run every test case. Just close it only in after block so that, every test case use the same chrome instance without any errors. – Balasubramani M Jun 28 '18 at 12:30
  • Something similar to this worked for me too, but on Mac you'll need to find the temp folder with `open $TMPDIR` (https://apple.stackexchange.com/questions/94964/where-is-the-temp-folder). I then found that VS Code had made a huge typescript folder. Once I clean that out my Spectron tests ran again. – cham Dec 09 '18 at 22:49
4

While using this error message on platform...

WebDriverError: no such session
  (Driver info: chromedriver=a.b.c (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.11.5 x86_64)

Or

This error message on platform...

WebDriverError: no such session
    (Driver info: chromedriver=p.q.r,platform=Linux 3.2.0-4-amd64 x86_64) (Selenium::WebDriver::Error::NoSuchDriverError)

Or

This error message on platform...

WebDriverError: no such session 
(Driver info: chromedriver=x.y.z (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Windows NT 6.1 SP1 x86_64) (NoSuchDriver)

...implies that the ChromeDriver was unable to communicate with the existing Browsing Context i.e. Chrome Browser session.


We have discussed this issue in details within the discussion Issue 732: No such session error - inconsistent problem which appears when running tests for a prolonged period. This error is usually observed after an extended period of executing the Test Suite as follows:

[489.798][DEBUG]: DEVTOOLS EVENT Inspector.targetCrashed {

}
[489.798][INFO]: Waiting for pending navigations...
[489.798][INFO]: Done waiting for pending navigations
[0127/105308:ERROR:nacl_helper_linux.cc(289)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly
[489.849][INFO]: RESPONSE FindElements unknown error: session deleted because of page crash
from tab crashed
  (Session info: chrome=p.q.r.s)
[489.849][DEBUG]: Log type 'driver' lost 0 entries on destruction
[489.849][DEBUG]: Log type 'browser' lost 9 entries on destruction

This error is defined in nacl_helper_linux.cc as follows:

// If the Zygote has started handling requests, we should be sandboxed via
// the setuid sandbox.
if (!IsSandboxed()) {
  LOG(ERROR) << "NaCl helper process running without a sandbox!\n"
    << "Most likely you need to configure your SUID sandbox "
    << "correctly";

Precisely the FindElement(s) method have FAILED due to sandbox issue and Page Crash occured due to session deletion


Solution

This error can happen due to a lot of diverse reasons and the solution to address this error are as follows:

  • Initiate the Chrome session configuring ChromeDriver with the argument --disable-impl-side-painting
    • Additionally, you can also add the argument --enable-gpu-rasterization which allow heuristics to determine when a layer tile should be drawn with the Skia GPU backend. Only valid with GPU accelerated compositing + impl-side painting.
    • As an option, you can also add the argument --force-gpu-rasterization which always uses the Skia GPU backend for drawing layer tiles. Only valid with GPU accelerated compositing + impl-side painting. Overrides the kEnableGpuRasterization flag.
  • This error is also observed when the server does not recognize the unique session identifier. This happens if the session has been deleted or if the session ID is invalid in either of the following ways:

    • Explicit session deletion: A WebDriver session is explicitly deleted when explicitly invoking the quit() method as follows:

      from selenium import webdriver
      from selenium.common.exceptions import InvalidSessionIdException
      
      driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
      print("Current session is {}".format(driver.session_id))
      driver.quit()
      try:
          driver.get("https://www.google.com/")
      except Exception as e:
          print(e.message)
      
      #Console Output:
      Current session is a9272550-c4e5-450f-883d-553d337eed48
      No active session with ID a9272550-c4e5-450f-883d-553d337eed48
      
    • Implicit session deletion: A WebDriver session is implicitly deleted when you close the last window or tab invoking close() method as follows:

      driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
      print("Current session is {}".format(driver.session_id))
      # closes current window/tab
      driver.close()
      try:
          driver.get("https://www.google.com/")
      except Exception as e:
          print(e.message)
      
      #Console Output:
      Current session is a9272550-c4e5-450f-883d-553d337eed48
      No active session with ID a9272550-c4e5-450f-883d-553d337eed48
      
  • You may also have to add the argument --no-sandbox

  • Chrome seem to crash often in Docker containers on certain pages due to too small /dev/shm. Similarly, you may have to fix the small /dev/shm size.
  • An example:

    sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm
    
  • It also works if you use -v /dev/shm:/dev/shm option to share host /dev/shm

  • Another way to make it work would be to add the chrome_options as --disable-dev-shm-usage. This will force Chrome to use the /tmp directory instead. This may slow down the execution though since disk will be used instead of memory.

    chrome_options.add_argument('--disable-dev-shm-usage')        
    

from tab crashed

from tab crashed was WIP(Work In Progress) with the Chromium Team for quite some time now which relates to Linux attempting to always use /dev/shm for non-executable memory. Here are the references :


Reference

You can find a couple of detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
3

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

David J
  • 1,018
  • 1
  • 9
  • 14
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.

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.

Nick Brady
  • 6,084
  • 1
  • 46
  • 71
0

nosuchsessionException Check your code might be you are calling Driver.close(); or Driver.quit(); twice or both.

Solution : Remove one.

Ravi Makwana
  • 2,782
  • 1
  • 29
  • 41