Closed AllanOricil closed 1 year ago
This also does not work
// import the webdriver and the high level browser wrapper
import { VSBrowser, WebDriver, Workbench, BottomBarPanel, TerminalView } from 'vscode-extension-tester';
// Create a Mocha suite
describe('My Test Suite', () => {
let driver: WebDriver
// initialize the browser and webdriver
before(async () => {
driver = VSBrowser.instance.driver;
});
// test whatever we want using webdriver, here we are just checking the page title
it('My Test Case', async () => {
try{
const bottomBarPanel : BottomBarPanel = new BottomBarPanel();
const terminalView : TerminalView = await bottomBarPanel.openTerminalView()
}catch(e){
console.log(e);
}
});
});
From the logs, I can see the test actually failed with a timeout
1) My Test Suite
My Test Case:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\allan_000\workspace\soe2\out\test\query-editor-spec.js) at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
Mocha test cases by default have a 2 second hard timeout. That's hardly enough for most UI tests, so you can set it to whatever you like:
it('test case', () => {
// test block
}).timeout(timeoutInMilliseconds)
As for the NoSuchSessionError
, there is a forced shutdown after all tests are complete. The error happens if there still is an unresolved promise in the webdriver queue at that time. Usually it means some asynchronous task leaked from a test case unawaited.
There might be a way to purge the queue before shutdown, which would keep the error from appearing again. Some might say the error has some debug value, though.
BTW the first test case doesn't actually do much, because you need to return promises in order to chain them. As for the second attempt, I have no idea what could have gone wrong.
@jrichter1 When I used the async/await approach it threw the same error.
When the test starts I can see the terminal is opened, but when the test reaches this line terminalView.executeCommand("ls")
, terminalView is undefined somehow and I also get that exception. I can't understand if Im doing something wrong or it is a bug because the doc does not have a proper example :/
If you or someone else could help me I would appreciate :)
The async/await code looks like it shouldn't run into any problems, it runs completely fine when I'm trying it.
Given you are experiencing the same error as in the previous attempt, make sure you re-compile the .ts test files into .js every time you change and run them.
As far as the then chain is concerned, you can only chain promises. And if you don't return anything from the then callbacks, it can't chain on void type. So your code basically calls the first promise, and then doesn't wait for the callbacks to chain. Mocha also implicitly only waits for promises that are either awaited, or returned. In the end, a couple of return statements should make it work.
it('My Test Case', async () => {
return new BottomBarPanel().openTerminalView()
.then((terminalView) => {
return terminalView.getChannelNames().then((names) => {
return terminalView.executeCommand("ls")
.then(() => {
return new Workbench().executeCommand('SFDX: Open Salesforce Query Editor')
.then(() => {
console.log('hi');
})
})
.catch((e) => {
console.log(e);
})
})
})
.catch((e) => {
console.error(e);
})
});
Oh I see. I have not tried to add a return there. Thanks @jrichter1. I will try and later come back with the results
Im trying to execute the following test and I can't get a TerminalView to work. The terminal opens, but for some reason the Promise never resolves to a terminalView. It is always going into the catch.
this is the output I receive, when I launch the test with a debugger attached