all repos — caroster @ 9706a05b8adf4b0adf97299733cfd9ea2c457a62

[Octree] Group carpool to your event https://caroster.io

e2e/hooks/index.js (view raw)

 1'use strict';
 2
 3/* global browser */
 4
 5const cmds = require('wdio-screen-commands');
 6const slugify = require('slugify');
 7
 8const {Scene} = require('../test/pages/utils/Scene');
 9/* eslint-disable jsdoc/valid-types */
10/** @type WebdriverIO.HookFunctions */
11const config = {
12  before: async () => {
13    global.uuidv4 = require('uuid').v4;
14    global.SCENE = Scene;
15    browser.addCommand('saveScreenshotByName', async screenshotName => {
16      console.log('New screen shots');
17      if (Scene.feature) {
18        Scene.screenShotCount++;
19        screenshotName =
20          slugify(Scene.feature.document.feature.name) +
21          '_' +
22          (Scene.screenShotCount < 10
23            ? '0' + Scene.screenShotCount
24            : Scene.screenShotCount) +
25          ' ' +
26          screenshotName;
27      }
28      await cmds.saveScreenshotByName(screenshotName);
29      console.log('screenshot ', screenshotName);
30    });
31    if (browser.config.appium)
32      await browser.updateSettings(browser.config.appium);
33    if (browser.config.maximizeWindow) await browser.maximizeWindow();
34    console.log('Ready to spec');
35  },
36  beforeFeature: async function (uri, feature, scenarios) {
37    Scene.feature = feature;
38    Scene.screenShotCount = 0;
39    const name = slugify(feature.document.feature.name);
40    const test = {
41      parent: 'Feat',
42      uid: name,
43      title: name,
44      state: 'passed',
45      type: 'test',
46    };
47    console.log('start recording');
48    await cmds.startScreenRecording(test);
49  },
50  afterFeature: async function (uri, feature, scenarios) {
51    const name = slugify(feature.document.feature.name);
52    const test = {
53      parent: 'Feat',
54      uid: name,
55      title: name,
56      state: 'passed',
57      type: 'test',
58    };
59    console.log('stop recording');
60
61    await cmds.stopScreenRecording(test, {
62      error: undefined,
63      result: 0,
64      duration: undefined,
65      passed: scenarios.length,
66      retries: 0,
67    });
68    Scene.feature = undefined;
69  },
70};
71
72module.exports = config;