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 await cmds.saveScreenshotByName(screenshotName);
18 console.log('screenshot ', screenshotName);
19 });
20 if (browser.config.appium)
21 await browser.updateSettings(browser.config.appium);
22 if (browser.config.maximizeWindow) await browser.maximizeWindow();
23 console.log('Ready to spec');
24 },
25 beforeFeature: async function (uri, feature, scenarios) {
26 console.log({featureTags: feature.document.feature.tags});
27 const name = slugify(feature.document.feature.name);
28 const test = {
29 parent: 'Feat',
30 uid: name,
31 title: name,
32 state: 'passed',
33 type: 'test',
34 };
35 console.log('start recording');
36 await cmds.startScreenRecording(test);
37 },
38 afterFeature: async function (uri, feature, scenarios) {
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('stop recording');
48
49 await cmds.stopScreenRecording(test, {
50 error: undefined,
51 result: 0,
52 duration: undefined,
53 passed: scenarios.length,
54 retries: 0,
55 });
56 },
57};
58
59module.exports = config;