@testring/plugin-selenium-driver 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ const deepmerge = require("deepmerge");
15
15
  const child_process_1 = require("@testring/child-process");
16
16
  const logger_1 = require("@testring/logger");
17
17
  const devtool_extension_1 = require("@testring/devtool-extension");
18
+ const code_coverage_client_1 = require("@nullcc/code-coverage-client");
18
19
  // Stupidly needed thing for making our own requests
19
20
  const _webdriverReq = require('webdriver/build/request');
20
21
  const WebDriverRequest = _webdriverReq.default;
@@ -31,6 +32,7 @@ const DEFAULT_CONFIG = {
31
32
  args: [],
32
33
  },
33
34
  },
35
+ cdpCoverage: false
34
36
  };
35
37
  function delay(timeout) {
36
38
  return new Promise((resolve) => setTimeout(() => resolve(), timeout));
@@ -266,14 +268,57 @@ class SeleniumPlugin {
266
268
  throw Error('Session can not be null');
267
269
  }
268
270
  const customClient = this.addCustromMethods(client);
271
+ let cdpCoverageCollector;
272
+ if (this.config.cdpCoverage) {
273
+ this.logger.debug('Started to init cdp coverage....');
274
+ cdpCoverageCollector = yield this.enableCDPCoverageClient(client);
275
+ this.logger.debug('ended to init cdp coverage....');
276
+ }
269
277
  this.browserClients.set(applicant, {
270
278
  client: customClient,
271
279
  sessionId,
272
280
  initTime: Date.now(),
281
+ cdpCoverageCollector: cdpCoverageCollector
282
+ ? cdpCoverageCollector
283
+ : null,
273
284
  });
274
285
  this.logger.debug(`Started session for applicant: ${applicant}. Session id: ${sessionId}`);
275
286
  });
276
287
  }
