redhat-developer / vscode-extension-tester

ExTester: Your Essential UI Testing Companion for Visual Studio Code Extensions! Seamlessly execute UI tests with Selenium WebDriver, ensuring robustness and reliability in your extension development journey. Simplify UI testing for your VS Code extensions and elevate the quality of your user interface effortlessly.
Apache License 2.0
258 stars 70 forks source link

[🚫 Bug] Getting StaleElementReferenceError for WebviewView #1255

Closed mirth closed 5 months ago

mirth commented 5 months ago

Describe the bug

The bug appears when trying to use WebviewView to access bottom panel elements.

Getting StaleElementReferenceError: stale element reference: stale element not found

Steps to reproduce

Repo to reproduce the bug:
https://github.com/mirth/StaleElementReferenceError-reproduce

The test:

await new Workbench().executeCommand('Calico Colors: Focus on Tests View View');

const webviewView = new WebviewView();
await webviewView.switchToFrame();
const runTest = await webviewView.findElement(By.css('vscode-button'));
const buttonName = await runTest.getText();
console.log('buttonName: ', buttonName);

Running the tests: ./node_modules/.bin/extest setup-and-run --mocha_config .mocharc.js setup-and-run out/e2e/simple.test.js


### Logs

```Shell
Downloading VS Code: 1.88.1 / stable
VS Code exists in local cache, skipping download
ChromeDriver 120.0.6099.109 exists in local cache, skipping download
Executing prepublish script 'npm run vscode:prepublish'...

> calico-colors@0.0.1 vscode:prepublish
> npm run compile

> calico-colors@0.0.1 compile
> tsc -p ./

 WARNING  LICENSE, LICENSE.md, or LICENSE.txt not found
Do you want to continue? [y/N] y
 DONE  Packaged: /webview-view-sample/calico-colors-0.0.1.vsix (25 files, 28.25KB)
Installing extensions...
Extension 'calico-colors-0.0.1.vsix' was successfully installed.
Loading mocha configuration from .mocharc.js

Writing code settings to /var/folders/_r/XXXXXXXXXX/T/test-resources/settings/User/settings.json
Launching browser...
Browser ready in 4314 ms
Launching tests...
  My Test Suite
    1) My Test Case

Shutting down the browser

  0 passing (8s)
  1 failing

  1) My Test Suite
       My Test Case:
     StaleElementReferenceError: stale element reference: stale element not found
  (Session info: chrome=120.0.6099.291)
      at Object.throwDecodedError (node_modules/selenium-webdriver/lib/error.js:521:15)
      at parseHttpResponse (node_modules/selenium-webdriver/lib/http.js:513:13)
      at Executor.execute (node_modules/selenium-webdriver/lib/http.js:446:28)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Driver.execute (node_modules/selenium-webdriver/lib/webdriver.js:740:17)
      at async Context.<anonymous> (out/e2e/simple.test.js:19:25)

Operating System

macOS 14.4.1

Visual Studio Code

1.88.1

vscode-extension-tester

8.0.2

NodeJS

18.16.0

npm

9.5.1

djelinek commented 5 months ago

Hello @mirth thank you for reporting your issue! 👍🏻

I was able to reproduce locally. You need to do a little modification of your test and hopefully you should be able to proceed 🙂

Just need to change 2 lines of yours code to this:

await webviewView.switchToFrame(1000);
const runTest = await webviewView.findWebElement(By.css('button'));
mirth commented 5 months ago

Thanks, it worked!