@contexts/chrome
v1.0.0
Published
The Remote Chrome Context For Testing Like Webdriver.
Downloads
401
Maintainers
Readme
@contexts/chrome
@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.