288
+ enableCDPCoverageClient(client) {
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ if (this.config.host === undefined) {
291
+ return null;
292
+ }
293
+ //accurate
294
+ if (!client.capabilities['se:cdp']) {
295
+ return null;
296
+ }
297
+ const cdpAddress = client.capabilities['se:cdp'];
298
+ const collector = new code_coverage_client_1.CDPCoverageCollector({
299
+ wsEndpoint: cdpAddress,
300
+ });
301
+ yield collector.init();
302
+ yield collector.start();
303
+ return collector;
304
+ });
305
+ }
306
+ getCdpCoverageFile(applicant) {
307
+ return __awaiter(this, void 0, void 0, function* () {
308
+ const clientData = this.browserClients.get(applicant);
309
+ this.logger.debug(`start upload coverage for applicant ${applicant}`);
310
+ if (!clientData) {
311
+ return;
312
+ }
313
+ const coverageCollector = clientData.cdpCoverageCollector;
314
+ if (!coverageCollector) {
315
+ return;
316
+ }
317
+ const { coverage } = yield coverageCollector.collect();
318
+ yield coverageCollector.stop();
319
+ return [Buffer.from(JSON.stringify(coverage))];
320
+ });
321
+ }
277
322
  addCustromMethods(client) {
278
323
  // Creating our delete selenium session to be able to close
279
324
  // session if it's id is changed while we are running test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testring/plugin-selenium-driver",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "main": "./dist/index.js",
5
5
  "typings": "./src/index.ts",
6
6
  "repository": {
@@ -10,11 +10,12 @@
10
10
  "author": "RingCentral",
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
- "@testring/child-process": "0.6.1",
14
- "@testring/devtool-extension": "0.6.1",
15
- "@testring/logger": "0.6.1",
16
- "@testring/plugin-api": "0.6.1",
17
- "@testring/types": "0.6.1",
13
+ "@nullcc/code-coverage-client": "1.4.2",
14
+ "@testring/child-process": "0.6.3",
15
+ "@testring/devtool-extension": "0.6.3",
16
+ "@testring/logger": "0.6.3",
17
+ "@testring/plugin-api": "0.6.3",
18
+ "@testring/types": "0.6.3",
18
19
  "@types/deepmerge": "2.2.0",
19
20
  "@types/node": "18.11.18",
20
21
  "chromedriver": "*",
@@ -9,6 +9,7 @@ import * as deepmerge from 'deepmerge';
9
9
  import {spawn} from '@testring/child-process';
10
10
  import {loggerClient} from '@testring/logger';
11
11
  import {absoluteExtensionPath} from '@testring/devtool-extension';
12
+ import {CDPCoverageCollector} from '@nullcc/code-coverage-client';
12
13
 
13
14
  import type {Cookie} from '@wdio/protocols';
14
15
  import type {
@@ -32,6 +33,7 @@ type browserClientItem = {
32
33
  client: BrowserObjectCustom;
33
34
  sessionId: string;
34
35
  initTime: number;
36
+ cdpCoverageCollector: CDPCoverageCollector;
35
37
  };
36
38
 
37
39
  const DEFAULT_CONFIG: SeleniumPluginConfig = {
@@ -47,6 +49,7 @@ const DEFAULT_CONFIG: SeleniumPluginConfig = {
47
49
  args: [] as string[],
48
50
  },
49
51
  },
52
+ cdpCoverage: false
50
53
  };
51
54
 
52
55
  function delay(timeout) {
@@ -360,10 +363,19 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {
360
363
  client as BrowserObjectCustom,
361
364
  );
362
365
 
366
+ let cdpCoverageCollector;
367
+ if (this.config.cdpCoverage) {
368
+ this.logger.debug('Started to init cdp coverage....');
369
+ cdpCoverageCollector = await this.enableCDPCoverageClient(client);
370
+ this.logger.debug('ended to init cdp coverage....');
371
+ }
363
372
  this.browserClients.set(applicant, {
364
373
  client: customClient,
365
374
  sessionId,
366
375
  initTime: Date.now(),
376
+ cdpCoverageCollector: cdpCoverageCollector
377
+ ? cdpCoverageCollector
378
+ : null,
367
379
  });
368
380
 
369
381
  this.logger.debug(
@@ -371,6 +383,38 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {
371
383
  );
372
384
  }
373
385
 
386
+ private async enableCDPCoverageClient(client) {
387
+ if (this.config.host === undefined) {
388
+ return null;
389
+ }
390
+ //accurate
391
+ if (!client.capabilities['se:cdp']) {
392
+ return null;
393
+ }
394
+ const cdpAddress = client.capabilities['se:cdp'];
395
+ const collector = new CDPCoverageCollector({
396
+ wsEndpoint: cdpAddress,
397
+ });
398
+ await collector.init();
399
+ await collector.start();
400
+ return collector;
401
+ }
402
+
403
+ public async getCdpCoverageFile(applicant: string) {
404
+ const clientData = this.browserClients.get(applicant);
405
+ this.logger.debug(`start upload coverage for applicant ${applicant}`);
406
+ if (!clientData) {
407
+ return;
408
+ }
409
+ const coverageCollector = clientData.cdpCoverageCollector;
410
+ if (!coverageCollector) {
411
+ return;
412
+ }
413
+ const {coverage} = await coverageCollector.collect();
414
+ await coverageCollector.stop();
415
+ return [Buffer.from(JSON.stringify(coverage))];
416
+ }
417
+
374
418
  protected addCustromMethods(
375
419
  client: BrowserObjectCustom,
376
420
  ): BrowserObjectCustom {
@@ -855,6 +899,7 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {
855
899
 
856
900
  return client.getWindowHandles();
857
901
  }
902
+
858
903
  // @deprecated
859
904
  public async windowHandles(applicant: string) {
860
905
  return this.getTabIds(applicant);
package/src/types.ts CHANGED
@@ -7,4 +7,5 @@ export type SeleniumPluginConfig = RemoteOptions & {
7
7
  clientTimeout: number;
8
8
  host?: string; // fallback for configuration. In WebdriverIO 5 field host renamed to hostname
9
9
  desiredCapabilities?: WebDriver.DesiredCapabilities[]; // fallback for configuration. In WebdriverIO 5 field renamed
10
+ cdpCoverage: boolean;
10
11
  };