Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
7 changes: 4 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false
}
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gbisogno/cdp-utils",
"version": "1.3.10",
"version": "1.4.0",
"description": "A set of utilities/wrapper for Test Automation or Performance testing on top of Chrome DevTools Protocol",
"repository": {
"type": "git",
Expand All @@ -11,8 +11,9 @@
"scripts": {
"build": "tsc",
"test": "jest",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"lint": "tslint -p tsconfig.json",
"format": "prettier --write src/**/*.ts",
"prebuild": "npm run lint && npm run format",
"lint": "eslint --fix ./src/**/*.ts",
"doc": "compodoc -p --tsconfig tsconfig.json -s"
},
"keywords": [
Expand All @@ -33,14 +34,17 @@
"@types/chrome-remote-interface": "^0.31.4",
"@types/jest": "^27.5.2",
"@types/selenium-webdriver": "^4.0.16",
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"chromedriver": "latest",
"endpoint-utils": "^1.0.2",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^27.4.5",
"prettier": "^2.4.1",
"selenium-webdriver": "^4.0.0",
"ts-jest": "^27.1.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typed-query-selector": "^2.6.1",
"typescript": "^4.4.4"
},
Expand Down
48 changes: 23 additions & 25 deletions src/__tests__/browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
import { Builder } from "selenium-webdriver";
import * as chrome from "selenium-webdriver/chrome";
import { Builder } from 'selenium-webdriver';
import * as chrome from 'selenium-webdriver/chrome';
import 'chromedriver';
import { CDPClient } from '../cdpClient';
import { GooglePage } from '../pages/googlePage';
import { Browser } from '../browser';
import { cdpConfig } from "../config/cdpConfig";
import { cdpConfig } from '../config/cdpConfig';
import { getFreePort } from 'endpoint-utils';

jest.setTimeout(cdpConfig.maxTimeout);

test('Test Browser', async () => {
const port = await getFreePort();
const options = new chrome.Options();

const port = await getFreePort();
const options = new chrome.Options();
options.addArguments(`--remote-debugging-port=${port}`);

options.addArguments(`--remote-debugging-port=${port}`);
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();

const driver = await new Builder().forBrowser('chrome')
.setChromeOptions(options)
.build();
const googlePage = new GooglePage(driver);

const googlePage = new GooglePage(driver);
const cdpClient = new CDPClient();
await cdpClient.init(port);

const cdpClient = new CDPClient();
await cdpClient.init(port);

const browser = new Browser(cdpClient);
const browser = new Browser(cdpClient);

await driver.get("https://www.google.com");
await driver.get('https://www.google.com');

const url = await driver.getCurrentUrl();
await browser.grantPermissions({
origin: url,
permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
});
const url = await driver.getCurrentUrl();
await browser.grantPermissions({
origin: url,
permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
});

await googlePage.searchFromClipboard();
await googlePage.searchFromClipboard();

await cdpClient.close();
await cdpClient.close();

await driver.quit();
await driver.quit();
});


47 changes: 23 additions & 24 deletions src/__tests__/lighthouse.tests.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
import { Builder } from "selenium-webdriver";
import * as chrome from "selenium-webdriver/chrome";
import { Builder } from 'selenium-webdriver';
import * as chrome from 'selenium-webdriver/chrome';
import 'chromedriver';
import { GooglePage } from '../pages/googlePage';
import { Lighthouse } from '../lighthouse';
import { getFreePort } from 'endpoint-utils';
import * as DesktopConfig from 'lighthouse/lighthouse-core/config/desktop-config.js';
import { cdpConfig } from "../config/cdpConfig";
import { cdpConfig } from '../config/cdpConfig';

jest.setTimeout(cdpConfig.maxTimeout);

test('Test Lighthouse', async () => {
const port = await getFreePort();
const options = new chrome.Options();

const port = await getFreePort();
const options = new chrome.Options();
options.addArguments(`--remote-debugging-port=${port}`);
options.excludeSwitches('--enable-logging');

options.addArguments(`--remote-debugging-port=${port}`);
options.excludeSwitches('--enable-logging');
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();

const driver = await new Builder().forBrowser('chrome')
.setChromeOptions(options)
.build();
const googlePage = new GooglePage(driver);

const googlePage = new GooglePage(driver);
const lighthouse = new Lighthouse(port);

const lighthouse = new Lighthouse(port);
await lighthouse.initWorkFlow('Google search', DesktopConfig.settings);

await lighthouse.initWorkFlow('Google search', DesktopConfig.settings);
await lighthouse.navigate('https://www.google.com');

await lighthouse.navigate("https://www.google.com");
await lighthouse.startTrace('search operation');

await lighthouse.startTrace('search operation');
await googlePage.search('test');

await googlePage.search('test');
const res = await lighthouse.stopTrace();

const res = await lighthouse.stopTrace();
await driver.quit();

await driver.quit();

await lighthouse.generateFlowReport('lighthouse.html');

res.forEach((step) => {
expect(step.lhr.categories.performance.score).toBeGreaterThanOrEqual(0.8);
})
await lighthouse.generateFlowReport('lighthouse.html');

res.forEach((step) => {
expect(step.lhr.categories.performance.score).toBeGreaterThanOrEqual(0.8);
});
});
46 changes: 22 additions & 24 deletions src/__tests__/network.test.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
import { Builder } from "selenium-webdriver";
import * as chrome from "selenium-webdriver/chrome";
import { Builder } from 'selenium-webdriver';
import * as chrome from 'selenium-webdriver/chrome';
import 'chromedriver';
import { GooglePage } from '../pages/googlePage';
import { Network } from '../network';
import { CDPClient } from '../cdpClient';
import { getFreePort } from 'endpoint-utils';
import { Har } from "har-format";
import { cdpConfig } from "../config/cdpConfig";
import { Har } from 'har-format';
import { cdpConfig } from '../config/cdpConfig';

jest.setTimeout(cdpConfig.maxTimeout);

test('Test Network', async () => {
const port = await getFreePort();
const options = new chrome.Options();

const port = await getFreePort();
const options = new chrome.Options();
options.addArguments(`--remote-debugging-port=${port}`);

options.addArguments(`--remote-debugging-port=${port}`);
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();

const driver = await new Builder().forBrowser('chrome')
.setChromeOptions(options)
.build();
const googlePage = new GooglePage(driver);

const googlePage = new GooglePage(driver);
const cdpClient = new CDPClient();
await cdpClient.init(port);

const cdpClient = new CDPClient();
await cdpClient.init(port);
const network = new Network(cdpClient, 'network.har');

const network = new Network(cdpClient, 'network.har');
await network.startTrace();

await network.startTrace();
await driver.get('https://www.google.com');

await driver.get("https://www.google.com");
await googlePage.search('test');

await googlePage.search('test');
const networkResults: Har = await network.stopTrace();
expect(networkResults.log.entries.length).toBeGreaterThan(0);

const networkResults: Har = await network.stopTrace();
expect(networkResults.log.entries.length).toBeGreaterThan(0);

await cdpClient.close();

await driver.quit()
await cdpClient.close();

await driver.quit();
});

50 changes: 26 additions & 24 deletions src/__tests__/performance.test.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
import { Builder } from "selenium-webdriver";
import * as chrome from "selenium-webdriver/chrome";
import { Builder } from 'selenium-webdriver';
import * as chrome from 'selenium-webdriver/chrome';
import 'chromedriver';
import { GooglePage } from '../pages/googlePage';
import { Performance } from '../performance';
import { CDPClient } from '../cdpClient';
import { getFreePort } from 'endpoint-utils';
import { cdpConfig } from "../config/cdpConfig";
import { cdpConfig } from '../config/cdpConfig';

jest.setTimeout(cdpConfig.maxTimeout);

test('Test Performance', async () => {
const port = await getFreePort();
const options = new chrome.Options();

const port = await getFreePort();
const options = new chrome.Options();
options.addArguments(`--remote-debugging-port=${port}`);

options.addArguments(`--remote-debugging-port=${port}`);
const driver = await new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();

const driver = await new Builder().forBrowser('chrome')
.setChromeOptions(options)
.build();
const googlePage = new GooglePage(driver);

const googlePage = new GooglePage(driver);
const cdpClient = new CDPClient();
await cdpClient.init(port);

const cdpClient = new CDPClient();
await cdpClient.init(port);
const performance = new Performance(
cdpClient,
'startTrace.json',
'endTrace.json'
);

const performance = new Performance(cdpClient, 'startTrace.json', 'endTrace.json');
const perfStartResults = await performance.startTrace();

const perfStartResults = await performance.startTrace();
await driver.get('https://www.google.com');

await driver.get("https://www.google.com");
await googlePage.search('test');

await googlePage.search('test');
const perfEndResults = await performance.stopTrace();

const perfEndResults = await performance.stopTrace();
expect(perfStartResults.metrics.length).toBeGreaterThan(0);
expect(perfEndResults.metrics.length).toBeGreaterThan(0);

expect(perfStartResults.metrics.length).toBeGreaterThan(0);
expect(perfEndResults.metrics.length).toBeGreaterThan(0);

await cdpClient.close();

await driver.quit()
await cdpClient.close();

await driver.quit();
});

Loading