0.5.8 • Published 6 years ago

@zooshgroup/puppeteer-e2e v0.5.8

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

E2E testing with Puppeteer

This is a library wrapping Puppeteer so that it integrates well with a Mocha environment, providing helpful functions to use during testing.

API

class: TestManager

The TestManager module provides two functions which wrap your tests, mainly providing a Puppeteer page/browser instance.

useTestConfig(config)

  • config
    • authenticationFunction : must be given, if you want to use withPage() for your tests. Takes two arguments:
      • page : a Puppeteer page instance to do the authentication on.
      • user : the User object you pass to withPage().
    • pageReadyFunction : can be given, if you want to stall the testing waiting for something (certain elements to load). Takes one argument:
      • page : a Puppeteer page on which your tests will work, to check it for certain conditions.
    • debug : can be given to enable logging of certain util functions.
    • ...config: : any number of other keys, passed to Puppeteer as configuration.

Method used for configuring TestManager, allowing authenticated and pre-guarded tests.

withBrowser(testCase)

  • testCase : contains a sequence of custom assertions. Receives one parameter:
    • browser : the Puppeteer Browser instance to run the test against. Is destroyed after the test.

Provides your test with a Puppeteer browser instance, which is deallocated property after the test. A typical example of using this:

  it('can run a sample test case', withBrowser(async (browser) => {
    const page = await browser.newPage();
    await page.goto(baseUrl);
    await login(page, defaultUser);
    const path = await page.evaluate(() => window.location.pathname);
    expect(path).to.equal('/home');
  }));

withPage(options, testCase)

  • options
    • user: (required): user to authenticate to the page with.
    • location
      • url: : can be given to navigate page to a certain url after creation, thus reducing boilerplate in tests. Defaults to null.
  • testCase : contains a sequence of custom assertions. Receives two parameters:
    • page : the Puppeteer Page instance to run the Browser against. Always starts in an authenticated state with the given User.
    • predicates : contains functions that wait for the passed predicate to be true: THESE CANNOT BE GIVEN ANY VARIABLES FROM AN OUTSIDE SCOPE
      • page: a function returning true or false, run in the console of the browser
      • element: a function returning true or false, run in the console of the browser

A more complex test wrapper, withPage gives you an authenticated page instance from the browser of the user you defined.

  it('can run a sample test case', withBrowser(async (browser) => {
    const page = await browser.newPage();
    await page.goto(baseUrl);
    await login(page, defaultUser);
    const path = await page.evaluate(() => window.location.pathname);
    expect(path).to.equal('/home');
  }));
0.5.8

6 years ago

0.4.8

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago