2.2.0 • Published 4 years ago

puppeteer-page-object v2.2.0

Weekly downloads
58
License
ISC
Repository
github
Last release
4 years ago

Puppeteer page object Build Status

Small wrapper on puppeteer allows to you use page object pattern with clean steps and incapsulated methods.

Installation

Install it with npm:

npm i --save-dev puppeteer-page-object

Or yarn:

yarn add -D puppeteer-page-object

Usage

Follow examples bellow for fast start.

You can also check some examples with cucumber here.

Base page object

About all properties you can here.

const PageObject = require('puppeteer-page-object')

const examplePageObject = new PageObject({
  scenarioName: 'example-scenario'
})
;async () => {
  await examplePageObject.init()
  await examplePageObject.open('https://example.com')
  await examplePageObject.screenshot()
  await examplePageObject.close()
}

Extending

You can create page object instances and use all power of build in methods and properties:

const PageObject = require('puppeteer-page-object')

class ExamplePage extends PageObject {
  async typeToInput(text) {
    await this.page.type('#input', text)
  }
}

const examplePageObject = new ExamplePage()
;async () => {
  await examplePageObject.init()
  await examplePageObject.open('https://example.com')
  await examplePageObject.screenshot()
  await examplePageObject.typeToInput('Hello world')
  await examplePageObject.close()
}

Properties

NameTypeDefault valueDescription
headlessbooleantrueHeadless mode.
scenarioNamestringnullScenario name to creates better screenshots names.
screenshotsPathstringscreenshotsPath to save screenshots.
argsstring[]['--no-sandbox', '--disable-setuid-sandbox']Args for puppeteer browser launch.

Methods

NameReturnsDescription
.init()Promise<void>Initialize page object, creates browser and page instance. Must be called before all actions with browser and page properties.
.open(url: string)Promise<void>Opens given url. Sugar for this.page.goto.
.close()Promise<void>Closes page. Sugar for this.browser.close.
.screenshot(params?: object)Promise<void>Capture screenshot and save it to dir defined by this.screenshotsPath. You can alse pass params-object. Sugar for this.page.screenshot
.generateScreenshotName()stringGenerates unique screenshot name with test date and scenario name (if it defined in class instance).
2.2.0

4 years ago

2.1.0

5 years ago

2.0.3

5 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.0.0

7 years ago