Selenium-Webdriver gives unhelpful stacktrace

52 Views Asked by At

I'm using selenium-webdriver + jasmine to write some automation tests, and when I write a bad test the stacktrace given by selenium does not indicate what line of my test (or even which webdriver command) caused the error.

Instead I get a stacktrace full lines like #0 0x55bb8653f303 <unknown>

I've made the following project as a minimal reproduction:

package.json:

{
  "name": "minimal-selenium-reproduction",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "test": "yarn jasmine --config=jasmine.json"
  },
  "devDependencies": {
    "chromedriver": "^121.0.0",
    "jasmine": "^5.1.0",
    "selenium-webdriver": "^4.18.1"
  }
}

jasmine.json:

{
    "spec_dir": ".",
    "spec_files": [
      "**/*.spec.js"
    ],
    "env": {
      "stopSpecOnExpectationFailure": false,
      "random": false
    }
}

test.spec.js (which is intentionally written to have a error):

const { Builder, By } = require("selenium-webdriver");

describe('selenium', function() {
    const driver = new Builder()
        .forBrowser('chrome')
        .build();

    it('should tell where an exception is thrown', async function () {
        await driver.get('https://duckduckgo.com');
        const searchField = await driver.findElement(By.css('#searchbox_input'));
        // leave out the await then navigate to a different page 
        // in order to cause stale element reference
        searchField.sendKeys('how to get better stacktrace from selenium');
        await driver.get('https://wikipedia.org');
        await driver.close();
    })
})

When running yarn test the jasmine reporter gives the following output:

yarn run v1.22.21
$ yarn jasmine --config=jasmine.json
$ /home/walley/repos/minimal-selenium-reproduction/node_modules/.bin/jasmine --config=jasmine.json
Started
F

Failures:
1) selenium should tell where an exception is thrown
  Message:
    Unhandled promise rejection: StaleElementReferenceError: stale element reference: stale element not found
      (Session info: chrome=121.0.6167.139)
  Stack:
    error properties: Object({ remoteStacktrace: '#0 0x55bb8653f303 <unknown>
    #1 0x55bb862242b7 <unknown>
    #2 0x55bb86233c2c <unknown>
    #3 0x55bb8622a3da <unknown>
    #4 0x55bb86228659 <unknown>
    #5 0x55bb8622b8ef <unknown>
    #6 0x55bb8622b99c <unknown>
    #7 0x55bb862708fc <unknown>
    #8 0x55bb862709d3 <unknown>
    #9 0x55bb8626739e <unknown>
    #10 0x55bb86292382 <unknown>
    #11 0x55bb86263f88 <unknown>
    #12 0x55bb8629254e <unknown>
    #13 0x55bb862b107c <unknown>
    #14 0x55bb86292123 <unknown>
    #15 0x55bb86262095 <unknown>
    #16 0x55bb8626309e <unknown>
    #17 0x55bb865036ab <unknown>
    #18 0x55bb865074ba <unknown>
    #19 0x55bb864eff85 <unknown>
    #20 0x55bb8650812f <unknown>
    #21 0x55bb864d3e6f <unknown>
    #22 0x55bb8652c5f8 <unknown>
    #23 0x55bb8652c7c2 <unknown>
    #24 0x55bb8653e4a4 <unknown>
    #25 0x7fdc81733044 <unknown>
    ' })
        at Object.throwDecodedError (/home/walley/repos/minimal-selenium-reproduction/node_modules/selenium-webdriver/lib/error.js:521:15)
        at parseHttpResponse (/home/walley/repos/minimal-selenium-reproduction/node_modules/selenium-webdriver/lib/http.js:510:13)
        at Executor.execute (/home/walley/repos/minimal-selenium-reproduction/node_modules/selenium-webdriver/lib/http.js:443:28)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async thenableWebDriverProxy.execute (/home/walley/repos/minimal-selenium-reproduction/node_modules/selenium-webdriver/lib/webdriver.js:740:17)

1 spec, 1 failure
Finished in 4.323 seconds
error Command failed with exit code 3.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 3.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
1

There are 1 best solutions below

2
Mihajlo Spasic On

I have the same issue. I've found that it's something to do with selenium being updated by to latest version (most likely by apt). If selenium goes to deprecated version it fixes the output in my case. Very strange indeed.