Skip to main content


Lit is a simple library for building fast, lightweight web components. Testing Lit web components with WebdriverIO is very easy thanks to WebdriverIOs shadow DOM selectors you can query in shadow roots nested elements with just one single command.


To setup WebdriverIO within your Lit project, follow the instructions in our component testing docs. For Lit you need a preset as Lit web components don't need to run through a compiler, they are pure web component enhancements.

Once set-up, you can start the tests by running:

npx wdio run ./wdio.conf.js

Writing Tests​

Given you have the following Lit component:

import { LitElement, css, html } from 'lit'
import { customElement, property } from 'lit/decorators.js'

export class SimpleGreeting extends LitElement {
name?: string = 'World'

// Render the UI as a function of component state
render() {
return html`<p>Hello, ${}!</p>`

In order test the component you have to render it into the test page before the test starts and ensure it gets cleaned up afterwards:

import expect from 'expect'
import { waitFor } from '@testing-library/dom'

// import Lit component
import './components/Component.ts'

describe('Lit Component testing', () => {
let elem: HTMLElement

beforeEach(() => {
elem = document.createElement('simple-greeting')

it('should render component', async () => {
elem.setAttribute('name', 'WebdriverIO')

await waitFor(() => {
expect(elem.shadowRoot.textContent).toBe('Hello, WebdriverIO!')

afterEach(() => {

You can find a full example of a WebdriverIO component test suite for Lit in our example repository.