GithubHelp home page GithubHelp logo

isabella232 / wdio-shadowdom-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from salesforce/wdio-shadowdom-service

0.0 0.0 0.0 856 KB

Plugin for WebDriverIO that makes CSS selectors "just work" with the shadow DOM

License: BSD 3-Clause "New" or "Revised" License

JavaScript 81.65% HTML 18.35%

wdio-shadowdom-service's Introduction

wdio-shadowdom-service build status

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.

wdio-shadowdom-service's People

Contributors

dependabot[bot] avatar nolanlawson avatar svc-scm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.