@cuppet/core 1.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.
@@ -0,0 +1,98 @@
1
+ const { Given, When, Then } = require('@cucumber/cucumber');
2
+ const utils = require('../../../src/elementInteraction');
3
+ const main = require('../../../src/mainFunctions');
4
+ const dataStorage = require('../../../src/dataStorage');
5
+ const config = require('config');
6
+
7
+ Given('I go to {string}', async function (path) {
8
+ const pathToVisit = await dataStorage.checkForMultipleVariables(path);
9
+ await main.visitPath(this.page, pathToVisit);
10
+ });
11
+ Given('I go to {string} page', async function (path) {
12
+ const pathFromConfig = config.get(path);
13
+ await main.visitPath(this.page, pathFromConfig);
14
+ });
15
+ Given('I go to current page plus {string}', async function (path) {
16
+ await main.visitCurrentPathPlus(this.page, path);
17
+ });
18
+ Given('I go to {string} path of {string} page', async function (path, page) {
19
+ const configPage = await config.get(page);
20
+ const checkedPath = await dataStorage.checkForVariable(path);
21
+ await main.visitPath(this.page, configPage + checkedPath);
22
+ });
23
+ Given('I visit the saved path {string}', async function (path) {
24
+ const savedPath = dataStorage.getVariable(path);
25
+ await main.visitPath(this.page, savedPath);
26
+ });
27
+ Given('I visit saved path page', async function () {
28
+ const path = await dataStorage.getVariable('path');
29
+ await main.visitPath(this.page, path);
30
+ });
31
+ Given('I log in', async function () {
32
+ const userName = config.get('credentials.username');
33
+ const password = config.get('credentials.password');
34
+ await utils.fillField(this.page, this.commonFields['Name'], userName);
35
+ await utils.fillField(this.page, this.commonFields['Pass'], password);
36
+ const navigationPromise = this.page.waitForNavigation();
37
+ await utils.click(this.page, this.commonFields['Submit']);
38
+ await navigationPromise;
39
+ });
40
+ Given('I log in as {string} {string}', async function (username, password) {
41
+ await utils.fillField(this.page, this.commonFields['Name'], username);
42
+ await utils.fillField(this.page, this.commonFields['Pass'], password);
43
+ const navigationPromise = this.page.waitForNavigation();
44
+ await utils.click(this.page, this.commonFields['Submit']);
45
+ await navigationPromise;
46
+ });
47
+ Given('I follow {string}', async function (text) {
48
+ await utils.followLink(this.page, text);
49
+ });
50
+ Given('I reload the page', async function () {
51
+ await main.reloadPage(this.page);
52
+ });
53
+ Given('I reload the current page with GET parameters {string}', async function (params) {
54
+ await main.reloadPageWithParams(this.page, params);
55
+ });
56
+ Given(
57
+ 'I receive the following status code {string} when requesting the {string} path of the {string} page',
58
+ async function (code, path, page) {
59
+ const configPage = await config.get(page);
60
+ await main.validateStatusCode(this.page, code, configPage + path);
61
+ }
62
+ );
63
+ Given('I open new tab with {string} url', async function (url) {
64
+ this.page = await main.openNewTab(this.browser, url);
65
+ });
66
+ When('I should be on {string} page', async function (page) {
67
+ const configPage = await config.get(page);
68
+ main.validatePath(this.page, configPage);
69
+ });
70
+ When('I should be on the {string} path of {string} page', async function (path, page) {
71
+ const configPage = await config.get(page);
72
+ main.validatePath(this.page, configPage + path);
73
+ });
74
+ When('I should be on a page with alias ending in {string}', async function (path) {
75
+ main.validatePathEnding(this.page, path);
76
+ });
77
+ Then('I should see the header {string} with value {string}', async function (header, value) {
78
+ await main.validatePageResponseHeaders(this.page, header, value);
79
+ });
80
+ Then('I verify that {string} cookie {string} present', async function (cookieName, presence) {
81
+ const stringToBool = {
82
+ is: true,
83
+ 'is not': false,
84
+ };
85
+ await main.verifyCookiePresence(this.page, cookieName, stringToBool[presence]);
86
+ });
87
+ Given('I set viewport size to {string}', async function (resolution) {
88
+ await main.setViewport(this.page, resolution);
89
+ });
90
+ Then('I {string} the alert dialog with text {string}', async function (action, expectedText) {
91
+ const accept = action.toLowerCase() === 'accept' ? true : false;
92
+ await main.handleAlert(this.page, accept, expectedText);
93
+ });
94
+
95
+ Then('I {string} the alert dialog', async function (action) {
96
+ const accept = action.toLowerCase() === 'accept' ? true : false;
97
+ await main.handleAlert(this.page, accept);
98
+ });
@@ -0,0 +1,79 @@
1
+ const { Given, When, Then } = require('@cucumber/cucumber');
2
+ const helper = require('../../../src/helperFunctions');
3
+ const dataStorage = require('../../../src/dataStorage');
4
+ const config = require('config');
5
+
6
+ When('I wait for {string} seconds', async function (seconds) {
7
+ seconds = seconds * 1000;
8
+ await new Promise(function (resolve) {
9
+ setTimeout(resolve, seconds);
10
+ });
11
+ });
12
+ When('I wait for AJAX loading to finish', async function () {
13
+ await helper.waitForAjax(this.page);
14
+ });
15
+ When('I put a breakpoint', { timeout: -1 }, async function () {
16
+ console.log('Debug mode on! Press any key to continue!');
17
+ await helper.waitForKeypress();
18
+ });
19
+ Given('I clear the json file', function () {
20
+ dataStorage.clearJsonFile();
21
+ });
22
+ Given('I store {string} in {string} variable', async function (data, variable) {
23
+ await dataStorage.iStoreVariableWithValueToTheJsonFile(data, variable);
24
+ });
25
+ Given('I save the path of the current page', async function () {
26
+ await dataStorage.saveCurrentPath(this.page);
27
+ });
28
+ Given('I store {string} from config to {string} in JSON', async function (param, variable) {
29
+ const value = await config.get(param);
30
+ await dataStorage.iStoreVariableWithValueToTheJsonFile(value, variable);
31
+ });
32
+ Given('I store the entity id with variable name {string} to the json file', async function (variable) {
33
+ await dataStorage.iStoreEntityId(this.page, variable);
34
+ });
35
+ Given('I store the value from the element with {string} selector in {string}', async function (cssSelector, variable) {
36
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
37
+ await dataStorage.storeValueOfElement(this.page, selector, variable);
38
+ });
39
+ Then(
40
+ 'I generate extension with {int} chars for the email {string} variable from config and store it in {string}',
41
+ async function (number, configVariable, varName) {
42
+ await dataStorage.generateExtensionAndStoreVar(number, configVariable, varName);
43
+ }
44
+ );
45
+ Then(
46
+ 'I generate extension with {int} chars for the email {string} and store it in {string}',
47
+ async function (number, email, varName) {
48
+ await dataStorage.generateExtensionAndStoreVar(number, email, varName);
49
+ }
50
+ );
51
+ Given('I lowercase all saved variables', async function () {
52
+ await dataStorage.lowercaseAllVariables();
53
+ });
54
+ When('I trim {string} variable on first special char occurrence', async function (variable) {
55
+ await dataStorage.trimVariableOnFirstSpecialChar(variable);
56
+ });
57
+ When('I generate date in {string} format for today and store it in {string}', async function (format, variable) {
58
+ await dataStorage.generateAndSaveDateWithCustomFormat(format, variable);
59
+ });
60
+ When(
61
+ 'I generate date in {string} format for {string} days from now and store it in {string}',
62
+ async function (format, days, variable) {
63
+ await dataStorage.generateAndSaveDateWithCustomFormat(format, variable, days);
64
+ }
65
+ );
66
+ When('I generate time in {string} format for now and store it in {string}', async function (format, variable) {
67
+ await dataStorage.generateAndSaveDateWithCustomFormat(format, variable);
68
+ });
69
+ When('I create json object from {string} file and store it in {string} variable', async function (filePath, variable) {
70
+ const checkedPath = await dataStorage.checkForSavedVariable(filePath);
71
+ const getFileData = dataStorage.getJsonFile(checkedPath);
72
+ await dataStorage.iStoreVariableWithValueToTheJsonFile(getFileData, variable);
73
+ });
74
+ Given('I switch back to original window', async function () {
75
+ this.page = await helper.openOriginalTab(this.browser);
76
+ });
77
+ Given('I switch to {string} tab', async function (tabNumber) {
78
+ this.page = await helper.switchToTab(this.browser, tabNumber);
79
+ });
@@ -0,0 +1,58 @@
1
+ const { When, Then } = require('@cucumber/cucumber');
2
+ const utils = require('../../../src/elementInteraction');
3
+ const config = require('config');
4
+ const dataStorage = require('../../../src/dataStorage');
5
+ Then('I should see {string} if visible', async function (text) {
6
+ if (config.has('skipSteps') && config.get('skipSteps') === text) {
7
+ return true;
8
+ }
9
+ await utils.seeTextByXpath(this.page, text);
10
+ });
11
+ When('I type {string} in {string} if visible', async function (text, cssSelector) {
12
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
13
+ await utils.typeInField(this.page, selector, text, true);
14
+ });
15
+ When('I click on the element {string} if visible', async function (cssSelector) {
16
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
17
+ await utils.click(this.page, selector, true);
18
+ });
19
+ Then('I select {string} from {string} if visible', async function (value, cssSelector) {
20
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
21
+ await utils.selectOptionByValue(this.page, selector, value, true);
22
+ });
23
+ Then('I fill in {string} with {string} if visible', async function (cssSelector, text) {
24
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
25
+ await utils.fillField(this.page, selector, text, true);
26
+ });
27
+ Then(
28
+ 'I check if element with selector {string} has attribute {string} with {string} value from config if visible',
29
+ async function (selector, attribute, variable) {
30
+ const attrValue = await config.get(variable);
31
+ await utils.validateElementWithSelectorHasAttributeWithValue(this.page, selector, attribute, attrValue, true);
32
+ }
33
+ );
34
+ Then(
35
+ 'I check if element with selector {string} has attribute {string} with {string} value from json if visible',
36
+ async function (selector, attribute, variable) {
37
+ const attrValue = dataStorage.getVariable(variable);
38
+ await utils.validateElementWithSelectorHasAttributeWithValue(this.page, selector, attribute, attrValue, true);
39
+ }
40
+ );
41
+ Then(
42
+ 'I check if link with href {string} has attribute {string} with {string} value from config if visible',
43
+ async function (href, attribute, value) {
44
+ const attrValue = await config.get(value);
45
+ await utils.validateValueOfLinkAttributeByHref(this.page, href, attribute, attrValue, true);
46
+ }
47
+ );
48
+ Then(
49
+ 'I check if link with href {string} has attribute {string} with {string} value from json if visible',
50
+ async function (href, attribute, value) {
51
+ const attrValue = dataStorage.getVariable(value);
52
+ await utils.validateValueOfLinkAttributeByHref(this.page, href, attribute, attrValue, true);
53
+ }
54
+ );
55
+ Then('I {string} the checkbox {string} if visible', async function (action, cssSelector) {
56
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
57
+ await utils.useCheckbox(this.page, selector, action, true);
58
+ });
@@ -0,0 +1,61 @@
1
+ const { When, Then } = require('@cucumber/cucumber');
2
+ const utils = require('../../../src/elementInteraction');
3
+ const dataStorage = require('../../../src/dataStorage');
4
+
5
+ Then('I should see {string} in iframe {string}', async function (text, frameSelector) {
6
+ const result = await dataStorage.checkForVariable(text);
7
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
8
+ await utils.seeTextByXpath(frame, result);
9
+ });
10
+ Then(
11
+ 'I wait for the text {string} to appear within {string} seconds in iframe {string}',
12
+ async function (text, time, frameSelector) {
13
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
14
+ await utils.seeTextByXpath(frame, text, time * 1000);
15
+ }
16
+ );
17
+ When('I click on element {string} in iframe with selector {string}', async function (elementSelector, frameSelector) {
18
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
19
+ await utils.click(frame, elementSelector);
20
+ });
21
+ When('I click on the text {string} in iframe with selector {string}', async function (text, frameSelector) {
22
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
23
+ await utils.clickByText(frame, text);
24
+ });
25
+ When(
26
+ 'I type {string} in {string} field in iframe with selector {string}',
27
+ async function (text, selector, frameSelector) {
28
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
29
+ await utils.typeInField(frame, selector, text);
30
+ }
31
+ );
32
+ When(
33
+ 'I click on the text {string} in iframe with selector {string} and follow the new tab',
34
+ async function (text, frameSelector) {
35
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
36
+ this.page = await utils.clickLinkOpenNewTab(this.browser, frame, text, true);
37
+ }
38
+ );
39
+ When(
40
+ 'I click on the element {string} in iframe with selector {string} and follow the new tab',
41
+ async function (cssSelector, frameSelector) {
42
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
43
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
44
+ this.page = await utils.clickLinkOpenNewTab(this.browser, frame, selector, false);
45
+ }
46
+ );
47
+ When(
48
+ 'I store the string matching the {string} pattern from the {string} text in iframe {string}',
49
+ async function (pattern, text, frameSelector) {
50
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
51
+ await dataStorage.storeTextFromPattern(frame, pattern, text);
52
+ }
53
+ );
54
+ Then(
55
+ 'I {string} the checkbox {string} in iframe with selector {string}',
56
+ async function (action, cssSelector, frameSelector) {
57
+ let frame = await utils.getFrameBySelector(this.page, frameSelector);
58
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
59
+ await utils.useCheckbox(frame, selector, action);
60
+ }
61
+ );
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @type {string}
3
+ * @name scenarioName - name of the scenario from the Before hook
4
+ */
5
+ const { Given, When } = require('@cucumber/cucumber');
6
+ const lighthouseMethods = require('../../../src/lighthouse');
7
+ const dataStorage = require('../../../src/dataStorage');
8
+ const main = require('../../../src/mainFunctions');
9
+
10
+ Given('I generate lighthouse report for the saved page', async function () {
11
+ const path = await dataStorage.getVariable('path');
12
+ await lighthouseMethods.validatePageSpeed(this.page, path, this.scenarioName);
13
+ });
14
+ When('I generate lighthouse report for {string} page', async function (path) {
15
+ const preparedPath = main.prepareUrl(path);
16
+ await lighthouseMethods.validatePageSpeed(this.page, preparedPath, this.scenarioName);
17
+ });
@@ -0,0 +1,208 @@
1
+ const { Given, When, Then } = require('@cucumber/cucumber');
2
+ const utils = require('../../../src/elementInteraction');
3
+ const dataStorage = require('../../../src/dataStorage');
4
+
5
+ /**
6
+ * This is a multipurpose step for text visibility. It uses direct input or variable,
7
+ * but it's too general to be moved to pageElementsJson.js file.
8
+ */
9
+ Then('I should see {string}', async function (text) {
10
+ const result = await dataStorage.checkForVariable(text);
11
+ await utils.seeTextByXpath(this.page, result);
12
+ });
13
+ When('I click on the element {string}', async function (cssSelector) {
14
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
15
+ await utils.click(this.page, selector);
16
+ });
17
+ When('I click on the element with xpath {string}', async function (xPath) {
18
+ const selector = 'xpath/' + `${xPath}`;
19
+ await utils.click(this.page, selector);
20
+ });
21
+ When('I click on all the elements with selector {string}', async function (cssSelector) {
22
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
23
+ await utils.clickAllElements(this.page, selector);
24
+ });
25
+ When('I click on the text {string}', async function (text) {
26
+ await utils.clickByText(this.page, text);
27
+ });
28
+ When('I click on the text {string} in the {string} region', async function (text, region) {
29
+ await utils.clickTextInRegion(this.page, text, region);
30
+ });
31
+
32
+ Then('I should see {string} in {string}', async function (value, cssSelector) {
33
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
34
+ await utils.validateTextInField(this.page, value, selector);
35
+ });
36
+
37
+ Then('I should see {string} in {string} region', async function (text, region) {
38
+ await utils.seeTextInRegion(this.page, text, region);
39
+ });
40
+
41
+ Then('I should see the element with selector {string}', async function (cssSelector) {
42
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
43
+ await utils.seeElement(this.page, selector);
44
+ });
45
+ Then('I should see the element with selector {string} in the DOM', async function (cssSelector) {
46
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
47
+ await utils.seeElement(this.page, selector, false);
48
+ });
49
+ Then('I should not see the element with selector {string}', async function (cssSelector) {
50
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
51
+ await utils.notSeeElement(this.page, selector);
52
+ });
53
+ Then('I wait for element {string} to disappear within {string} seconds', async function (cssSelector, time) {
54
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
55
+ await utils.notSeeElement(this.page, selector, time * 1000);
56
+ });
57
+ Then('I wait for element with {string} selector to appear within {string} seconds', async function (cssSelector, time) {
58
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
59
+ await utils.seeElement(this.page, selector, true, time * 1000);
60
+ });
61
+ Then('I should not see {string}', async function (text) {
62
+ await utils.notSeeText(this.page, text);
63
+ });
64
+ Then('I wait for the text {string} to appear within {string} seconds', async function (text, time) {
65
+ await utils.seeTextByXpath(this.page, text, time * 1000);
66
+ });
67
+ Then('I wait for the text {string} to disappear within {string} seconds', async function (text, time) {
68
+ await utils.disappearText(this.page, text, time * 1000);
69
+ });
70
+ Then('I upload the {string} in {string} field', async function (fileName, cssSelector) {
71
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
72
+ await utils.uploadFile(this.page, fileName, selector);
73
+ });
74
+ Then('I fill in {string} with {string}', async function (cssSelector, text) {
75
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
76
+ await utils.fillField(this.page, selector, text);
77
+ });
78
+ Then('I fill in CodeMirror field {string} with {string}', async function (cssSelector, value) {
79
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
80
+ await utils.setValueInCodeMirrorField(this.page, selector, value);
81
+ });
82
+ Then('I type {string} in {string}', async function (text, cssSelector) {
83
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
84
+ await utils.typeInField(this.page, selector, text);
85
+ });
86
+ Then('I {string} the checkbox {string}', async function (action, cssSelector) {
87
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
88
+ await utils.useCheckbox(this.page, selector, action);
89
+ });
90
+ Then('I write {string} into {string} ckeditor5 wysiwyg', async function (text, cssSelector) {
91
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
92
+ await utils.writeInCkEditor5(this.page, selector, text);
93
+ });
94
+ Then('I select {string} from {string}', async function (value, cssSelector) {
95
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
96
+ await utils.selectOptionByValue(this.page, selector, value);
97
+ });
98
+ Then('I select text {string} from {string}', async function (value, cssSelector) {
99
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
100
+ await utils.selectOptionByText(this.page, selector, value);
101
+ });
102
+
103
+ Then('I check if link {string} has href {string}', async function (text, href) {
104
+ await utils.validateHrefByText(this.page, text, href);
105
+ });
106
+ Then(
107
+ 'I check if link with href {string} has attribute {string} with {string} value',
108
+ async function (href, attribute, value) {
109
+ await utils.validateValueOfLinkAttributeByHref(this.page, href, attribute, value);
110
+ }
111
+ );
112
+ Then(
113
+ 'I check if element with selector {string} has attribute {string} with {string} value',
114
+ async function (selector, attribute, attrValue) {
115
+ await utils.validateElementWithSelectorHasAttributeWithValue(this.page, selector, attribute, attrValue);
116
+ }
117
+ );
118
+ Then(
119
+ 'I check if element with text {string} has attribute {string} with {string} value',
120
+ async function (text, attribute, value) {
121
+ await utils.validateValueOfElementAttributeByText(this.page, text, attribute, value);
122
+ }
123
+ );
124
+ Then('I upload {string} file to dropzone {string} field', async function (file, cssSelector) {
125
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
126
+ await utils.uploadToDropzone(this.page, file, selector);
127
+ });
128
+ Then('I should see {string} in the schema markup of the page', async function (text) {
129
+ await utils.validateTextInSchemaOrg(this.page, text);
130
+ });
131
+ Then('I should not see {string} in the schema markup of the page', async function (text) {
132
+ await utils.validateTextNotInSchemaOrg(this.page, text);
133
+ });
134
+ Then('I should see {string} in page scripts', async function (text) {
135
+ await utils.validateTextInScript(this.page, text);
136
+ });
137
+ Then('I should {string} see {string} in the {string} accordion', async function (isVisible, text, cssSelector) {
138
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
139
+ if (isVisible === 'not') {
140
+ isVisible = false;
141
+ }
142
+ await utils.textVisibilityInAccordion(this.page, selector, text, Boolean(isVisible));
143
+ });
144
+ Then('I select the first autocomplete option for {string} on the {string} field', async function (text, cssSelector) {
145
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
146
+ await utils.selectOptionFirstAutocomplete(this.page, text, selector);
147
+ });
148
+ Then('I select {string} from chosen {string}', async function (text, cssSelector) {
149
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
150
+ await utils.selectOptionFromChosen(this.page, text, selector);
151
+ });
152
+
153
+ Then('I set date {string} in flatpickr with selector {string}', async function (date, cssSelector) {
154
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
155
+ await utils.setDateFlatpickr(this.page, selector, date);
156
+ });
157
+ Then(
158
+ 'I get the href of element with selector {string} and store it to {string}',
159
+ async function (cssSelector, variable) {
160
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
161
+ await dataStorage.storeHrefOfElement(this.page, selector, variable);
162
+ }
163
+ );
164
+ Given('I scroll element with {string} to the top', async function (cssSelector) {
165
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
166
+ await utils.scrollElementToTop(this.page, selector);
167
+ });
168
+ Given('I scroll element with xpath {string} to the top', async function (xpath) {
169
+ const selector = 'xpath/' + `${xpath}`;
170
+ await utils.scrollElementToTop(this.page, selector);
171
+ });
172
+ Given('I check if options from dropdown {string} are in alphabetical order', async function (cssSelector) {
173
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
174
+ await utils.iCheckIfDropdownOptionsAreInAlphabeticalOrder(this.page, selector, true);
175
+ });
176
+ Given('I check if options from dropdown {string} are not in alphabetical order', async function (cssSelector) {
177
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
178
+ await utils.iCheckIfDropdownOptionsAreInAlphabeticalOrder(this.page, selector, false);
179
+ });
180
+ Given('I check if checkbox options with locator {string} are in alphabetical order', async function (cssSelector) {
181
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
182
+ await utils.iCheckIfCheckboxOptionsAreInAlphabeticalOrder(this.page, selector, true);
183
+ });
184
+ Given('I check if checkbox options with locator {string} are not in alphabetical order', async function (cssSelector) {
185
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
186
+ await utils.iCheckIfCheckboxOptionsAreInAlphabeticalOrder(this.page, selector, false);
187
+ });
188
+ When('I click on the text {string} and follow the new tab', async function (text) {
189
+ this.page = await utils.clickLinkOpenNewTab(this.browser, this.page, text, true);
190
+ });
191
+ When('I click on the element {string} and follow the new tab', async function (cssSelector) {
192
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
193
+ this.page = await utils.clickLinkOpenNewTab(this.browser, this.page, selector, true);
194
+ });
195
+ When('I click on the element {string} and follow the popup window', async function (cssSelector) {
196
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
197
+ this.page = await utils.clickElementOpenPopup(this.page, selector);
198
+ });
199
+ When('I press key {string}', async function (key) {
200
+ await utils.pressKey(this.page, key);
201
+ });
202
+ Then(
203
+ 'I set datetime picker {string} to format {string} with range {string}',
204
+ async function (cssSelector, format, range) {
205
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
206
+ await utils.setDateTimePickerWithFormat(this.page, selector, format, range);
207
+ }
208
+ );
@@ -0,0 +1,42 @@
1
+ const { When, Then } = require('@cucumber/cucumber');
2
+ const utils = require('../../../src/elementInteraction');
3
+ const config = require('config');
4
+ When('I click on the text {string} from config', async function (text) {
5
+ const textFromConfig = await config.get(text);
6
+ await utils.clickByText(this.page, textFromConfig);
7
+ });
8
+ Then('I should see {string} from config in element {string}', async function (value, cssSelector) {
9
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
10
+ const result = await config.get(value);
11
+ await utils.seeTextByElementHandle(this.page, selector, result);
12
+ });
13
+ Then('I fill in {string} with {string} variable from config', async function (cssSelector, variable) {
14
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
15
+ const value = await config.get(variable);
16
+ await utils.fillField(this.page, selector, value);
17
+ });
18
+ Then('I type {string} in {string} using variable from config', async function (variable, cssSelector) {
19
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
20
+ const value = await config.get(variable);
21
+ await utils.typeInField(this.page, selector, value);
22
+ });
23
+ Then(
24
+ 'I select the first autocomplete option for {string} from config on the {string} field',
25
+ async function (value, cssSelector) {
26
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
27
+ const result = await config.get(value);
28
+ await utils.selectOptionFirstAutocomplete(this.page, result, selector);
29
+ }
30
+ );
31
+ Then('I select {string} from config in {string} dropdown', async function (value, cssSelector) {
32
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
33
+ let data = config.get(value);
34
+ await utils.selectOptionByValue(this.page, selector, data);
35
+ });
36
+ Then(
37
+ 'I check if element with selector {string} has attribute {string} with {string} value from config',
38
+ async function (selector, attribute, value) {
39
+ const attrValue = config.get(value);
40
+ await utils.validateElementWithSelectorHasAttributeWithValue(this.page, selector, attribute, attrValue);
41
+ }
42
+ );
@@ -0,0 +1,49 @@
1
+ const { Then } = require('@cucumber/cucumber');
2
+ const utils = require('../../../src/elementInteraction');
3
+ const dataStorage = require('../../../src/dataStorage');
4
+ Then('I should see {string} from json in element {string}', async function (value, cssSelector) {
5
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
6
+ const result = await dataStorage.getVariable(value);
7
+ await utils.seeTextByElementHandle(this.page, selector, result);
8
+ });
9
+ Then('I should see stored text {string} in {string} region', async function (text, region) {
10
+ const result = await dataStorage.checkForMultipleVariables(text);
11
+ await utils.seeTextInRegion(this.page, result, region);
12
+ });
13
+ Then('I hover on text {string} in {string} region', async function (text, region) {
14
+ const result = await dataStorage.checkForMultipleVariables(text);
15
+ await utils.hoverTextInRegion(this.page, result, region);
16
+ });
17
+ Then('I should see variable {string} in {string} region', async function (variable, region) {
18
+ const value = dataStorage.getVariable(variable);
19
+ await utils.seeTextInRegion(this.page, value, region);
20
+ });
21
+ Then('I fill in {string} with {string} variable from JSON', async function (cssSelector, variable) {
22
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
23
+ const value = await dataStorage.getVariable(variable);
24
+ await utils.fillField(this.page, selector, value);
25
+ });
26
+ Then('I fill in {string} with {string} variable using JSON stringify', async function (cssSelector, variable) {
27
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
28
+ const value = await dataStorage.getVariable(variable, true);
29
+ await utils.fillField(this.page, selector, value);
30
+ });
31
+ Then('I type {string} in {string} using variable from JSON', async function (variable, cssSelector) {
32
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
33
+ const value = await dataStorage.getVariable(variable);
34
+ await utils.typeInField(this.page, selector, value);
35
+ });
36
+ Then('I check if link {string} has href {string} from JSON', async function (text, href) {
37
+ const savedHref = await dataStorage.getVariable(href);
38
+ await utils.validateHrefByText(this.page, text, savedHref);
39
+ });
40
+ Then('I set stored date {string} in flatpickr with selector {string}', async function (date, cssSelector) {
41
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
42
+ const result = await dataStorage.checkForVariable(date);
43
+ await utils.setDateFlatpickr(this.page, selector, result);
44
+ });
45
+ Then('I select {string} from json in {string} dropdown', async function (variable, cssSelector) {
46
+ const selector = this.commonFields[cssSelector] ?? cssSelector;
47
+ let data = await dataStorage.getVariable(variable);
48
+ await utils.selectOptionByValue(this.page, selector, data);
49
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @type {string}
3
+ * @name scenarioName - name of the scenario from the Before hook
4
+ */
5
+ const { Given, Then } = require('@cucumber/cucumber');
6
+ const imageCompare = require('../../../src/visualRegression');
7
+ const main = require('../../../src/mainFunctions');
8
+ const dataStorage = require('../../../src/dataStorage');
9
+ Given('I generate reference screenshot for {string}', async function (path) {
10
+ const storedUrl = await dataStorage.checkForVariable(path);
11
+ const url = await main.prepareUrl(storedUrl);
12
+ await imageCompare.runBackStopSingleScenario(this.scenarioName, url, 'reference');
13
+ });
14
+ Then('I compare {string} to reference screenshot', async function (path) {
15
+ const storedUrl = await dataStorage.checkForVariable(path);
16
+ const url = await main.prepareUrl(storedUrl);
17
+ await imageCompare.runBackStopSingleScenario(this.scenarioName, url, 'test');
18
+ });
19
+ Given('I generate reference screenshot for multiple pages', async function (docString) {
20
+ const pages = JSON.parse(docString);
21
+ await imageCompare.runBackstopMultiplePages(pages, 'reference');
22
+ });
23
+ Then('I compare multiple pages to their references', async function (docString) {
24
+ const pages = JSON.parse(docString);
25
+ await imageCompare.runBackstopMultiplePages(pages, 'test');
26
+ });
@@ -0,0 +1,15 @@
1
+ const { setWorldConstructor, setDefaultTimeout } = require('@cucumber/cucumber');
2
+
3
+ setDefaultTimeout(120 * 1000);
4
+
5
+ //attach: function used for adding attachments to hooks/steps
6
+ class World {
7
+ constructor({ attach }) {
8
+ this.attach = attach;
9
+ }
10
+
11
+ fixSonar() {
12
+ console.log('Sample function to fix empty class.');
13
+ }
14
+ }
15
+ setWorldConstructor(World);