2.0.2 • Published 3 years ago

playwright-mocha v2.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

playwright-mocha

NPM

The aim of playwright-mocha is to deliver a lightweight test-framework that is combining the power of mocha and playwright. You should be able to use all configuration options you can provide via mocha or playwright. If you miss something raise an issue or open a pull request.

Installation and configuration via CLI

To install the framework:

npm install playwright-mocha

To run:

npx playwright-mocha

If no configuration file is found the CLI is automatically activated to setup the file via the CLI.

npm.io

Create test

Example

const assert = require('assert');
const { PlaywrightMocha } = require('playwright-mocha/dist/pm');

it('checks the title of the page', async () => {

  const page = PlaywrightMocha.page();

  await page.goto('https://www.headlesstesting.com/');
  const title = await page.title();
  assert.strictEqual(title, 'Headless Testing with Puppeteer and Playwright in the Cloud.');
})

Advanced configuration

The only thing you need now is a configuration file the paramaters browser and testFilesBaseDir are custom framework paramaters the rest of the paramaters are 1:1 mapped to specific playwright or mocha options.

Nameoptions
browserfirefox/chromium/webkit
testFilesBaseDirrelative path to your folder containing the test files
playwrightLaunchOptionshttps://playwright.dev/docs/api/class-browsertype?_highlight=launch#browsertypelaunchoptions
playwrightContextOptionshttps://playwright.dev/docs/api/class-browser?_highlight=context&_highlight=op#browsernewcontextoptions
mochaOptionshttps://mochajs.org/api/mocha

The framework supports parallel execution for each test/spec file. To enable this feature you can add the following lines to the "mochaOptions" in the configuration file.

    "require": ["node_modules/playwright-mocha/dist/hooks.js"],
    "parallel": true

example config with parallel execution

{
  "browser": "firefox",
  "testFilesBaseDir": "examples",
  "playwrightLaunchOptions": {
    "headless": false
  },
  "playwrightContextOptions": {

    "viewport": {
      "width": 1600,
      "height": 1000
    },
    "recordVideo": {
      "dir": "video"
    }
  },
  "mochaOptions": {
    "timeout": 30000,
    "require": ["node_modules/playwright-mocha/dist/hooks.js"],
    "parallel": true
  }
}
2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.0

3 years ago