3

I just installed the latest version of Selenium Runner

npm install -g selenium-side-runner

on my Mac High Sierra. I'm running node v14.1.0. I'm using Chrome Driver v 83. I want to run a very simple file that simply opens a page, waiting for an element on that page to be present. However, I'm getting a "NoSuchSessionError: This driver instance does not have a valid session ID" error.

The Selenium Runner .side file in question is

$ cat selenium/KarmaDecayGetResults.side
{
  "id": "9664bd47-b18f-405f-9bd3-06014919ca7e",
  "version": "2.0",
  "name": "KarmaDecay",
  "url": "http://karmadecay.com",
  "tests": [
    {
      "id": "8f462171-01b8-4247-87b9-40e2d1fef143",
      "name": "KarmaDecay",
      "commands": [
        {
          "id": "c297319b-4350-4f04-b72e-1a347a67100c",
          "comment": "",
          "command": "open",
          "target": "/r/gifs/comments/gz5v5j/caracal_visits_jimmy_kimmel_gets_shy_and_tries_to/",
          "targets": [],
          "value": ""
        },
        {
          "id": "32f35ed7-1a28-4540-a93d-3cb8ba0e012a",
          "comment": "",
          "command": "pause",
          "target": "",
          "targets": [],
          "value": "2000"
        },
        {
          "id": "95261633-22ff-4477-ab6f-7b3354bea8b9",
          "comment": "",
          "command": "setWindowSize",
          "target": "1440x900",
          "targets": [],
          "value": ""
        },
        {
          "id": "fbf35ed7-1a28-4540-a93d-3cb8ba0e012a",
          "comment": "",
          "command": "waitForElementPresent",
          "target": "id=content",
          "targets": [],
          "value": ""
        },
        {
          "id": "aed35ed7-1a28-4540-a93d-3cb8ba0e012a",
          "comment": "",
          "command": "waitForElementVisible",
          "target": "id=content",
          "targets": [],
          "value": ""
        },
        {
          "id": "fbf59ed7-1a28-4540-a93d-3cb8ba0e012a",
          "comment": "",
          "command": "pause",
          "target": "",
          "targets": [],
          "value": "2000"
        }
      ]
    }
  ],
  "suites": [
    {
      "id": "91809d77-24c1-457b-8266-516b2fc58555",
      "name": "Default Suite",
      "persistSession": false,
      "parallel": false,
      "timeout": 300,
      "tests": [
        "8f462171-01b8-4247-87b9-40e2d1fef143"
      ]
    }
  ],
  "urls": [
    "http://karmadecay.com/"
  ],
  "plugins": []
}

Below is the output of running the file ...

$ PATH=/Users/davea/Documents/workspace/article_project/selenium/dev:/usr/local/bin:$PATH /usr/local/bin/selenium-side-runner -c "goog:chromeOptions.args=[--headless,--nogpu] browserName=chrome" selenium/KarmaDecayGetResults.side

 FAIL  ./DefaultSuite.test.js (301.959s)
  Default Suite
    ✕ KarmaDecay (300540ms)

  ● Default Suite › KarmaDecay

    : Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Error:

       8 | jest.setTimeout(300000);
       9 | describe("Default Suite", () => {
    > 10 |   it("KarmaDecay", async () => {
         |   ^
      11 |     await tests["KarmaDecay"](driver, vars);
      12 |     expect(true).toBeTruthy();
      13 |   });

      at new Spec (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Suite.<anonymous> (DefaultSuite.test.js:10:3)

  ● Default Suite › KarmaDecay

    NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.

      at ../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/webdriver.js:729:38
      at Object.thenFinally [as finally] (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/promise.js:124:12)
          at runMicrotasks (<anonymous>)
      at WebdriverEnvironment.global.cleanup (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/jest-environment-selenium/dist/index.js:30:7)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        302.159s
Ran all test suites.

Do I need to be doing something different to get my test to run cleanly?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Dave
  • 15,639
  • 133
  • 442
  • 830

1 Answers1

3

invalid session id

The invalid session ID error is a WebDriver error that occurs 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.

A WebDriver session can be deleted through either of the following ways:

You can find a detailed discussion in selenium.common.exceptions.WebDriverException: Message: invalid session id using Selenium with ChromeDriver and Chrome through Python


This usecase

I don't see any such error within your code block. However your main error seems to be...

Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 300000ms timeout specified by jest.setTimeout.Error:

...which implies that the Async callback being referred to in the error is getting timedout even with timeout set as 300000:

jest.setTimeout(300000);

The real issue is with the url of KarmaDecay which contains a hCaptcha to keep off automated bots.

  • URL Snapshot:

hCaptcha_Karmadecay


Conclusion

As per your test setup to execute the selenium-side-runner within the website http://karmadecay.com/ first you have to interact with the to get authenticated and then run your tests.

You can find a couple of relevant discussions on how to interact with in:


Another aspect

If the initial tests works fine but for the rest of your tests you get a session ID error most possibly the Selenium WebDriver controled Browsing Context is getting detected and hence blocking the next requests.

There are different reasons for the WebDriver controled Web Browser to get detected and simultaneously get blocked. You can find a couple of detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thanks, but I'm not clear reading through these what actions I need to take to get everything to work. In as far as SO discourages links because they get broken over time, could you include the steps I would need to make my script run successfully? – Dave Jun 22 '20 at 02:05
  • @Dave Checkout the updated answer with a _Conclusion_ section. All of the links referred within the _Conclusion_ section involves steps in details on how to interact with captcha / recaptcha. let me know if you need further help. – undetected Selenium Jun 22 '20 at 09:17