Skip to content

Commit c72ea22

Browse files
committed
Merge branch '3.x' of github.com:codeceptjs/CodeceptJS into 3.x
2 parents 6261c0f + 361edba commit c72ea22

File tree

18 files changed

+454
-113
lines changed

18 files changed

+454
-113
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ Applicable plugins:
2121
- [ ] autoLogin
2222
- [ ] customLocator
2323
- [ ] pauseOnFail
24-
- [ ] puppeteerCoverage
24+
- [ ] coverage
2525
- [ ] retryFailedStep
2626
- [ ] screenshotOnFail
2727
- [ ] selenoid
2828
- [ ] stepByStepReport
2929
- [ ] wdio
30+
- [ ] subtitles
3031

3132
## Type of change
3233

docs/configuration.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ After running `codeceptjs init` it should be saved in test root.
1111

1212
Here is an overview of available options with their defaults:
1313

14-
* **tests**: `"./*_test.js"` - pattern to locate tests. Allows to enter [glob pattern](https://github.com/isaacs/node-glob).
14+
* **tests**: `"./*_test.js"` - pattern to locate tests. Allows to enter [glob pattern](https://github.com/isaacs/node-glob), Can either be a pattern to locate tests or an array of patterns to locate tests / test file names.
1515
* **grep**: - pattern to filter tests by name
1616
* **include**: `{}` - actors and page objects to be registered in DI container and included in tests. Accepts objects and module `require` paths
1717
* **timeout**: `10000` - default tests timeout
@@ -47,7 +47,20 @@ exports.config = {
4747
require: ["ts-node/register", "should"]
4848
}
4949
```
50-
50+
For array of test pattern
51+
```js
52+
exports.config = {
53+
tests: ['./*_test.js','./sampleTest.js'],
54+
timeout: 10000,
55+
output: '',
56+
helpers: {},
57+
include: {},
58+
bootstrap: false,
59+
mocha: {},
60+
// require modules
61+
require: ["ts-node/register", "should"]
62+
}
63+
```
5164
## Dynamic Configuration
5265

5366
By default `codecept.json` is used for configuration. You can override its values in runtime by using `--override` or `-o` option in command line, passing valid JSON as a value:

docs/helpers/Appium.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,11 +1667,9 @@ I.saveElementScreenshot(`#submit`,'debug.png');
16671667

16681668
Saves a screenshot to ouput folder (set in codecept.json or codecept.conf.js).
16691669
Filename is relative to output folder.
1670-
Optionally resize the window to the full available page `scrollHeight` and `scrollWidth` to capture the entire page by passing `true` in as the second argument.
16711670

16721671
```js
16731672
I.saveScreenshot('debug.png');
1674-
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
16751673
```
16761674

16771675
#### Parameters

docs/playwright.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,63 @@ For instance, this is how you can read a trace for a failed test from an example
456456
npx playwright show-trace /home/davert/projects/codeceptjs/examples/output/trace/open.zip
457457
```
458458

459+
## Capturing code coverage
460+
461+
Code coverage can be captured, by enabling the `coverage` plugin in `codecept.config.js`.
462+
463+
```js
464+
{
465+
plugins: {
466+
coverage: {
467+
enabled: true
468+
}
469+
}
470+
}
471+
```
472+
473+
Once all the tests are completed, `codecept` will create and store coverage in `output/coverage` folder, as shown below.
474+
475+
![](https://user-images.githubusercontent.com/16587779/131362352-30ee9c51-705f-4098-b665-53035ea9275f.png)
476+
477+
### Converting `playwright` coverage to `istanbul` coverage
478+
479+
To convert coverage generated from `playwright` to `istanbul` coverage, you first need to install
480+
- [`v8-to-istanbul`](https://www.npmjs.com/package/v8-to-istanbul)
481+
482+
Once installed, convert the coverage to a format which `istanbul` can recognize, by writing a script as shown below.
483+
484+
```js
485+
const v8toIstanbul = require('v8-to-istanbul');
486+
// read all the coverage file from output/coverage folder
487+
const coverage = require('./output/coverage/Visit_Home_1630335005.coverage.json');
488+
const fs = require('fs/promises');
489+
490+
(async () => {
491+
for (const entry of coverage) {
492+
// Used to get file name
493+
const file = entry.url.match(/(?:http(s)*:\/\/.*\/)(?<file>.*)/);
494+
const converter = new v8toIstanbul(file.groups.file, 0, {
495+
source: entry.source
496+
});
497+
498+
await converter.load();
499+
converter.applyCoverage(entry.functions);
500+
501+
// Store converted coverage file which can later be used to generate report
502+
await fs.writeFile('./coverage/final.json', JSON.stringify(converter.toIstanbul(), null, 2));
503+
}
504+
})();
505+
```
506+
507+
Once the istanbul compatible coverage is generated, use [`nyc`](https://www.npmjs.com/package/nyc) to generate your coverage report in your desired format.
508+
509+
```
510+
npx nyc report --reporter text -t coverage
511+
```
512+
513+
The above command will generate a text report like shown below.
514+
515+
![](https://user-images.githubusercontent.com/16587779/131363170-b03b4398-5e9a-4142-bc32-764a5f4a5e11.png)
459516
## Extending Helper
460517

461518
To create custom `I.*` commands using Playwright API you need to create a custom helper.

docs/plugins.md

Lines changed: 60 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,29 @@ Scenario('project update test', async (I) => {
409409

410410
- `config`
411411

412+
## coverage
413+
414+
Dumps code coverage from Playwright/Puppeteer after every test.
415+
416+
#### Configuration
417+
418+
```js
419+
plugins: {
420+
playwrightCoverage: {
421+
enabled: true
422+
}
423+
}
424+
```
425+
426+
Possible config options:
427+
428+
- `coverageDir`: directory to dump coverage files
429+
- `uniqueFileName`: generate a unique filename by adding uuid
430+
431+
### Parameters
432+
433+
- `config`
434+
412435
## customLocator
413436

414437
Creates a [custom locator][3] by using special attributes in HTML.
@@ -441,7 +464,7 @@ Using `data-test` attribute with `$` prefix:
441464
// in codecept.conf.js
442465
plugins: {
443466
customLocator: {
444-
enabled: true
467+
enabled: true,
445468
attribute: 'data-test'
446469
}
447470
}
@@ -460,7 +483,7 @@ Using `data-qa` attribute with `=` prefix:
460483
// in codecept.conf.js
461484
plugins: {
462485
customLocator: {
463-
enabled: true
486+
enabled: true,
464487
prefix: '=',
465488
attribute: 'data-qa'
466489
}
@@ -536,45 +559,6 @@ Enable it manually on each run via `-p` option:
536559
537560
npx codeceptjs run -p pauseOnFail
538561
539-
## puppeteerCoverage
540-
541-
Dumps puppeteers code coverage after every test.
542-
543-
#### Configuration
544-
545-
Configuration can either be taken from a corresponding helper (deprecated) or a from plugin config (recommended).
546-
547-
```js
548-
plugins: {
549-
puppeteerCoverage: {
550-
enabled: true
551-
}
552-
}
553-
```
554-
555-
Possible config options:
556-
557-
- `coverageDir`: directory to dump coverage files
558-
- `uniqueFileName`: generate a unique filename by adding uuid
559-
560-
First of all, your mileage may vary!
561-
562-
To work, you need the client javascript code to be NOT uglified. They need to be built in "development" mode.
563-
And the end of your tests, you'll get a directory full of coverage per test run. Now what?
564-
You'll need to convert the coverage code to something istanbul can read. Good news is someone wrote the code
565-
for you (see puppeteer-to-istanbul link below). Then using istanbul you need to combine the converted
566-
coverage and create a report. Good luck!
567-
568-
Links:
569-
570-
- [https://github.com/GoogleChrome/puppeteer/blob/v1.12.2/docs/api.md#class-coverage][7]
571-
- [https://github.com/istanbuljs/puppeteer-to-istanbul][8]
572-
- [https://github.com/gotwarlost/istanbul][9]
573-
574-
### Parameters
575-
576-
- `config`
577-
578562
## retryFailedStep
579563
580564
Retries each failed step in a test.
@@ -673,14 +657,14 @@ Possible config options:
673657
674658
## selenoid
675659
676-
[Selenoid][10] plugin automatically starts browsers and video recording.
660+
[Selenoid][7] plugin automatically starts browsers and video recording.
677661
Works with WebDriver helper.
678662
679663
### Prerequisite
680664
681665
This plugin **requires Docker** to be installed.
682666
683-
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][11] tool from Selenoid
667+
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][8] tool from Selenoid
684668
685669
### Usage
686670
@@ -709,7 +693,7 @@ plugins: {
709693
}
710694
```
711695
712-
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][12] and start Selenoid automatically.
696+
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][9] and start Selenoid automatically.
713697
It will also create `browsers.json` file required by Selenoid.
714698
715699
In automatic mode the latest version of browser will be used for tests. It is recommended to specify exact version of each browser inside `browsers.json` file.
@@ -721,10 +705,10 @@ In automatic mode the latest version of browser will be used for tests. It is re
721705
While this plugin can create containers for you for better control it is recommended to create and launch containers manually.
722706
This is especially useful for Continous Integration server as you can configure scaling for Selenoid containers.
723707
724-
> Use [Selenoid Configuration Manager][11] to create and start containers semi-automatically.
708+
> Use [Selenoid Configuration Manager][8] to create and start containers semi-automatically.
725709
726710
1. Create `browsers.json` file in the same directory `codecept.conf.js` is located
727-
[Refer to Selenoid documentation][13] to know more about browsers.json.
711+
[Refer to Selenoid documentation][10] to know more about browsers.json.
728712
729713
_Sample browsers.json_
730714
@@ -749,7 +733,7 @@ _Sample browsers.json_
749733
750734
2. Create Selenoid container
751735
752-
Run the following command to create a container. To know more [refer here][14]
736+
Run the following command to create a container. To know more [refer here][11]
753737
754738
```bash
755739
docker create \
@@ -782,15 +766,15 @@ When `allure` plugin is enabled a video is attached to report automatically.
782766
| enableVideo | Enable video recording and use `video` folder of output (default: false) |
783767
| enableLog | Enable log recording and use `logs` folder of output (default: false) |
784768
| deletePassed | Delete video and logs of passed tests (default : true) |
785-
| additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here][15] to know more |
769+
| additionalParams | example: `additionalParams: '--env TEST=test'` [Refer here][12] to know more |
786770
787771
### Parameters
788772
789773
- `config`
790774
791775
## stepByStepReport
792776
793-
![step-by-step-report][16]
777+
![step-by-step-report][13]
794778
795779
Generates step by step report for a test.
796780
After each step in a test a screenshot is created. After test executed screenshots are combined into slideshow.
@@ -823,6 +807,20 @@ Possible config options:
823807
824808
- `config` **any**
825809
810+
## subtitles
811+
812+
Automatically captures steps as subtitle, and saves it as an artifact when a video is found for a failed test
813+
814+
#### Configuration
815+
816+
```js
817+
plugins: {
818+
subtitles: {
819+
enabled: true
820+
}
821+
}
822+
```
823+
826824
## tryTo
827825
828826
Adds global `tryTo` function inside of which all failed steps won't fail a test but will return true/false.
@@ -897,7 +895,7 @@ This plugin allows to run webdriverio services like:
897895
- browserstack
898896
- appium
899897
900-
A complete list of all available services can be found on [webdriverio website][17].
898+
A complete list of all available services can be found on [webdriverio website][14].
901899
902900
#### Setup
903901
@@ -909,7 +907,7 @@ See examples below:
909907
910908
#### Selenium Standalone Service
911909
912-
Install `@wdio/selenium-standalone-service` package, as [described here][18].
910+
Install `@wdio/selenium-standalone-service` package, as [described here][15].
913911
It is important to make sure it is compatible with current webdriverio version.
914912
915913
Enable `wdio` plugin in plugins list and add `selenium-standalone` service:
@@ -928,7 +926,7 @@ Please note, this service can be used with Protractor helper as well!
928926
929927
#### Sauce Service
930928
931-
Install `@wdio/sauce-service` package, as [described here][19].
929+
Install `@wdio/sauce-service` package, as [described here][16].
932930
It is important to make sure it is compatible with current webdriverio version.
933931
934932
Enable `wdio` plugin in plugins list and add `sauce` service:
@@ -970,28 +968,22 @@ In the same manner additional services from webdriverio can be installed, enable
970968
971969
[6]: /basics/#pause
972970
973-
[7]: https://github.com/GoogleChrome/puppeteer/blob/v1.12.2/docs/api.md#class-coverage
974-
975-
[8]: https://github.com/istanbuljs/puppeteer-to-istanbul
976-
977-
[9]: https://github.com/gotwarlost/istanbul
978-
979-
[10]: https://aerokube.com/selenoid/
971+
[7]: https://aerokube.com/selenoid/
980972
981-
[11]: https://aerokube.com/cm/latest/
973+
[8]: https://aerokube.com/cm/latest/
982974
983-
[12]: https://hub.docker.com/u/selenoid
975+
[9]: https://hub.docker.com/u/selenoid
984976
985-
[13]: https://aerokube.com/selenoid/latest/#_prepare_configuration
977+
[10]: https://aerokube.com/selenoid/latest/#_prepare_configuration
986978
987-
[14]: https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container
979+
[11]: https://aerokube.com/selenoid/latest/#_option_2_start_selenoid_container
988980
989-
[15]: https://docs.docker.com/engine/reference/commandline/create/
981+
[12]: https://docs.docker.com/engine/reference/commandline/create/
990982
991-
[16]: https://codecept.io/img/codeceptjs-slideshow.gif
983+
[13]: https://codecept.io/img/codeceptjs-slideshow.gif
992984
993-
[17]: https://webdriver.io
985+
[14]: https://webdriver.io
994986
995-
[18]: https://webdriver.io/docs/selenium-standalone-service.html
987+
[15]: https://webdriver.io/docs/selenium-standalone-service.html
996988
997-
[19]: https://webdriver.io/docs/sauce-service.html
989+
[16]: https://webdriver.io/docs/sauce-service.html

examples/coverage_test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Feature('Local server');
2+
3+
Scenario('Render buttons', ({ I }) => {
4+
I.amOnPage('http://127.0.0.1:8080/');
5+
I.see('Hi');
6+
I.forceClick('Hi');
7+
});

0 commit comments

Comments
 (0)