@contexts/chrome

1.0.0 • Public • Published

@contexts/chrome

npm version

@contexts/chrome is The Remote Chrome Context For Testing Like Webdriver.

yarn add -E @contexts/chrome

Table Of Contents

API

The package is available by importing its default function:

import ChromeContext from '@contexts/chrome'

class ChromeContext

The class can be used either as a context, or as a persistent context in Zoroaster testing framework to eliminate the need to manually write set-up and tear-down routines in tests. The context will connect to a headless chrome and expose API for testing.

import { ok } from 'zoroaster/assert'
import ChromeContext from '@contexts/chrome'

/** @type {Object.<string, (c: ChromeContext)>} */
const T = {
  persistentContext: ChromeContext,
  async 'navigates to a web page'({ Page, evaluate, navigate }) {
    await navigate('about:blank')
    await Page.loadEventFired()
    const { value } = await evaluate('window.navigator.userAgent', false)
    ok(/HeadlessChrome/.test(value))
  },
}

export default T

async navigate(
  url: string,
): void

Navigates to a webpage.

async evaluate(
  expression: string,
  json?: boolean,
): *

Evaluates an expression and returns the result. By default, the outcome will be serialised on the client and deserialised on the receiving end by the context using JSON to enable passing objects. To disable that, the json argument should be set to false.

get Page

The enabled page.

get Network

The enabled network.

Copyright

Art Deco © Art Deco for Depack 2019 Tech Nation Visa Tech Nation Visa Sucks

Package Sidebar

Install

npm i @contexts/chrome

Weekly Downloads

62

Version

1.0.0

License

MIT

Unpacked Size

10.9 kB

Total Files

9

Last publish

Collaborators

  • zvr