Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dpck/chrome

The Remote Chrome Context For Testing Like Webdriver.
https://github.com/dpck/chrome

Last synced: about 1 month ago
JSON representation

The Remote Chrome Context For Testing Like Webdriver.

Awesome Lists containing this project

README

        

# @contexts/chrome

[![npm version](https://badge.fury.io/js/%40contexts%2Fchrome.svg)](https://npmjs.org/package/@contexts/chrome)

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

```sh
yarn add -E @contexts/chrome
```

## Table Of Contents

- [Table Of Contents](#table-of-contents)
- [API](#api)
- [class `ChromeContext`](#class-chromecontext)
* [`async navigate(url: string)`](#async-navigateurl-string-void)
* [`async evaluate(expression: string, json?: boolean): *`](#async-evaluateexpression-stringjson-boolean-)
* [get `Page`](#get-page)
* [get `Network`](#get-network)
- [Copyright](#copyright)

## API

The package is available by importing its default function:

```js
import ChromeContext from '@contexts/chrome'
```

## class `ChromeContext`

The class can be used either as a context, or as a persistent context in [_Zoroaster_](https://github.com/contexttesting/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.

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

/** @type {Object.} */
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 2019Tech Nation VisaTech Nation Visa Sucks