playwright/utils/testrunner
Dmitry Gozman 2d57fff0be
fix(tests): fix multiple browsers tests (#1718)
- Use a server only once, not once per browser.
- Avoid require cache for test files.
- Improve testrunner hooks debugging.
2020-04-08 15:54:17 -07:00
..
examples Initial commit 2019-11-19 10:58:15 -08:00
test feat(testrunner): catch delegate errors (#1704) 2020-04-07 22:56:21 -07:00
.npmignore Initial commit 2019-11-19 10:58:15 -08:00
GoldenUtils.js feat(testrunner): make it easier to setup golden matcher (#1682) 2020-04-06 18:01:56 -07:00
index.js test: structure tests to use environments, closer to end user (#1713) 2020-04-08 14:17:34 -07:00
Location.js feat(testrunner): catch delegate errors (#1704) 2020-04-07 22:56:21 -07:00
Matchers.js feat(testrunner): catch delegate errors (#1704) 2020-04-07 22:56:21 -07:00
README.md chore: replace pptr with pw (#643) 2020-01-24 16:15:41 -08:00
Reporter.js chore(testrunner): split TestRunner into parts (#1679) 2020-04-06 17:21:42 -07:00
SourceMap.js devops(testrunner): support source maps (#340) 2020-01-08 16:16:54 +00:00
SourceMapSupport.js fix(testrunner): support throwing non-errors 2020-02-20 17:06:05 -08:00
Test.js fix(testrunner): better capture Location for hooks (#1680) 2020-04-06 17:47:17 -07:00
TestCollector.js test: structure tests to use environments, closer to end user (#1713) 2020-04-08 14:17:34 -07:00
TestRunner.js fix(tests): fix multiple browsers tests (#1718) 2020-04-08 15:54:17 -07:00

TestRunner

This test runner is used internally by Playwright to test Playwright itself.

  • testrunner is a library: tests are node.js scripts
  • parallel wrt IO operations
  • supports async/await
  • modular
  • well-isolated state per execution thread

Example

Save the following as test.js and run using node:

node test.js
const {TestRunner, Reporter, Matchers} = require('.');

// Runner holds and runs all the tests
const runner = new TestRunner({
  parallel: 2, // run 2 parallel threads
  timeout: 1000, // setup timeout of 1 second per test
});
// Simple expect-like matchers
const {expect} = new Matchers();

// Extract jasmine-like DSL into the global namespace
const {describe, xdescribe, fdescribe} = runner;
const {it, fit, xit} = runner;
const {beforeAll, beforeEach, afterAll, afterEach} = runner;

// Test hooks can be async.
beforeAll(async state => {
  state.parallelIndex; // either 0 or 1 in this example, depending on the executing thread
  state.foo = 'bar'; // set state for every test
});

describe('math', () => {
  it('to be sane', async (state, test) => {
    state.parallelIndex; // Very first test will always be ran by the 0's thread
    state.foo; // this will be 'bar'
    expect(2 + 2).toBe(4);
  });
});

// Reporter subscribes to TestRunner events and displays information in terminal
const reporter = new Reporter(runner);

// Run all tests.
runner.run();