Framework Adapters for Protractor
April 7, 2019 ยท View on GitHub
Protractor can work with any test framework that is adapted here.
Each file details the adapter for one test framework. Each file must export a
run function with the interface:
/**
* @param {Runner} runner The Protractor runner instance.
* @param {Array.<string>} specs A list of absolute filenames.
* @return {Promise.<Object>} Promise resolved with the test results. See
* "Requirements" section for details.
*/
export let run: (runner: Protractor.Runner, specs: string[]) => Promise<Object>
Requirements
-
runner.emitmust be called withtestPassandtestFailmessages. These messages must be passed atestInfoobject with the following structure:testInfo: { category: string, name: string }The
categoryproperty could be the name of thedescribeblock in jasmine/mocha, theFeaturein cucumber, or the class name in something like jUnit. Thenameproperty could be the name of anitblock in jasmine/mocha, theScenarioin cucumber, or the method name in something like jUnit. -
runner.runTestPreparermust be called after the framework has been initialized but before any spec files are run. This function returns a promise which should be waited on before executing tests. The framework should also pass an array of extra command line flags it accepts, if any. -
runner.getConfig().onCompletemust be called when tests are finished. It might return a promise, in which caseexports.run's promise should not resolve until afteronComplete's promise resolves. -
The returned promise must be resolved when tests are finished and it should return a results object. This object must have a
failedCountproperty and optionally aspecResultsobject of the following structure:specResults: [{ description: string, assertions: [{ passed: boolean, errorMsg: string, stackTrace: string }], duration: integer }]
Future requirements
In Protractor 6.0, the following additional requirement will be added:
runner.afterEachwill have to be called after each test finishes. It will return a promise, which should be waited for before moving onto the next test.
If you want your framework to be backwards-compatible, you can simply write:
if (runner.afterEach) {
// Add afterEach caller
}
Failing to call runner.afterEach will cause features like
restartBrowserBetweenTests to fail. Protractor may also log a warning to the
console.
Custom Frameworks
If you have created/adapted a custom framework and want it added to Protractor core please send a PR so it can evaluated for addition as an official supported framework. In the meantime you can instruct Protractor to use your own framework via the config file:
export let config: Protractor.Config = {
// set to "custom" instead of jasmine/mocha
framework: 'custom',
// path relative to the current config file
frameworkPath: './frameworks/my_custom_jasmine.js',
};
More on this at the configuration.
Disclaimer: current framework interface can change without a major version bump.