Gathering detailed insights and metrics for wdio-vscode-service
Gathering detailed insights and metrics for wdio-vscode-service
Gathering detailed insights and metrics for wdio-vscode-service
Gathering detailed insights and metrics for wdio-vscode-service
wdio-chromedriver-service
WebdriverIO service to start & stop ChromeDriver
@wdio/local-runner
A WebdriverIO runner to run tests locally
@wdio/utils
A WDIO helper utility to provide several utility functions used across the project.
wdio-intercept-service
Capture and assert HTTP ajax calls in webdriver.io 🕸
A service to test VSCode extensions from end to end using WebdriverIO
npm install wdio-vscode-service
60.9
Supply Chain
89.2
Quality
77.7
Maintenance
50
Vulnerability
95.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
37 Stars
228 Commits
28 Forks
11 Watching
4 Branches
26 Contributors
Updated on 20 Nov 2024
TypeScript (98.85%)
JavaScript (1.12%)
Shell (0.02%)
Cumulative downloads
Total Downloads
Last day
15.1%
1,712
Compared to previous day
Last week
-1.6%
7,399
Compared to previous week
Last month
11.9%
30,833
Compared to previous month
Last year
142.3%
390,437
Compared to previous year
17
1
29
Tested on:
WebdriverIO service for testing VSCode extensions.
This WebdriverIO service allows you to seamlessly test your VSCode extensions from end to end in the VSCode Desktop IDE or as a web extension. You only need to provide a path to your extension and the service does the rest by:
stable
, insiders
or a specified version)This project was highly inspired by the vscode-extension-tester project which is based on Selenium. This package takes the idea and adapts it to WebdriverIO.
Starting from VSCode v1.86 it is required to use webdriverio
v8.14 or later to install Chromedriver with no configuration necessary. If you need to test earlier versions of VSCode, see the Chromedriver configuration section below.
To initiate a new WebdriverIO project, run:
1npm create wdio ./
An installation wizard will guide you through the process. Ensure you select TypeScript as compiler and don't have it generate page objects for you given this project comes with all page objects needed. Then make sure to select vscode
within the list of services:
For more information on how to install WebdriverIO
, please check the project docs.
To use the service you need to add vscode
to your list of services, optionally followed by a configuration object. This will make WebdriverIO download given VSCode binaries and appropriate Chromedriver version:
1// wdio.conf.ts 2export const config = { 3 outputDir: 'trace', 4 // ... 5 capabilities: [{ 6 browserName: 'vscode', 7 browserVersion: '1.86.0', // "insiders" or "stable" for latest VSCode version 8 'wdio:vscodeOptions': { 9 extensionPath: __dirname, 10 userSettings: { 11 "editor.fontSize": 14 12 } 13 } 14 }], 15 services: ['vscode'], 16 /** 17 * Optionally define the path WebdriverIO stores all VSCode binaries, e.g.: 18 * services: [['vscode', { cachePath: __dirname }]] 19 */ 20 // ... 21};
If you define wdio:vscodeOptions
with any other browserName
but vscode
, e.g. chrome
, the service will serve the extension as a web extension. If you test on Chrome no additional driver service is required, e.g.:
1// wdio.conf.ts 2export const config = { 3 outputDir: 'trace', 4 // ... 5 capabilities: [{ 6 browserName: 'chrome', 7 'wdio:vscodeOptions': { 8 extensionPath: __dirname 9 } 10 }], 11 services: ['vscode'], 12 // ... 13};
Note: when testing web extensions you can only choose between stable
or insiders
as browserVersion
.
In your tsconfig.json
make sure to add wdio-vscode-service
to your list of types:
1{ 2 "compilerOptions": { 3 "types": [ 4 "node", 5 "webdriverio/async", 6 "@wdio/mocha-framework", 7 "expect-webdriverio", 8 "wdio-vscode-service" 9 ], 10 "target": "es2019", 11 "moduleResolution": "node", 12 "esModuleInterop": true 13 } 14}
You can then use the getWorkbench
method to access the page objects for the locators matching your desired VSCode version:
1describe('WDIO VSCode Service', () => { 2 it('should be able to load VSCode', async () => { 3 const workbench = await browser.getWorkbench() 4 expect(await workbench.getTitleBar().getTitle()) 5 .toBe('[Extension Development Host] - README.md - wdio-vscode-service - Visual Studio Code') 6 }) 7})
If you like to execute certain automation through the VSCode API you can do that by running remote commands via the custom executeWorkbench
command. This command allows you to remotely execute code from your test inside the VSCode environment and enables you to access the VSCode API. You can pass arbitrary parameters into the function which will then be propagated into the function. The vscode
object will be always passed in as the first argument following the outer function parameters. Note that you can not access variables outside of the function scope as the callback is executed remotely. Here is an example:
1const workbench = await browser.getWorkbench() 2await browser.executeWorkbench((vscode, param1, param2) => { 3 vscode.window.showInformationMessage(`I am an ${param1} ${param2}!`) 4}, 'API', 'call') 5 6const notifs = await workbench.getNotifications() 7console.log(await notifs[0].getMessage()) // outputs: "I am an API call!"
For the full page object documentation, check out the docs. You can find various usage examples in this project's test suite.
Through service configuration, you can manage the VSCode version as well as user settings for VSCode:
Service options are options needed for the service to set up the test environment.
cachePath
Define a cache path to avoid re-downloading VS Code bundles. This is useful for CI/CD to avoid re-downloading VSCode for every test run.
Type: string
Default: process.cwd()
wdio:vscodeOptions
)In order to run tests through VSCode you have to define vscode
as browserName
. You can specify the VSCode version by providing a browserVersion
capability. Custom VSCode options are then defined within the custom wdio:vscodeOptions
capability. The options are the following:
binary
Path to a locally installed VSCode installation. If the option is not provided the service will download VSCode based on the given browserVersion
(or stable
if not given).
Type: string
extensionPath
Define the directory to the extension you want to test.
Type: string
storagePath
Define a custom location for VS Code to store all its data. This is the root for internal VS Code directories such as (partial list)
If not provided, a temporary directory is used.
Type: string
userSettings
Define custom user settings to be applied to VSCode.
Type: Record<string, number | string | object | boolean>
Default: {}
workspacePath
Opens VSCode for a specific workspace. If not provided VSCode starts without a workspace opened.
Type: string
filePath
Opens VSCode with a specific file opened.
Type: string
vscodeArgs
Additional start-up arguments as an object, e.g.
1vscodeArgs: { fooBar: true, 'bar-foo': '/foobar' }
will be passed in as:
1--foo-bar --fooBar --bar-foo=/foobar
Type: Record<string, string | boolean>
Default: see constants.ts#L5-L14
verboseLogging
If set to true, the service logs VSCode output from the extension host and console API.
Type: boolean
Default: false
vscodeProxyOptions
VSCode API proxy configurations define how WebdriverIO connects to the VSCode workbench to give you access to the VSCode API.
Type: VSCodeProxyOptions
Default:
1{ 2 /** 3 * If set to true, the service tries to establish a connection with the 4 * VSCode workbench to enable access to the VSCode API 5 */ 6 enable: true, 7 /** 8 * Port of the WebSocket connection used to connect to the workbench. 9 * By default set to an available port in your operating system. 10 */ 11 // port?: number 12 /** 13 * Timeout for connecting to WebSocket inside of VSCode 14 */ 15 connectionTimeout: 5000, 16 /** 17 * Timeout for command to be executed within VSCode 18 */ 19 commandTimeout: 5000 20}
Starting from VSCode v1.86 it is required to use webdriverio
v8.14 or later to install Chromedriver with no configuration necessary. The simplified browser automation setup handles everything for you.
To test earlier versions of VS Code, find the expected version of Chromedriver from the logs, download Chromedriver, and configure the path. For example:
[0-0] ERROR webdriver: Failed downloading chromedriver v108: Download failed: ...
1 capabilities: [{ 2 browserName: 'vscode', 3 browserVersion: '1.80.0', 4 'wdio:chromedriverOptions': { 5 binary: path.join(cacheDir, 'chromedriver-108.0.5359.71')
You can reuse the components used in this service for your own review page objects. For that first create a file that defines all your selectors, e.g.:
1// e.g. in /test/pageobjects/locators.ts 2export const componentA = { 3 elem: 'form', // component container element 4 submit: 'button[type="submit"]', // submit button 5 username: 'input.username', // username input 6 password: 'input.password' // password input 7}
Now you can create a page object as follows:
1// e.g. in /test/pageobjects/loginForm.ts 2import { PageDecorator, IPageDecorator, BasePage } from 'wdio-vscode-service' 3import * as locatorMap, { componentA as componentALocators } from './locators' 4export interface LoginForm extends IPageDecorator<typeof componentALocators> {} 5@PageDecorator(componentALocators) 6export class LoginForm extends BasePage<typeof componentALocators, typeof locatorMap> { 7 /** 8 * @private locator key to identify locator map (see locators.ts) 9 */ 10 public locatorKey = 'componentA' as const 11 12 public login (username: string, password: string) { 13 await this.username$.setValue(username) 14 await this.password$.setValue(password) 15 await this.submit$.click() 16 } 17}
Now in your test, you can use your page object as follows:
1import { LoginForm } from '../pageobjects/loginForm' 2import * as locatorMap from '../locators' 3 4// e.g. in /test/specs/example.e2e.ts 5describe('my extension', () => { 6 it('should login', async () => { 7 const loginForm = new LoginForm(locatorMap) 8 await loginForm.login('admin', 'test123') 9 10 // you can also use page object elements directly via `[selector]$` 11 // or `[selector]$$`, e.g.: 12 await loginForm.submit$.click() 13 14 // or access locators directly 15 console.log(loginForm.locators.username) 16 // outputs: "input.username" 17 }) 18})
If you use WebdriverIO with TypeScript make sure to add wdio-vscode-service
to your types
in your tsconfig.json
, e.g.:
1{ 2 "compilerOptions": { 3 "moduleResolution": "node", 4 "types": [ 5 "webdriverio/async", 6 "@wdio/mocha-framework", 7 "expect-webdriverio", 8 // add this service to your types 9 "wdio-devtools-service" 10 ], 11 "target": "es2019" 12 } 13}
During the initialization of this service, a ChromeDriver and VSCode distribution is downloaded. You can tunnel this requests through a proxy by setting the environment variable HTTPS_PROXY
or https_proxy
. E. g.:
1HTTPS_PROXY=http://127.0.0.1:1080 npm run wdio
The following VS Code extensions use wdio-vscode-service
:
Before posting a pull request, please run the following:
git clone git@github.com:webdriverio-community/wdio-vscode-service.git
cd wdio-vscode-service
npm install
npm run build
npm run test
(or npm run ci
)If you want to learn more about testing VSCode Extensions, check out Christian Bromann's talk at OpenJS World 2022:
For more information on WebdriverIO check out the project homepage.
No vulnerabilities found.
No security vulnerabilities found.