web page automatic tester
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.editorconfig
.gitignore
.travis.yml
README.md
executor.js
index.js
package.json
util.js

README.md

Npm Package Build Status Dependency Status Npm Downloads

chrome-tester

Web page auto tester with headless chrome

Use

const Tester = require('chrome-tester');
const tester = new Tester();
await tester.init();
const job = {
  url: 'https://ke.qq.com',
  tests: [
    {
      des: 'succ test',
      script: `return true`
    },
    {
      des: 'fail test',
      script: `throw 1`
    }
  ]
}
const executor = await tester.exec(job);
executor.on('test-pass', (test, value) => {
  console.log('test-pass');
  assert.equal(test.des, 'succ test');
  assert.equal(value, true);
});
executor.on('test-failed', (test, exceptionDetails) => {
  console.log('test-failed');
  assert.equal(test.des, 'fail test');
  assert.equal(exceptionDetails.exception.value, 1);
});
await executor.wait();
const dom = await executor.getDOM();
await tester.destroy();
  • tester.init(): await tester be ready
  • tester.exec(job): run a test job, this will return a executor used to listen on some events
  • await executor.wait(): await until all unit tests job has done
  • await executor.getDOM(): get page current dom node
  • tester.destroy(): destroy this tester, close chrome, release resource

tester.exec options

  • url {string}: required, web page url
  • referrer {string}: http request referrer header
  • cookies {Object}: http request cookies
  • headers {Object}: http request headers
  • injectScript {string}: inject script to exec after domContentEventFired
  • tests {Array}: unit tests will run after injectScript has been inject, tests will be run one by one in order element in tests should be:
      {  
        script {string}: unit test script content,
        ... other props
      }

executor events table

  • log: chrome console out
  • error: window.onerror | unhandledrejection
  • test-pass: unit test exec complete
  • test-failed: unit test exec complete
  • done: exec complete
  • pageload-failed: page cant load
  • network-failed: Network.loadingFailed event
  • network-received: Network.loadingFailed event

see unit test for more use case.