Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit cb56767

Browse files
committed
chore(docs): new framework requirements in Protractor 6.0
Also converted the code in `lib/frameworks/README.md` to typescript. Also exported the type of `Runner` so that framework-writers can use typescript. Closes #3893
1 parent 293ffa6 commit cb56767

File tree

2 files changed

+79
-33
lines changed

2 files changed

+79
-33
lines changed

Diff for: lib/frameworks/README.md

+77-33
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,91 @@ Framework Adapters for Protractor
33

44
Protractor can work with any test framework that is adapted here.
55

6-
Each file details the adapter for one test framework. Each file must export a `run` function with the interface:
6+
Each file details the adapter for one test framework. Each file must export a
7+
`run` function with the interface:
78

8-
```js
9+
```ts
910
/**
1011
* @param {Runner} runner The Protractor runner instance.
1112
* @param {Array.<string>} specs A list of absolute filenames.
12-
* @return {q.Promise} Promise resolved with the test results
13+
* @return {Promise.<Object>} Promise resolved with the test results. See
14+
* "Requirements" section for details.
1315
*/
14-
exports.run = function(runner, specs)
16+
export let run: (runner: Protractor.Runner, specs: string) => Promise<Object>
17+
```
18+
19+
It is recommended that it also export a `protractorVersion` property:
20+
21+
```ts
22+
/**
23+
* The version of Protractor this framework was written for. Do not use syntax
24+
* like "^6.0.0" - name a specific version of Protractor. This property is
25+
* optional but recommended.
26+
*
27+
* @example "6.0.0"
28+
* @type {string=}
29+
*/
30+
export let protractorVersion: string;
1531
```
1632

1733
Requirements
1834
------------
1935

20-
- `runner.emit` must be called with `testPass` and `testFail` messages. These
21-
messages must be passed a `testInfo` object, with a `name` and `category`
22-
property. The `category` property could be the name of the `describe` block
23-
in jasmine/mocha, the `Feature` in cucumber, or the class name in something
24-
like jUnit. The `name` property could be the name of an `it` block in
25-
jasmine/mocha, the `Scenario` in cucumber, or the method name in something
26-
like jUnit.
27-
28-
- `runner.runTestPreparer` must be called before any tests are run.
29-
30-
- `runner.getConfig().onComplete` must be called when tests are finished.
31-
It might return a promise, in which case `exports.run`'s promise should not
32-
resolve until after `onComplete`'s promise resolves.
33-
34-
- The returned promise must be resolved when tests are finished and it should return a results object. This object must have a `failedCount` property and optionally a `specResults`
35-
object of the following structure:
36-
```
37-
specResults = [{
38-
description: string,
39-
assertions: [{
40-
passed: boolean,
41-
errorMsg: string,
42-
stackTrace: string
43-
}],
44-
duration: integer
45-
}]
46-
```
36+
- `runner.emit` must be called with `testPass` and `testFail` messages. These
37+
messages must be passed a `testInfo` object with the following structure:
38+
39+
```ts
40+
testInfo: {
41+
category: string,
42+
name: string
43+
}
44+
```
45+
46+
The `category` property could be the name of the `describe` block in
47+
jasmine/mocha, the `Feature` in cucumber, or the class name in something like
48+
jUnit.
49+
The `name` property could be the name of an `it` block in jasmine/mocha, the
50+
`Scenario` in cucumber, or the method name in something like jUnit.
51+
52+
- `runner.runTestPreparer` must be called after the framework has been
53+
initialized but before any spec files are run. This function returns a
54+
promise which should be waited on before executing tests.
55+
56+
- `runner.getConfig().onComplete` must be called when tests are finished.
57+
It might return a promise, in which case `exports.run`'s promise should not
58+
resolve until after `onComplete`'s promise resolves.
59+
60+
- The returned promise must be resolved when tests are finished and it should
61+
return a results object. This object must have a `failedCount` property and
62+
optionally a `specResults` object of the following structure:
63+
64+
```ts
65+
specResults: Array<{
66+
description: string,
67+
assertions: Array<{
68+
passed: boolean,
69+
errorMsg: string,
70+
stackTrace: string
71+
}>,
72+
duration: integer
73+
}>
74+
```
75+
76+
### Future requirements
77+
78+
In Protractor 6.0, the following additional requirement will be added:
79+
80+
- `runner.afterEach` will have to be called after each test finishes. It will
81+
return a promise, which should be waited for before moving onto the next test.
82+
83+
If your framework does not export a `protractorVersion` property which is at
84+
least 6.0.0, and `testPass` or `testFail` are emitted before
85+
`runner.afterEach` is called, Protractor will assume your framework is old and
86+
does not support `runner.afterEach`. In this case, Protractor will call
87+
`runner.afterEach` inside the listener for `testPass` or `testFail`.
88+
Protractor will log warnings to the console if important asynchronous work
89+
in `runner.afterEach` needed to finish before the next test started, since it
90+
can't wait on a Promise from inside an event listener.
4791

4892
Custom Frameworks
4993
-----------------
@@ -53,8 +97,8 @@ Protractor core please send a PR so it can evaluated for addition as an
5397
official supported framework. In the meantime you can instruct Protractor
5498
to use your own framework via the config file:
5599

56-
```js
57-
exports.config = {
100+
```ts
101+
export let config: Protractor.Config = {
58102
// set to "custom" instead of jasmine/mocha
59103
framework: 'custom',
60104
// path relative to the current config file

Diff for: lib/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {ElementArrayFinder, ElementFinder} from './element';
33
import {ProtractorExpectedConditions} from './expectedConditions';
44
import {ProtractorBy} from './locators';
55
import {Ptor} from './ptor';
6+
import {Runner} from './runner';
67

78
// Re-export selenium-webdriver types.
89
export {ActionSequence, Browser, Builder, Button, Capabilities, Capability, error, EventEmitter, FileDetector, Key, logging, promise, Session, until, WebDriver, WebElement, WebElementPromise} from 'selenium-webdriver';
@@ -14,6 +15,7 @@ export {ElementArrayFinder, ElementFinder} from './element';
1415
export {ProtractorExpectedConditions} from './expectedConditions';
1516
export {ProtractorBy} from './locators';
1617
export {Ptor} from './ptor';
18+
export type Runner = Runner;
1719

1820
export let utils = {
1921
firefox: require('selenium-webdriver/firefox'),

0 commit comments

Comments
 (0)