Skip to content

Commit

Permalink
Upd nodejs version
Browse files Browse the repository at this point in the history
  • Loading branch information
And93 committed Feb 27, 2021
1 parent 8c75928 commit 7e44b80
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 57 deletions.
105 changes: 58 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Protractor-puppeteer plugin

The main goal of this plugin is to enable the use of two tools in autotests written on Protractor.
Also, this plugin can measure page performance using Lighthouse.
The main goal of this plugin is to enable the use of two tools in autotests written on Protractor. Also, this plugin can
measure page performance using Lighthouse.

**Chrome only supported.**

Expand All @@ -14,7 +14,7 @@ Also, this plugin can measure page performance using Lighthouse.
| ^3.0.0 | ^5.0.0 | ^4.0.0 | - | ^10 |
| ^4.0.0 | ^5.0.0 | ^5.0.0 | - | ^10 |
| ^5.0.0 | ^5.0.0 | ^5.2.0 | ^6.3.0 | ^10 |
| ^5.2.0 (`Current`) | ^5.0.0 | ^5.5.0 | ^7.0.0 | ^10 |
| ^5.2.0 (`Current`) | ^5.0.0 | ^5.5.0 | ^7.0.0 | ^12 |

## How to add this plugin to protractor:

Expand Down Expand Up @@ -65,13 +65,15 @@ plugins: [{
}
}]
```

**(!) Note:** The `configFile` property takes precedence over the `configOptions` property.

### What should 'configFile' contain?

The `configFile` must be `.json` extension and contains the following properties.

E.g.:

```
// puppeteer.conf.json
{
Expand Down Expand Up @@ -115,6 +117,7 @@ E.g.:
```

### Documentation

* [`connectOptions`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerconnectoptions)
* [`timeout`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetdefaulttimeouttimeout)
* [`defaultArgs`](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#puppeteerdefaultargsoptions)
Expand All @@ -124,9 +127,8 @@ E.g.:

## How to use:

1. If you would like to connect to browser by yourself,
or you would like to use some functions which return from `class: Puppeteer`,
you should use `puppeteer` property:
1. If you would like to connect to browser by yourself, or you would like to use some functions which return
from `class: Puppeteer`, you should use `puppeteer` property:

```javascript
const {browser} = require('protractor');
Expand All @@ -140,12 +142,12 @@ you should use `puppeteer` property:

// etc.
```
More information about this class you can find here:

More information about this class you can find here:
* [`class: Puppeteer`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-puppeteer)
2. If Puppeteer was connected by `protractor-puppeteer-plugin`, you should use `cdp` property.
The `cdp` property provides to use all features of Puppeteer after merging with Protractor.

2. If Puppeteer was connected by `protractor-puppeteer-plugin`, you should use `cdp` property. The `cdp` property
provides to use all features of Puppeteer after merging with Protractor.

```javascript
const {browser} = require('protractor');
Expand All @@ -159,8 +161,8 @@ The `cdp` property provides to use all features of Puppeteer after merging with
browser.cdp.page. // --> Page
browser.cdp.browser. // --> Browser
```
More information about this class you can find here:

More information about this class you can find here:
* [`class: Puppeteer`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-puppeteer)
* [`class: Target`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-target)
* [`class: CDPSession`](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-cdpsession)
Expand All @@ -180,10 +182,10 @@ The `cdp` property provides to use all features of Puppeteer after merging with
// If not, will be the default: '%timestamp%_PID_%pid%_chrome_browser_har_log.har'
```

Saved files can be read by Chrome.
Saved files can be read by Chrome.

4. If `browser.restart()` was executed, you need to connect Puppeteer one more time:

```javascript
const {browser} = require('protractor');
const {setup} = require('protractor-puppeteer-plugin');
Expand All @@ -200,27 +202,28 @@ The `cdp` property provides to use all features of Puppeteer after merging with
await browser.lighthouse(url, {flags?, config?, connection?, reportName?});
// The report(s) will stored automatically. Default: './artifacts/lighthouse/' directory; '.html' and '.json' formats.
```

where:
* `url` - The URL to test.
* `flags`- Optional settings for the Lighthouse run. If present, they will override any settings in the config;
> Default flags: `{"port": (!) Determined automatically, "logLevel": "info", "output": ["json", "html"]}`.
**(!) It is not recommended to change the port**.
[Types](https://github.com/GoogleChrome/lighthouse/blob/master/types/externs.d.ts#L151).
* `config` - Configuration for the Lighthouse run. If not present, the default config is used;
> [Default config](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/lr-desktop-config.js#L11),
[Documentation](https://github.com/GoogleChrome/lighthouse/blob/master/docs/configuration.md) and
[Types](https://github.com/GoogleChrome/lighthouse/blob/master/types/config.d.ts#L16).
* `connection` - Custom connection if it's not ChromeProtocol. If not present, the `host` and `port` are used;
> [Source code](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/gather/connections/cri.js)
* `reportName` - If the 'reportName' parameter is passed, the report name will be: '%timestamp%\_PID\_%pid%_%reportName%.%format%'.
If not, will be the default: '%timestamp%\_PID\_%pid%_lighthouse_report.%format%'
* `url` - The URL to test.
* `flags`- Optional settings for the Lighthouse run. If present, they will override any settings in the config;
> Default flags: `{"port": (!) Determined automatically, "logLevel": "info", "output": ["json", "html"]}`.
**(!) It is not recommended to change the port**.
[Types](https://github.com/GoogleChrome/lighthouse/blob/master/types/externs.d.ts#L151).
* `config` - Configuration for the Lighthouse run. If not present, the default config is used;
> [Default config](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/lr-desktop-config.js#L11),
[Documentation](https://github.com/GoogleChrome/lighthouse/blob/master/docs/configuration.md) and
[Types](https://github.com/GoogleChrome/lighthouse/blob/master/types/config.d.ts#L16).
* `connection` - Custom connection if it's not ChromeProtocol. If not present, the `host` and `port` are used;
> [Source code](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/gather/connections/cri.js)
* `reportName` - If the 'reportName' parameter is passed, the report name will be: '%timestamp%\_PID\_%pid%_
%reportName%.%format%'. If not, will be the default: '%timestamp%\_PID\_%pid%_lighthouse_report.%format%'
During the execution Lighthouse opens a new tab, performs necessary actions, closes the tab and generates a report.
More information about this class you can find here:
* [`Lighthouse`](https://github.com/GoogleChrome/lighthouse)
* [`Lighthouse`](https://github.com/GoogleChrome/lighthouse)
### Example:
```javascript
// protractor.conf.js
plugins: [{
Expand Down Expand Up @@ -329,15 +332,15 @@ describe('Example suite', () => {
## How to use in Docker
1. If you would like to use autotests within the same container with `selenium-standalone/chrome`,
you don't need to do anything.
1. If you would like to use autotests within the same container with `selenium-standalone/chrome`, you don't need to do
anything.
2. If you would like to use autotest and `selenium-standalone/chrome` in different containers,
you have to manage a port for Chrome debug protocol.
Since you won’t be able to know on which port the Chrome debugger is available,
and based on Chrome’s policy is prohibited connect to Chrome from the outside.
2. If you would like to use autotest and `selenium-standalone/chrome` in different containers, you have to manage a port
for Chrome debug protocol. Since you won’t be able to know on which port the Chrome debugger is available, and based
on Chrome’s policy is prohibited connect to Chrome from the outside.
To do this, you need to pass the following arguments:
* `--headless`
* `--remote-debugging-address=0.0.0.0`
* `--remote-debugging-port=9222` - with port address you want
Expand All @@ -358,15 +361,18 @@ capabilities: {
}
```
More arguments you can find here:
More arguments you can find here:
* [List of Chromium Command Line Switches](https://peter.sh/experiments/chromium-command-line-switches/)
## Workarounds
1. Error: '**Error: You probably have multiple tabs open to the same origin.**' during `await browser.lighthouse('https://my-site/')`:
1. Error: '**Error: You probably have multiple tabs open to the same origin.**'
during `await browser.lighthouse('https://my-site/')`:
**(!)** This workaround will be applied automatically, if the option `connectToBrowser: true` is set in the `protractor-puppeteer-plugin` config.
More details about the issue: https://github.com/GoogleChrome/lighthouse/issues/3024
**(!)** This workaround will be applied automatically, if the option `connectToBrowser: true` is set in
the `protractor-puppeteer-plugin` config. More details about the
issue: https://github.com/GoogleChrome/lighthouse/issues/3024
```typescript
import {browser} from 'protractor';
Expand All @@ -389,38 +395,41 @@ describe('Lighthouse workaround', () => {
// or
await browser.get('https://angular.io/');
await browser.$('.button.hero-cta').click();

// workaround

async function lighthouse(url) {
const currentUrl = browser.cdp.page.url();

await browser.cdp.browser.newPage();
const [firstPage, secondPage] = await browser.cdp.browser.pages();
await firstPage.close();

await browser.lighthouse(url);

const [tab] = await browser.getAllWindowHandles();
await browser.switchTo().window(tab);
Object.assign(browser.cdp.page, secondPage);

await browser.get(currentUrl); // Now it works
// or
// await browser.cdp.page.goto(currentUrl); // Now it works
}

await lighthouse('https://angular.io/');
});
});
```
## Documentation:
Protractor:
* https://www.protractortest.org
* https://github.com/angular/protractor
Puppeteer:
* https://pptr.dev/
* https://github.com/puppeteer/puppeteer
* https://try-puppeteer.appspot.com/
Expand All @@ -429,9 +438,11 @@ Puppeteer:
* https://developers.google.com/web/tools/puppeteer/examples
Chrome DevTools Protocol:
* https://chromedevtools.github.io/devtools-protocol/
Lighthouse:
* https://github.com/GoogleChrome/lighthouse
* https://developers.google.com/web/tools/lighthouse
* https://github.com/GoogleChrome/lighthouse/blob/master/docs/readme.md#using-programmatically
Expand Down
19 changes: 13 additions & 6 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# Release notes

## 5.2.1 - 2021-02-27

### Added

* Updated the version of NodeJS to 12.

## 5.2.0 - 2020-12-25

### Added

* Updated `@types/puppeteer-core@5.4.0`
* Updated `lighthouse@7.0.0`
> (!) Lighthouse has breaking changes [Release notes](https://github.com/GoogleChrome/lighthouse/releases/tag/v7.0.0)
> (!) Lighthouse has breaking changes [Release notes](https://github.com/GoogleChrome/lighthouse/releases/tag/v7.0.0)
## 5.1.3 - 2020-11-20

Expand All @@ -31,7 +37,7 @@

### Added

* Added 'reportName' parameter to `browser.har.stop()` and `browser.lighthouse()` functions
* Added 'reportName' parameter to `browser.har.stop()` and `browser.lighthouse()` functions

## 5.0.2 - 2020-09-08

Expand All @@ -58,27 +64,28 @@
### Added

* Updated the dependencies to `puppeteer@5.0.0`
> (!) Puppeteer has breaking changes [Release notes](https://github.com/puppeteer/puppeteer/releases/tag/v5.0.0)
> (!) Puppeteer has breaking changes [Release notes](https://github.com/puppeteer/puppeteer/releases/tag/v5.0.0)
## 3.0.0 - 2020-06-23

### Added

* Updated the dependencies to `puppeteer@4.0.0`
> (!) Puppeteer has breaking changes [Release notes](https://github.com/puppeteer/puppeteer/releases/tag/v4.0.0)
> (!) Puppeteer has breaking changes [Release notes](https://github.com/puppeteer/puppeteer/releases/tag/v4.0.0)
## 2.3.1 - 2020-06-11

### Added

* Added a verification whether a 'inline' plugin is present
* Fixed the reference types of protractor
* Fixed the reference types of protractor

## 2.3.0 - 2020-06-07

### Added

* Updated the dependencies to `puppeteer@3.3.0` [Release notes](https://github.com/puppeteer/puppeteer/releases/tag/v3.3.0)
* Updated the dependencies
to `puppeteer@3.3.0` [Release notes](https://github.com/puppeteer/puppeteer/releases/tag/v3.3.0)
* Updated README file

## 2.2.0 - 2020-05-30
Expand Down
5 changes: 4 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ declare module 'protractor' {

public readonly lighthouse: (
url: string,
params?: { flags?: lighthouse.Flags, config?: lighthouse.Config.Json, connection?: lighthouse.Connection, reportName?: string }
params?: {
flags?: lighthouse.Flags, config?: lighthouse.Config.Json,
connection?: lighthouse.Connection, reportName?: string
}
) => Promise<lighthouse.RunnerResult>
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protractor-puppeteer-plugin",
"version": "5.2.0",
"version": "5.2.1",
"description": "Plugin for merging puppeteer with protractor",
"main": "index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -39,7 +39,7 @@
"protractor": "^5.0.0"
},
"engines": {
"node": ">=10.18.1",
"node": ">=12",
"npm": ">=6"
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Lighthouse = require('./lighthouse');
const Puppeteer = require('./puppeteer');
const Endpoint = require('./endpoint');

let {Logger, setLogLevel} = require('./helpers/logger');
const {Logger, setLogLevel} = require('./helpers/logger');
const logger = Logger('Protractor and Puppeteer');

module.exports = async function () {
Expand Down

0 comments on commit 7e44b80

Please sign in to comment.