npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wdio-shadowdom-service

v1.0.2

Published

Plugin for webdriver.io to transparently make CSS selectors "just work" with shadow DOM

Downloads

102

Readme

wdio-shadowdom-service

This is a plugin for WebDriverIO that transparently makes CSS selectors "just work" with the shadow DOM.

With this plugin, APIs like $('.foo') and $$('.foo')will automatically query inside the shadow DOM to find elements. This can help avoid complicated or hard-to-maintain test code.

Before:

// 😞
const element = $('.foo')
  .shadow$('.bar')
  .shadow$('.baz')
  .shadow$('.quux')

After:

// 🥳
const element = $('.quux') 

Features:

  • APIs like $, $$, and even some basic usage of execute all "just work" with the shadow DOM.
  • Doesn't override the global document.querySelector or document.querySelectorAll. Only touches your test code, not your production code.
  • Uses kagekiri under the hood – a rigorously-tested utility containing a full CSS selector parser.

Install

npm install wdio-shadowdom-service

Usage

Configuration

Modify your wdio.conf.js like so:

const ShadowDomService = require('wdio-shadowdom-service')

exports.config = {
    // ...
    services: [ [ShadowDomService, {}] ],
    // ...
}

Use the webdriver protocol

Due to an open bug on WebDriverIO, you will also need to use the webdriver protocol, not the devtools protocol. Set this in your wdio.conf.js:

exports.config = {
  // ...
  automationProtocol: 'webdriver',
  path: '/wd/hub',
  // ...
}

Examples

Now you can use selector queries that pierce the shadow DOM:

const element = await browser.$('.foo')
const elements = await browser.$$('.foo')

Some simple usages of document.querySelector/querySelectorAll are also supported:

const element = await browser.execute(() => document.querySelector('.foo'))
const elements = await browser.execute(() => document.querySelectorAll('.foo'))

All selectors are able to pierce the shadow DOM, including selectors like '.outer .inner' where .outer is in the light DOM and .inner is in the shadow DOM. See kagekiri for more details on how it works.

Supported APIs

* execute and executeAsync only work with simple usages of document.querySelector/querySelectorAll or element.querySelector/querySelectorAll.

Currently, WebDriverIO v6 and v7 are supported.

Contributing

To lint:

npm run lint

To fix most lint issues automatically:

npm run lint:fix

To run the tests:

npm test

To run the tests in debug mode:

DEBUG=true npm test

Then open chrome:inspector in Chrome and open the dedicated DevTools for Node.