@jahia/cypress 5.1.0 → 6.0.0
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.
- package/dist/support/index.d.ts +1 -0
- package/dist/support/index.js +1 -0
- package/dist/support/provisioning/index.d.ts +2 -2
- package/dist/support/provisioning/index.js +2 -2
- package/dist/support/provisioning/installModule.d.ts +11 -0
- package/dist/support/provisioning/installModule.js +25 -0
- package/dist/support/provisioning/runProvisioningScript.d.ts +1 -1
- package/dist/support/provisioning/{uninstallBundle.d.ts → uninstallModule.d.ts} +2 -2
- package/dist/support/provisioning/{uninstallBundle.js → uninstallModule.js} +4 -4
- package/dist/support/registerSupport.js +5 -1
- package/dist/support/testStep.d.ts +27 -0
- package/dist/support/testStep.js +15 -0
- package/dist/utils/Logger.d.ts +46 -0
- package/dist/utils/Logger.js +79 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
- package/src/support/index.ts +1 -0
- package/src/support/provisioning/index.ts +2 -2
- package/src/support/provisioning/installModule.ts +34 -0
- package/src/support/provisioning/runProvisioningScript.ts +1 -1
- package/src/support/provisioning/{uninstallBundle.ts → uninstallModule.ts} +3 -3
- package/src/support/registerSupport.ts +7 -2
- package/src/support/testStep.ts +41 -0
- package/src/utils/Logger.ts +78 -0
- package/src/utils/index.ts +1 -0
- package/dist/support/provisioning/installBundle.d.ts +0 -9
- package/dist/support/provisioning/installBundle.js +0 -15
- package/src/support/provisioning/installBundle.ts +0 -23
package/dist/support/index.d.ts
CHANGED
package/dist/support/index.js
CHANGED
|
@@ -12,5 +12,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
exports.__esModule = true;
|
|
13
13
|
__exportStar(require("./executeGroovy"), exports);
|
|
14
14
|
__exportStar(require("./runProvisioningScript"), exports);
|
|
15
|
-
__exportStar(require("./
|
|
16
|
-
__exportStar(require("./
|
|
15
|
+
__exportStar(require("./installModule"), exports);
|
|
16
|
+
__exportStar(require("./uninstallModule"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
declare global {
|
|
3
|
+
namespace Cypress {
|
|
4
|
+
interface Chainable<Subject> {
|
|
5
|
+
installModule(moduleFile: string): Chainable<Cypress.Response<any>>;
|
|
6
|
+
installAndStartModule(moduleFile: string): Chainable<Cypress.Response<any>>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const installModule: (moduleFile: string) => void;
|
|
11
|
+
export declare const installAndStartModule: (moduleFile: string) => void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.installAndStartModule = exports.installModule = void 0;
|
|
5
|
+
/// <reference types="cypress" />
|
|
6
|
+
var installModule = function (moduleFile) {
|
|
7
|
+
cy.runProvisioningScript({
|
|
8
|
+
script: [{ installModule: moduleFile }],
|
|
9
|
+
files: [{
|
|
10
|
+
fileName: moduleFile,
|
|
11
|
+
type: 'text/plain'
|
|
12
|
+
}]
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.installModule = installModule;
|
|
16
|
+
var installAndStartModule = function (moduleFile) {
|
|
17
|
+
cy.runProvisioningScript({
|
|
18
|
+
script: [{ installAndStartModule: moduleFile }],
|
|
19
|
+
files: [{
|
|
20
|
+
fileName: moduleFile,
|
|
21
|
+
type: 'text/plain'
|
|
22
|
+
}]
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.installAndStartModule = installAndStartModule;
|
|
@@ -3,7 +3,7 @@ import RequestOptions = Cypress.RequestOptions;
|
|
|
3
3
|
declare global {
|
|
4
4
|
namespace Cypress {
|
|
5
5
|
interface Chainable<Subject> {
|
|
6
|
-
runProvisioningScript(params: RunProvisioningScriptParams): Chainable<
|
|
6
|
+
runProvisioningScript(params: RunProvisioningScriptParams): Chainable<unknown>;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
declare global {
|
|
3
3
|
namespace Cypress {
|
|
4
4
|
interface Chainable<Subject> {
|
|
5
|
-
|
|
5
|
+
uninstallModule(moduleSymbolicName: string): Chainable<Cypress.Response<any>>;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const uninstallModule: (moduleSymbolicName: string) => void;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.
|
|
4
|
+
exports.uninstallModule = void 0;
|
|
5
5
|
/// <reference types="cypress" />
|
|
6
|
-
var
|
|
6
|
+
var uninstallModule = function (moduleSymbolicName) {
|
|
7
7
|
cy.runProvisioningScript({
|
|
8
8
|
script: {
|
|
9
|
-
fileContent: '-
|
|
9
|
+
fileContent: '- uninstallModule: "' + moduleSymbolicName + '"\n',
|
|
10
10
|
type: 'application/yaml'
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
|
-
exports.
|
|
14
|
+
exports.uninstallModule = uninstallModule;
|
|
@@ -7,16 +7,20 @@ var login_1 = require("./login");
|
|
|
7
7
|
var logout_1 = require("./logout");
|
|
8
8
|
var fixture_1 = require("./fixture");
|
|
9
9
|
var repeatUntil_1 = require("./repeatUntil");
|
|
10
|
+
var testStep_1 = require("./testStep");
|
|
10
11
|
var registerSupport = function () {
|
|
11
12
|
Cypress.Commands.add('apolloClient', apollo_1.apolloClient);
|
|
12
13
|
Cypress.Commands.add('apollo', { prevSubject: 'optional' }, apollo_1.apollo);
|
|
13
14
|
Cypress.Commands.add('runProvisioningScript', provisioning_1.runProvisioningScript);
|
|
14
15
|
Cypress.Commands.add('executeGroovy', provisioning_1.executeGroovy);
|
|
15
|
-
Cypress.Commands.add('
|
|
16
|
+
Cypress.Commands.add('installModule', provisioning_1.installModule);
|
|
17
|
+
Cypress.Commands.add('installAndStartModule', provisioning_1.installAndStartModule);
|
|
18
|
+
Cypress.Commands.add('uninstallModule', provisioning_1.uninstallModule);
|
|
16
19
|
Cypress.Commands.add('login', login_1.login);
|
|
17
20
|
Cypress.Commands.add('loginAndStoreSession', login_1.loginAndStoreSession);
|
|
18
21
|
Cypress.Commands.add('logout', logout_1.logout);
|
|
19
22
|
Cypress.Commands.add('repeatUntil', repeatUntil_1.repeatUntil);
|
|
20
23
|
Cypress.Commands.overwrite('fixture', fixture_1.fixture);
|
|
24
|
+
Cypress.Commands.add('step', testStep_1.step);
|
|
21
25
|
};
|
|
22
26
|
exports.registerSupport = registerSupport;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extends global Cypress Chainable interface with custom commands from 'commands.js' to avoid TypeScript errors when using them.
|
|
3
|
+
*/
|
|
4
|
+
declare global {
|
|
5
|
+
namespace Cypress {
|
|
6
|
+
interface Chainable<Subject> {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a foldable test-case step with corresponding message in Cypress log
|
|
9
|
+
* @param {string} message - folder's message
|
|
10
|
+
* @param {() => void} func - function to be executed and wrapped into the folder
|
|
11
|
+
* @returns void
|
|
12
|
+
* @example
|
|
13
|
+
* cy.step('Navigate to the destination point', () => {
|
|
14
|
+
* cy.get('selector').click();
|
|
15
|
+
* ...
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* cy.step('Do something', () => {
|
|
19
|
+
* cy.get('element').click();
|
|
20
|
+
* ...
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
step(message: string, func: () => void): void;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export declare const step: (message: string, func: () => void) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.step = void 0;
|
|
4
|
+
var step = function (message, func) {
|
|
5
|
+
cy.then(function () {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
Cypress.log({ groupStart: true, displayName: '[ STEP ]', message: "" + message });
|
|
8
|
+
}).then(function () {
|
|
9
|
+
func();
|
|
10
|
+
}).then(function () {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
Cypress.log({ groupEnd: true, emitOnly: true });
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.step = step;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class to decorate Cypress log messages with different log levels (INFO and DEBUG at the moment).
|
|
3
|
+
* Class contains only static methods and should not be instantiated.
|
|
4
|
+
* @example
|
|
5
|
+
* Log.info('This is an info message');
|
|
6
|
+
* Log.debug('This is a debug message');
|
|
7
|
+
* Log.json('DEBUG', myJSON);
|
|
8
|
+
* Log.info('My info message').then(() => { ... });
|
|
9
|
+
* @note The log level can be set by changing the `Log.LEVEL` variable in the code (default is `INFO`).
|
|
10
|
+
* It tells the logger to log only messages with the given level and above.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Log {
|
|
13
|
+
static LEVEL: string;
|
|
14
|
+
private static levels;
|
|
15
|
+
/**
|
|
16
|
+
* Logs INFO message
|
|
17
|
+
* @param {string} message - log message
|
|
18
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
19
|
+
*/
|
|
20
|
+
static info(message: string): Cypress.Chainable;
|
|
21
|
+
/**
|
|
22
|
+
* Logs DEBUG message
|
|
23
|
+
* @param {string} message - log message
|
|
24
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
25
|
+
*/
|
|
26
|
+
static debug(message: string): Cypress.Chainable;
|
|
27
|
+
/**
|
|
28
|
+
* Logs JSON object with logging level given
|
|
29
|
+
* @param {string} level - log level (e.g. 'INFO', 'DEBUG')
|
|
30
|
+
* @param {string} json - json object to be logged
|
|
31
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
32
|
+
*/
|
|
33
|
+
static json(level: string, json: string): Cypress.Chainable;
|
|
34
|
+
/**
|
|
35
|
+
* Private method to send the log message to Cypress log
|
|
36
|
+
* @param {string} level - log level (e.g. 'INFO', 'DEBUG')
|
|
37
|
+
* @param {string} message - log message
|
|
38
|
+
* @note The method checks if the log level is enabled before sending the message to Cypress log
|
|
39
|
+
* and uses the Cypress.log method to display the message in the Cypress log
|
|
40
|
+
* @note The method is private and should not be called directly
|
|
41
|
+
* Use the public methods (info, debug, error, warning) to send log messages
|
|
42
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
private static _send_;
|
|
46
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.Log = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Helper class to decorate Cypress log messages with different log levels (INFO and DEBUG at the moment).
|
|
6
|
+
* Class contains only static methods and should not be instantiated.
|
|
7
|
+
* @example
|
|
8
|
+
* Log.info('This is an info message');
|
|
9
|
+
* Log.debug('This is a debug message');
|
|
10
|
+
* Log.json('DEBUG', myJSON);
|
|
11
|
+
* Log.info('My info message').then(() => { ... });
|
|
12
|
+
* @note The log level can be set by changing the `Log.LEVEL` variable in the code (default is `INFO`).
|
|
13
|
+
* It tells the logger to log only messages with the given level and above.
|
|
14
|
+
*/
|
|
15
|
+
var Log = /** @class */ (function () {
|
|
16
|
+
function Log() {
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Logs INFO message
|
|
20
|
+
* @param {string} message - log message
|
|
21
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
22
|
+
*/
|
|
23
|
+
Log.info = function (message) {
|
|
24
|
+
return Log._send_('INFO', message);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Logs DEBUG message
|
|
28
|
+
* @param {string} message - log message
|
|
29
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
30
|
+
*/
|
|
31
|
+
Log.debug = function (message) {
|
|
32
|
+
return Log._send_('DEBUG', message);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Logs JSON object with logging level given
|
|
36
|
+
* @param {string} level - log level (e.g. 'INFO', 'DEBUG')
|
|
37
|
+
* @param {string} json - json object to be logged
|
|
38
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
39
|
+
*/
|
|
40
|
+
Log.json = function (level, json) {
|
|
41
|
+
return Log._send_(level, JSON.stringify(json, null, 2));
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Private method to send the log message to Cypress log
|
|
45
|
+
* @param {string} level - log level (e.g. 'INFO', 'DEBUG')
|
|
46
|
+
* @param {string} message - log message
|
|
47
|
+
* @note The method checks if the log level is enabled before sending the message to Cypress log
|
|
48
|
+
* and uses the Cypress.log method to display the message in the Cypress log
|
|
49
|
+
* @note The method is private and should not be called directly
|
|
50
|
+
* Use the public methods (info, debug, error, warning) to send log messages
|
|
51
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
Log._send_ = function (level, message) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
// Check if the log level is valid
|
|
57
|
+
if (!Log.levels.includes(level.toUpperCase())) {
|
|
58
|
+
throw new Error("Log level \"" + level + "\" is not supported. Supported levels are: " + Log.levels.join(', '));
|
|
59
|
+
}
|
|
60
|
+
// Check if the log level is enabled,
|
|
61
|
+
// take into account the log level set in Cypress.env('LOG_LEVEL') and the log level set in the Log.LEVEL variable.
|
|
62
|
+
// If the log level is enabled, send the message to Cypress log.
|
|
63
|
+
if ((Log.levels.includes((_a = Cypress.env('LOG_LEVEL')) === null || _a === void 0 ? void 0 : _a.toUpperCase()) && Log.levels.indexOf(level.toUpperCase()) >= Log.levels.indexOf((_b = Cypress.env('LOG_LEVEL')) === null || _b === void 0 ? void 0 : _b.toUpperCase())) ||
|
|
64
|
+
Log.levels.indexOf(level.toUpperCase()) >= Log.levels.indexOf(Log.LEVEL)) {
|
|
65
|
+
// Send the message to Cypress log
|
|
66
|
+
// use cy.then() to ensure that the log message is sent in the correct order
|
|
67
|
+
// and use cy.wrap() to return the Cypress chainable object
|
|
68
|
+
return cy.then(function () {
|
|
69
|
+
Cypress.log({ displayName: "[ " + level.toUpperCase() + " ]", message: "" + message });
|
|
70
|
+
}).then(cy.wrap);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// The default log level is set to 'INFO' and can be changed by setting the Log.LEVEL variable in the code
|
|
74
|
+
Log.LEVEL = 'INFO';
|
|
75
|
+
// The log levels are defined in the levels array and are ordered from the lowest to the highest priority
|
|
76
|
+
Log.levels = ['DEBUG', 'INFO'];
|
|
77
|
+
return Log;
|
|
78
|
+
}());
|
|
79
|
+
exports.Log = Log;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
package/src/support/index.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
2
|
+
|
|
3
|
+
// Load type definitions that come with Cypress module
|
|
4
|
+
/// <reference types="cypress" />
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
namespace Cypress {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
interface Chainable<Subject> {
|
|
10
|
+
installModule(moduleFile: string): Chainable<Cypress.Response<any>>;
|
|
11
|
+
installAndStartModule(moduleFile: string): Chainable<Cypress.Response<any>>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const installModule = function (moduleFile: string): void {
|
|
17
|
+
cy.runProvisioningScript({
|
|
18
|
+
script: [{installModule: moduleFile}],
|
|
19
|
+
files: [{
|
|
20
|
+
fileName: moduleFile,
|
|
21
|
+
type: 'text/plain'
|
|
22
|
+
}]
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const installAndStartModule = function (moduleFile: string): void {
|
|
27
|
+
cy.runProvisioningScript({
|
|
28
|
+
script: [{installAndStartModule: moduleFile}],
|
|
29
|
+
files: [{
|
|
30
|
+
fileName: moduleFile,
|
|
31
|
+
type: 'text/plain'
|
|
32
|
+
}]
|
|
33
|
+
});
|
|
34
|
+
};
|
|
@@ -8,7 +8,7 @@ declare global {
|
|
|
8
8
|
namespace Cypress {
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
10
|
interface Chainable<Subject> {
|
|
11
|
-
runProvisioningScript(params: RunProvisioningScriptParams): Chainable<
|
|
11
|
+
runProvisioningScript(params: RunProvisioningScriptParams): Chainable<unknown>;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -7,15 +7,15 @@ declare global {
|
|
|
7
7
|
namespace Cypress {
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
9
|
interface Chainable<Subject> {
|
|
10
|
-
|
|
10
|
+
uninstallModule(moduleSymbolicName: string): Chainable<Cypress.Response<any>>
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const
|
|
15
|
+
export const uninstallModule = function (moduleSymbolicName: string): void {
|
|
16
16
|
cy.runProvisioningScript({
|
|
17
17
|
script: {
|
|
18
|
-
fileContent: '-
|
|
18
|
+
fileContent: '- uninstallModule: "' + moduleSymbolicName + '"\n',
|
|
19
19
|
type: 'application/yaml'
|
|
20
20
|
}
|
|
21
21
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {apollo, apolloClient} from './apollo';
|
|
2
|
-
import {executeGroovy, runProvisioningScript,
|
|
2
|
+
import {executeGroovy, runProvisioningScript, installModule, installAndStartModule, uninstallModule} from './provisioning';
|
|
3
3
|
import {login, loginAndStoreSession} from './login';
|
|
4
4
|
import {logout} from './logout';
|
|
5
5
|
import {fixture} from './fixture';
|
|
6
6
|
import {repeatUntil} from './repeatUntil';
|
|
7
|
+
import {step} from './testStep';
|
|
7
8
|
|
|
8
9
|
export const registerSupport = (): void => {
|
|
9
10
|
Cypress.Commands.add('apolloClient', apolloClient);
|
|
@@ -11,7 +12,9 @@ export const registerSupport = (): void => {
|
|
|
11
12
|
|
|
12
13
|
Cypress.Commands.add('runProvisioningScript', runProvisioningScript);
|
|
13
14
|
Cypress.Commands.add('executeGroovy', executeGroovy);
|
|
14
|
-
Cypress.Commands.add('
|
|
15
|
+
Cypress.Commands.add('installModule', installModule);
|
|
16
|
+
Cypress.Commands.add('installAndStartModule', installAndStartModule);
|
|
17
|
+
Cypress.Commands.add('uninstallModule', uninstallModule);
|
|
15
18
|
|
|
16
19
|
Cypress.Commands.add('login', login);
|
|
17
20
|
Cypress.Commands.add('loginAndStoreSession', loginAndStoreSession);
|
|
@@ -19,4 +22,6 @@ export const registerSupport = (): void => {
|
|
|
19
22
|
Cypress.Commands.add('repeatUntil', repeatUntil);
|
|
20
23
|
|
|
21
24
|
Cypress.Commands.overwrite('fixture', fixture);
|
|
25
|
+
|
|
26
|
+
Cypress.Commands.add('step', step);
|
|
22
27
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
/**
|
|
3
|
+
* Extends global Cypress Chainable interface with custom commands from 'commands.js' to avoid TypeScript errors when using them.
|
|
4
|
+
*/
|
|
5
|
+
declare global {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
7
|
+
namespace Cypress {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
interface Chainable<Subject> {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a foldable test-case step with corresponding message in Cypress log
|
|
12
|
+
* @param {string} message - folder's message
|
|
13
|
+
* @param {() => void} func - function to be executed and wrapped into the folder
|
|
14
|
+
* @returns void
|
|
15
|
+
* @example
|
|
16
|
+
* cy.step('Navigate to the destination point', () => {
|
|
17
|
+
* cy.get('selector').click();
|
|
18
|
+
* ...
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* cy.step('Do something', () => {
|
|
22
|
+
* cy.get('element').click();
|
|
23
|
+
* ...
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
step (message: string, func: () => void): void;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const step = (message: string, func: () => void): void => {
|
|
32
|
+
cy.then(() => {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
Cypress.log({groupStart: true, displayName: '[ STEP ]', message: `${message}`});
|
|
35
|
+
}).then(() => {
|
|
36
|
+
func();
|
|
37
|
+
}).then(() => {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
Cypress.log({groupEnd: true, emitOnly: true});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class to decorate Cypress log messages with different log levels (INFO and DEBUG at the moment).
|
|
3
|
+
* Class contains only static methods and should not be instantiated.
|
|
4
|
+
* @example
|
|
5
|
+
* Log.info('This is an info message');
|
|
6
|
+
* Log.debug('This is a debug message');
|
|
7
|
+
* Log.json('DEBUG', myJSON);
|
|
8
|
+
* Log.info('My info message').then(() => { ... });
|
|
9
|
+
* @note The log level can be set by changing the `Log.LEVEL` variable in the code (default is `INFO`).
|
|
10
|
+
* It tells the logger to log only messages with the given level and above.
|
|
11
|
+
*/
|
|
12
|
+
export class Log {
|
|
13
|
+
// The default log level is set to 'INFO' and can be changed by setting the Log.LEVEL variable in the code
|
|
14
|
+
static LEVEL = 'INFO';
|
|
15
|
+
// The log levels are defined in the levels array and are ordered from the lowest to the highest priority
|
|
16
|
+
private static levels = ['DEBUG', 'INFO'];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Logs INFO message
|
|
20
|
+
* @param {string} message - log message
|
|
21
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
22
|
+
*/
|
|
23
|
+
static info(message: string): Cypress.Chainable {
|
|
24
|
+
return Log._send_('INFO', message);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Logs DEBUG message
|
|
29
|
+
* @param {string} message - log message
|
|
30
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
31
|
+
*/
|
|
32
|
+
static debug(message: string): Cypress.Chainable {
|
|
33
|
+
return Log._send_('DEBUG', message);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Logs JSON object with logging level given
|
|
38
|
+
* @param {string} level - log level (e.g. 'INFO', 'DEBUG')
|
|
39
|
+
* @param {string} json - json object to be logged
|
|
40
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
41
|
+
*/
|
|
42
|
+
static json(level: string, json: string): Cypress.Chainable {
|
|
43
|
+
return Log._send_(level, JSON.stringify(json, null, 2));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Private method to send the log message to Cypress log
|
|
48
|
+
* @param {string} level - log level (e.g. 'INFO', 'DEBUG')
|
|
49
|
+
* @param {string} message - log message
|
|
50
|
+
* @note The method checks if the log level is enabled before sending the message to Cypress log
|
|
51
|
+
* and uses the Cypress.log method to display the message in the Cypress log
|
|
52
|
+
* @note The method is private and should not be called directly
|
|
53
|
+
* Use the public methods (info, debug, error, warning) to send log messages
|
|
54
|
+
* @returns {Cypress.Chainable} - Cypress chainable object
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
private static _send_(level: string, message: string): Cypress.Chainable {
|
|
58
|
+
// Check if the log level is valid
|
|
59
|
+
if (!Log.levels.includes(level.toUpperCase())) {
|
|
60
|
+
throw new Error(`Log level "${level}" is not supported. Supported levels are: ${Log.levels.join(', ')}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Check if the log level is enabled,
|
|
64
|
+
// take into account the log level set in Cypress.env('LOG_LEVEL') and the log level set in the Log.LEVEL variable.
|
|
65
|
+
// If the log level is enabled, send the message to Cypress log.
|
|
66
|
+
if (
|
|
67
|
+
(Log.levels.includes(Cypress.env('LOG_LEVEL')?.toUpperCase()) && Log.levels.indexOf(level.toUpperCase()) >= Log.levels.indexOf(Cypress.env('LOG_LEVEL')?.toUpperCase())) ||
|
|
68
|
+
Log.levels.indexOf(level.toUpperCase()) >= Log.levels.indexOf(Log.LEVEL)
|
|
69
|
+
) {
|
|
70
|
+
// Send the message to Cypress log
|
|
71
|
+
// use cy.then() to ensure that the log message is sent in the correct order
|
|
72
|
+
// and use cy.wrap() to return the Cypress chainable object
|
|
73
|
+
return cy.then(() => {
|
|
74
|
+
Cypress.log({displayName: `[ ${level.toUpperCase()} ]`, message: `${message}`});
|
|
75
|
+
}).then(cy.wrap);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.installBundle = void 0;
|
|
5
|
-
/// <reference types="cypress" />
|
|
6
|
-
var installBundle = function (bundleFile) {
|
|
7
|
-
cy.runProvisioningScript({
|
|
8
|
-
script: [{ installBundle: bundleFile }],
|
|
9
|
-
files: [{
|
|
10
|
-
fileName: bundleFile,
|
|
11
|
-
type: 'text/plain'
|
|
12
|
-
}]
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
exports.installBundle = installBundle;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
2
|
-
|
|
3
|
-
// Load type definitions that come with Cypress module
|
|
4
|
-
/// <reference types="cypress" />
|
|
5
|
-
|
|
6
|
-
declare global {
|
|
7
|
-
namespace Cypress {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
-
interface Chainable<Subject> {
|
|
10
|
-
installBundle(bundleFile: string): Chainable<Cypress.Response<any>>
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const installBundle = function (bundleFile: string): void {
|
|
16
|
-
cy.runProvisioningScript({
|
|
17
|
-
script: [{installBundle: bundleFile}],
|
|
18
|
-
files: [{
|
|
19
|
-
fileName: bundleFile,
|
|
20
|
-
type: 'text/plain'
|
|
21
|
-
}]
|
|
22
|
-
});
|
|
23
|
-
};
|