GithubHelp home page GithubHelp logo

isabella232 / wdio-devtools-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webdriverio-boneyard/wdio-devtools-service

0.0 0.0 0.0 88 KB

WebdriverIO v4 service that enables DevTools functionality for you WebDriver session

Home Page: http://webdriver.io

License: MIT License

JavaScript 100.00%

wdio-devtools-service's Introduction

WDIO DevTools Service

With Chrome v63 and up the browser started to support multi clients allowing arbitrary clients to access the Chrome DevTools Protocol. This provides interesting opportunities to automate Chrome beyond the WebDriver protocol. With this service you can enhance the wdio browser object to leverage that access and call Chrome DevTools commands within your tests to e.g. intercept requests, throttle network capabilities or take CSS/JS coverage.

Note: this service currently only supports Chrome v63 and up!

Installation

The easiest way is to keep wdio-devtools-service as a devDependency in your package.json.

{
  "devDependencies": {
    "wdio-devtools-service": "~0.1.1"
  }
}

You can simple do it by:

npm install wdio-devtools-service --save-dev

Instructions on how to install WebdriverIO can be found here.

Configuration

In order to use the service you just need to add the service to your service list in your wdio.conf.js like:

// wdio.conf.js
export.config = {
  // ...
  services: ['devtools'],
  // ...
};

Usage

For now the service allows two different ways to access the Chrome DevTools Protocol:

Via cdp Command

The cdp command is a custom command added to the browser scope that allows you to call directly commands to the protocol.

browser.cdp(<domain>, <command>, <arguments>)

For example if you want to get the JavaScript coverage of your page you can do the following:

it('should take JS coverage', () => {
    /**
     * enable necessary domains
     */
    browser.cdp('Profiler', 'enable')
    browser.cdp('Debugger', 'enable')

    /**
     * start test coverage profiler
     */
    browser.cdp('Profiler', 'startPreciseCoverage', {
        callCount: true,
        detailed: true
    })

    browser.url('http://google.com')

    /**
     * capture test coverage
     */
    const { result } = browser.cdp('Profiler', 'takePreciseCoverage')
    const coverage = result.filter((res) => res.url !== '')
    console.log(coverage)
})

Via Event Listener

In order to capture events in the browser you can register an event listener to a Chrome DevTools event like:

it('should listen on network events', () => {
    browser.cdp('Network', 'enable')
    browser.on('Network.responseReceived', (params) => {
        console.log(`Loaded ${params.response.url}`)
    })
    browser.url('https://www.google.com')
})

Development

All commands can be found in the package.json. The most important are:

Watch changes:

$ npm run watch

Build package:

$ npm build

For more information on WebdriverIO see the homepage.

wdio-devtools-service's People

Contributors

benzaremean avatar christian-bromann avatar sns45 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.