Command API

API available via page.runjs command

Puppeteer methods

  • bs - object representing browsing session

    • browser - instance of Browserarrow-up-right, which is being created in test setup with configuration provided in Puppetry app

    • page - instance of Pagearrow-up-right (alias of bs.browser.page)

    • target(element: ElementHandle) - helpers

      • getProp(prop: string): Promise<string> - obtain element property value

      • getAttr(attr: string): Promise<string> - obtain element attribute value

      • isVisible(): Promise<boolean> - find out f element visible

      • select(value: string): Promise<void> - set a value on select element

Examples:

// Navigating to "https://dsheiko.github.io/react-html5-form/"
  await bs.page.goto( "https://dsheiko.github.io/react-html5-form/", {
    timeout: 30000,
    waitUntil: "load"
  });
  
  // Emulating device "Blackberry PlayBook landscape"
  await bs.page.emulate( devices[ "Blackberry PlayBook landscape" ] );
  
  const title = await bs.page.title();

Working with targets

Assuming we have targets SUBMIT_BTN, EMAIL_INPUT defined with Puppetry app

Jest tools

Please find available API in official documentation of Jest frameworkarrow-up-right. Most demanded tool for the context is expect. In the scope of the test it is extended with the following methods:

  • expect( result )

    • toBeOk( expectedValue, assertionSource) - assert the received value is truthy

    • toBeEqual( expectedValue, assertionSource) - assert the received value equals expected one

    • toIncludeSubstring(expectedSubstring, assertionSource) - assert the received string contains expected one

    • toPassCondition(operator, valueToCompare, assertionSource) - assert the received value satisfies a given Puppetry condition

    • toMatchBoundingBoxSnapshot(snapshot, assertionSource) - assert the received bounding box matches a given snapshot

    • toMatchPosition(position, target, counterpart, assertionSource) - assert the received position object matches a given one

Examples:

Helpers

Helpers are functions available in specification (suite) scope

png( title, options ): Object - build screenshot options

Example:

This command saves screenshot in ./screenshots/All--available--methods/Just-for-test.png given that test title is All available methods

Node.js

In the test scope one can access Node.js modulesarrow-up-right.

Last updated