@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.
- package/LICENSE +201 -0
- package/README.md +183 -0
- package/features/app/appiumManager.js +58 -0
- package/features/app/browserManager.js +54 -0
- package/features/app/hooks.js +95 -0
- package/features/app/stepDefinitions/accessibilitySteps.js +17 -0
- package/features/app/stepDefinitions/apiSteps.js +52 -0
- package/features/app/stepDefinitions/appiumSteps.js +15 -0
- package/features/app/stepDefinitions/generalSteps.js +98 -0
- package/features/app/stepDefinitions/helperSteps.js +79 -0
- package/features/app/stepDefinitions/ifVisibleSteps.js +58 -0
- package/features/app/stepDefinitions/iframeSteps.js +61 -0
- package/features/app/stepDefinitions/lighthouseSteps.js +17 -0
- package/features/app/stepDefinitions/pageElements.js +208 -0
- package/features/app/stepDefinitions/pageElementsConfig.js +42 -0
- package/features/app/stepDefinitions/pageElementsJson.js +49 -0
- package/features/app/stepDefinitions/visualRegressionSteps.js +26 -0
- package/features/app/world.js +15 -0
- package/index.js +43 -0
- package/package.json +57 -0
- package/src/accessibilityTesting.js +44 -0
- package/src/apiFunctions.js +290 -0
- package/src/appiumTesting.js +79 -0
- package/src/dataStorage.js +290 -0
- package/src/elementInteraction.js +1003 -0
- package/src/helperFunctions.js +183 -0
- package/src/lighthouse.js +23 -0
- package/src/mainFunctions.js +288 -0
- package/src/visualRegression.js +67 -0
- package/stepDefinitions.js +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# @cuppet/core
|
|
2
|
+
|
|
3
|
+
Core testing framework components for Cuppet - a BDD framework based on Cucumber and Puppeteer.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @cuppet/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Basic Setup
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const {
|
|
17
|
+
BrowserManager,
|
|
18
|
+
elementInteraction,
|
|
19
|
+
dataStorage
|
|
20
|
+
} = require('@cuppet/core');
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### In your hooks.js
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
const { Before, After } = require('@cucumber/cucumber');
|
|
27
|
+
const { BrowserManager, AppiumManager } = require('@cuppet/core');
|
|
28
|
+
const config = require('config');
|
|
29
|
+
|
|
30
|
+
Before(async function (testCase) {
|
|
31
|
+
const browserArgs = config.get('browserOptions.args');
|
|
32
|
+
const browserViewport = config.get('browserOptions.viewport.default');
|
|
33
|
+
|
|
34
|
+
const browserManager = new BrowserManager(browserViewport, browserArgs);
|
|
35
|
+
await browserManager.initialize();
|
|
36
|
+
this.browserManager = browserManager;
|
|
37
|
+
this.browser = browserManager.browser;
|
|
38
|
+
this.page = browserManager.page;
|
|
39
|
+
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### In your step definitions
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
47
|
+
const { elementInteraction, mainFunctions } = require('@cuppet/core');
|
|
48
|
+
|
|
49
|
+
Given('I am on the homepage', async function() {
|
|
50
|
+
await mainFunctions.visitPath(this.page, 'homepage');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
When('I click the {string} button', async function(cssSelector) {
|
|
54
|
+
await elementInteraction.click(this.page, cssSelector);
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Available Components
|
|
59
|
+
|
|
60
|
+
### Core Functions
|
|
61
|
+
- `elementInteraction` - Element interaction utilities
|
|
62
|
+
- `dataStorage` - Data storage and management
|
|
63
|
+
- `mainFunctions` - Main testing functions
|
|
64
|
+
- `helperFunctions` - Helper utilities
|
|
65
|
+
- `apiFunctions` - API testing functions
|
|
66
|
+
- `appiumTesting` - Appium mobile testing
|
|
67
|
+
- `accessibilityTesting` - Accessibility testing with Pa11y
|
|
68
|
+
- `lighthouse` - Performance testing with Lighthouse
|
|
69
|
+
- `visualRegression` - Visual regression testing with BackstopJS
|
|
70
|
+
|
|
71
|
+
### Managers
|
|
72
|
+
- `BrowserManager` - Puppeteer browser management
|
|
73
|
+
- `AppiumManager` - Appium mobile testing management
|
|
74
|
+
|
|
75
|
+
### Step Definitions
|
|
76
|
+
- `stepDefinitions` - Pre-built Cucumber step definitions for common testing scenarios
|
|
77
|
+
|
|
78
|
+
## Using Step Definitions in Other Projects
|
|
79
|
+
|
|
80
|
+
The cuppet-core package includes pre-built step definitions that you can use in your main project. Here are several ways to integrate them:
|
|
81
|
+
|
|
82
|
+
### Option 1: Import and use directly in your step definition files
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
// In your project's step definition file (e.g., mySteps.js)
|
|
86
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
87
|
+
const { stepDefinitions } = require('@cuppet/core');
|
|
88
|
+
|
|
89
|
+
// Use the pre-built step definitions
|
|
90
|
+
const { generalSteps, helperSteps, apiSteps } = stepDefinitions;
|
|
91
|
+
|
|
92
|
+
// You can now use the step definitions directly
|
|
93
|
+
Given('I am on the homepage', generalSteps.givenIAmOnTheHomepage);
|
|
94
|
+
When('I click the login button', helperSteps.whenIClickTheLoginButton);
|
|
95
|
+
Then('I should see the dashboard', generalSteps.thenIShouldSeeTheDashboard);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Option 2: Import step definitions separately
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
// Import step definitions directly
|
|
102
|
+
const stepDefinitions = require('@cuppet/core/stepDefinitions');
|
|
103
|
+
|
|
104
|
+
// Or import specific step definition modules
|
|
105
|
+
const generalSteps = require('@cuppet/core/features/app/stepDefinitions/generalSteps');
|
|
106
|
+
const apiSteps = require('@cuppet/core/features/app/stepDefinitions/apiSteps');
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Option 3: Extend and customize step definitions
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
// In your project's step definition file
|
|
113
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
114
|
+
const { stepDefinitions } = require('@cuppet/core');
|
|
115
|
+
|
|
116
|
+
// Extend the base step definitions with your custom logic
|
|
117
|
+
Given('I am logged in as {string}', async function(userType) {
|
|
118
|
+
// Your custom login logic
|
|
119
|
+
await this.page.goto('https://your-app.com/login');
|
|
120
|
+
await this.page.fill('[data-testid="username"]', userType);
|
|
121
|
+
await this.page.fill('[data-testid="password"]', 'password');
|
|
122
|
+
await this.page.click('[data-testid="login-button"]');
|
|
123
|
+
|
|
124
|
+
// Then use the base step definition
|
|
125
|
+
await stepDefinitions.generalSteps.thenIShouldSeeTheDashboard.call(this);
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Available Step Definition Categories
|
|
130
|
+
|
|
131
|
+
- `accessibilitySteps` - Accessibility testing steps
|
|
132
|
+
- `apiSteps` - API testing and validation steps
|
|
133
|
+
- `appiumSteps` - Mobile testing with Appium
|
|
134
|
+
- `generalSteps` - Common navigation and interaction steps
|
|
135
|
+
- `helperSteps` - Utility and helper steps
|
|
136
|
+
- `iframeSteps` - Iframe handling steps
|
|
137
|
+
- `ifVisibleSteps` - Conditional visibility steps
|
|
138
|
+
- `lighthouseSteps` - Performance testing steps
|
|
139
|
+
- `pageElements` - Page element management
|
|
140
|
+
- `pageElementsConfig` - Page element configuration
|
|
141
|
+
- `pageElementsJson` - JSON-based page elements
|
|
142
|
+
- `visualRegressionSteps` - Visual regression testing steps
|
|
143
|
+
|
|
144
|
+
### Cucumber Configuration
|
|
145
|
+
|
|
146
|
+
Make sure your Cucumber configuration includes the step definition paths:
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
// cucumber.js
|
|
150
|
+
module.exports = {
|
|
151
|
+
default: {
|
|
152
|
+
requireModule: ['@cuppet/core'],
|
|
153
|
+
require: [
|
|
154
|
+
'node_modules/@cuppet/core/features/app/stepDefinitions/*.js',
|
|
155
|
+
'features/step-definitions/**/*.js' // Your project's step definitions
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Project-Specific Components
|
|
162
|
+
|
|
163
|
+
The following components should be created in your project as they are specific to your application:
|
|
164
|
+
|
|
165
|
+
- `commonComponents/` - Common form fields and page paths for your application
|
|
166
|
+
- `multilingualStrings/` - Multilingual string support for your application
|
|
167
|
+
|
|
168
|
+
## Peer Dependencies
|
|
169
|
+
|
|
170
|
+
This package requires the following peer dependencies:
|
|
171
|
+
- `@cucumber/cucumber` ^11.0.0
|
|
172
|
+
- `puppeteer` ^24.0.1
|
|
173
|
+
- `config` ^3.3.9
|
|
174
|
+
|
|
175
|
+
Make sure to install these in your project:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
npm install @cucumber/cucumber puppeteer config
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
ISC
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wdio session
|
|
3
|
+
*
|
|
4
|
+
* @type {import('webdriverio')}
|
|
5
|
+
*/
|
|
6
|
+
const { remote } = require('webdriverio');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Appium instance manager for handling Appium sessions and capabilities.
|
|
10
|
+
*
|
|
11
|
+
* @class AppiumManager
|
|
12
|
+
* @typedef {AppiumManager}
|
|
13
|
+
*/
|
|
14
|
+
class AppiumManager {
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of AppiumManager.
|
|
17
|
+
*
|
|
18
|
+
* @constructor
|
|
19
|
+
* @param {*} capabilities
|
|
20
|
+
*/
|
|
21
|
+
constructor(capabilities) {
|
|
22
|
+
this.capabilities = capabilities;
|
|
23
|
+
this.appiumDriver = null;
|
|
24
|
+
this.appiumService = null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Description placeholder
|
|
29
|
+
*
|
|
30
|
+
* @async
|
|
31
|
+
* @returns {Promise<void>}
|
|
32
|
+
* @throws {Error} If the Appium service fails to start.
|
|
33
|
+
*/
|
|
34
|
+
async initialize() {
|
|
35
|
+
const wdOpts = {
|
|
36
|
+
hostname: process.env.APPIUM_HOST || 'localhost',
|
|
37
|
+
port: parseInt(process.env.APPIUM_PORT, 10) || 4723,
|
|
38
|
+
logLevel: 'silent', // Can be: 'trace', 'debug', 'info', 'warn', 'error', or 'silent'
|
|
39
|
+
capabilities: this.capabilities,
|
|
40
|
+
};
|
|
41
|
+
this.appiumDriver = await remote(wdOpts);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Description placeholder
|
|
46
|
+
*
|
|
47
|
+
* @async
|
|
48
|
+
* @returns {Promise<void>}
|
|
49
|
+
*/
|
|
50
|
+
async stop() {
|
|
51
|
+
if (this.appiumDriver) {
|
|
52
|
+
await this.appiumDriver.deleteSession();
|
|
53
|
+
this.appiumDriver = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = AppiumManager;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const puppeteer = require('puppeteer');
|
|
2
|
+
|
|
3
|
+
class BrowserManager {
|
|
4
|
+
constructor(config, args, credentials) {
|
|
5
|
+
this.config = config;
|
|
6
|
+
this.args = args;
|
|
7
|
+
this.credentials = credentials;
|
|
8
|
+
this.browser = null;
|
|
9
|
+
this.page = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async initialize() {
|
|
13
|
+
// Launch the browser with the provided arguments and configuration
|
|
14
|
+
this.browser = await puppeteer.launch({
|
|
15
|
+
headless: false,
|
|
16
|
+
args: this.args,
|
|
17
|
+
defaultViewport: null,
|
|
18
|
+
w3c: false,
|
|
19
|
+
});
|
|
20
|
+
// Check if the browser was launched successfully and a page is available
|
|
21
|
+
const pages = await this.browser.pages();
|
|
22
|
+
if (pages.length > 0) {
|
|
23
|
+
this.page = pages[0];
|
|
24
|
+
} else {
|
|
25
|
+
this.page = await this.browser.newPage();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Set the viewport for headless mode
|
|
29
|
+
if (Array.isArray(this.args)) {
|
|
30
|
+
const isHeadless = this.args.includes('--headless=new');
|
|
31
|
+
if (isHeadless) {
|
|
32
|
+
await this.page.setViewport({
|
|
33
|
+
width: Number(this.config.width),
|
|
34
|
+
height: Number(this.config.height),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Pass basic authentication credentials if provided
|
|
40
|
+
if (this.credentials) {
|
|
41
|
+
await this.page.authenticate(this.credentials);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async stop() {
|
|
46
|
+
if (this.browser) {
|
|
47
|
+
await this.browser.close();
|
|
48
|
+
this.browser = null;
|
|
49
|
+
this.page = null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = BrowserManager;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const { BeforeAll, AfterAll, Before, After, AfterStep, Status } = require('@cucumber/cucumber');
|
|
2
|
+
const BrowserManager = require('./browserManager');
|
|
3
|
+
const AppiumManager = require('./appiumManager');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const config = require('config');
|
|
6
|
+
const dataStore = require('../../src/dataStorage');
|
|
7
|
+
const profile = process.env.NODE_CONFIG_ENV;
|
|
8
|
+
|
|
9
|
+
let screenshotPath = config.get('screenshotsPath').toString() ?? 'screenshots/';
|
|
10
|
+
|
|
11
|
+
// ==== BeforeAll and AfterAll do not have access to test scope 'this'
|
|
12
|
+
// ==== Before and After do
|
|
13
|
+
|
|
14
|
+
// executed once before any test
|
|
15
|
+
BeforeAll(async function () {
|
|
16
|
+
await dataStore.createFile();
|
|
17
|
+
console.log(`Tests started at: ${new Date()}`);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
AfterStep(async function (testCase) {
|
|
21
|
+
/**
|
|
22
|
+
* If the test is not passed or the test is not tagged with @api, take a screenshot
|
|
23
|
+
*/
|
|
24
|
+
const arrayTags = testCase.pickle.tags;
|
|
25
|
+
const found = arrayTags.find((item) => item.name === '@api');
|
|
26
|
+
if (testCase.result.status !== Status.PASSED && found === undefined) {
|
|
27
|
+
let stepName = testCase.pickle.uri;
|
|
28
|
+
const name = stepName.replace(/[/\\.]/g, '_');
|
|
29
|
+
const baseScreenshotPath = `${screenshotPath}${profile}`;
|
|
30
|
+
if (!fs.existsSync(baseScreenshotPath)) {
|
|
31
|
+
fs.mkdirSync(baseScreenshotPath, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
let path = `${baseScreenshotPath}/screenshot_${name}.png`;
|
|
34
|
+
let screenshot = await this.page.screenshot({ path: path, fullPage: true });
|
|
35
|
+
console.log(`Screenshot taken: ${name}`);
|
|
36
|
+
// Convert Uint8Array to Buffer because Cucumber cannot work directly with Uint8Arrays
|
|
37
|
+
const buffer = Buffer.from(screenshot.buffer, screenshot.byteOffset, screenshot.byteLength);
|
|
38
|
+
this.attach(buffer, 'image/png');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// executed once after all tests
|
|
43
|
+
AfterAll(async function () {
|
|
44
|
+
const date = new Date();
|
|
45
|
+
console.log(`Tests completed at: ${date.toString()}`);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// executed before every test
|
|
49
|
+
Before(async function (testCase) {
|
|
50
|
+
// Get Browser config arguments array
|
|
51
|
+
const browserArgs = config.get('browserOptions.args');
|
|
52
|
+
// Get default browser viewport
|
|
53
|
+
const browserViewport = config.get('browserOptions.viewport.default');
|
|
54
|
+
// Check for basic auth credentials in config
|
|
55
|
+
let credentials;
|
|
56
|
+
if (config.has('basicAuth')) {
|
|
57
|
+
credentials = {
|
|
58
|
+
username: config.get('basicAuth.authUser').toString(),
|
|
59
|
+
password: config.get('basicAuth.authPass').toString(),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Get Appium capabilities from config
|
|
63
|
+
const appiumCapabilities = config.get('appiumCapabilities');
|
|
64
|
+
|
|
65
|
+
// Check if the test is tagged with @appium to either use Appium or Chromium
|
|
66
|
+
const arrayTags = testCase.pickle.tags;
|
|
67
|
+
const found = arrayTags.find((item) => item.name === '@appium');
|
|
68
|
+
if (!found) {
|
|
69
|
+
const browserManager = new BrowserManager(browserViewport, browserArgs, credentials);
|
|
70
|
+
await browserManager.initialize();
|
|
71
|
+
|
|
72
|
+
// Assign created browser, page, and scenario name to global variables
|
|
73
|
+
this.browserManager = browserManager;
|
|
74
|
+
this.browser = browserManager.browser;
|
|
75
|
+
this.page = browserManager.page;
|
|
76
|
+
this.scenarioName = testCase.pickle.name;
|
|
77
|
+
} else {
|
|
78
|
+
const appiumManager = new AppiumManager(appiumCapabilities);
|
|
79
|
+
await appiumManager.initialize();
|
|
80
|
+
this.appiumManager = appiumManager;
|
|
81
|
+
this.appiumDriver = appiumManager.appiumDriver;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// executed after every test
|
|
86
|
+
After(async function (testCase) {
|
|
87
|
+
if (testCase.result.status === Status.FAILED) {
|
|
88
|
+
console.log(`Scenario: '${testCase.pickle.name}' - has failed...\r\n`);
|
|
89
|
+
}
|
|
90
|
+
if (this.browser) {
|
|
91
|
+
await this.browserManager.stop();
|
|
92
|
+
} else if (this.appiumDriver) {
|
|
93
|
+
await this.appiumManager.stop();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
@@ -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 accessibilitySteps = require('../../../src/accessibilityTesting');
|
|
7
|
+
const dataStorage = require('../../../src/dataStorage');
|
|
8
|
+
const main = require('../../../src/mainFunctions');
|
|
9
|
+
|
|
10
|
+
Given('I validate the saved page accessibility', async function () {
|
|
11
|
+
const path = await dataStorage.getVariable('path');
|
|
12
|
+
await accessibilitySteps.validatePageAccessibility(this.browser, this.page, this.scenarioName, path);
|
|
13
|
+
});
|
|
14
|
+
When('I validate the accessibility of the {string} page', async function (path) {
|
|
15
|
+
const preparedPath = main.prepareUrl(path);
|
|
16
|
+
await accessibilitySteps.validatePageAccessibility(this.browser, this.page, this.scenarioName, preparedPath);
|
|
17
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
2
|
+
const apiSteps = require('../../../src/apiFunctions');
|
|
3
|
+
const main = require('../../../src/mainFunctions');
|
|
4
|
+
const dataStorage = require('../../../src/dataStorage');
|
|
5
|
+
|
|
6
|
+
Given('that I send a {string} request to {string}', async function (method, path) {
|
|
7
|
+
await apiSteps.sendRequest(method, path);
|
|
8
|
+
});
|
|
9
|
+
When(
|
|
10
|
+
'I send a {string} request to {string} with http header {string} and value {string}',
|
|
11
|
+
async function (method, path, headerName, headerValue) {
|
|
12
|
+
const name = await dataStorage.checkForSavedVariable(headerName);
|
|
13
|
+
const value = await dataStorage.checkForSavedVariable(headerValue);
|
|
14
|
+
const headers = {};
|
|
15
|
+
headers[name] = value;
|
|
16
|
+
await apiSteps.sendRequest(method, path, headers);
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
Given('the response code should be {string}', async function (code) {
|
|
20
|
+
await apiSteps.validateResponseCode(code);
|
|
21
|
+
});
|
|
22
|
+
Then('the response should be an {string}', async function (type) {
|
|
23
|
+
await apiSteps.validateResponseType(type);
|
|
24
|
+
});
|
|
25
|
+
Then('the property {string} should be an {string}', async function (property, type) {
|
|
26
|
+
await apiSteps.propertyIs(property, type);
|
|
27
|
+
});
|
|
28
|
+
Then('the response should have property {string} with value {string}', async function (property, value) {
|
|
29
|
+
await apiSteps.propertyHasValue(property, value);
|
|
30
|
+
});
|
|
31
|
+
When('I store {string} to {string} variable', async function (property, variable) {
|
|
32
|
+
await apiSteps.iRememberVariable(property, variable);
|
|
33
|
+
});
|
|
34
|
+
Given('that I have request body', async function (docString) {
|
|
35
|
+
const body = JSON.stringify(docString);
|
|
36
|
+
await apiSteps.prepareRequestBody(body);
|
|
37
|
+
});
|
|
38
|
+
Given(
|
|
39
|
+
'I put {string} to {string} property of {string} element in the body',
|
|
40
|
+
async function (value, property, parentObj) {
|
|
41
|
+
await apiSteps.iPutValuesInRequestBody(value, property, parentObj);
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
Given('I create json object from {string} file', async function (filePath) {
|
|
46
|
+
const checkedPath = await dataStorage.checkForSavedVariable(filePath);
|
|
47
|
+
await apiSteps.createRequestBodyFromFile(checkedPath);
|
|
48
|
+
});
|
|
49
|
+
Given('I validate that the page is a valid XML', async function () {
|
|
50
|
+
const currentPath = main.extractPath(this.page, true);
|
|
51
|
+
await apiSteps.validateXMLEndpoint(currentPath);
|
|
52
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
2
|
+
const appiumTesting = require('../../../src/appiumTesting');
|
|
3
|
+
|
|
4
|
+
Given('I go to {string} app package and {string} activity', async function (androidPackage, activity) {
|
|
5
|
+
await appiumTesting.reloadSession(this.appiumDriver, androidPackage, activity);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
Then('I click on the element {string} on mobile', async function (selector) {
|
|
9
|
+
const elSelector = appiumTesting.prepareSelector(selector);
|
|
10
|
+
await appiumTesting.clickElement(this.appiumDriver, elSelector);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
When('I scroll to the element {string} on mobile', async function (selector) {
|
|
14
|
+
await appiumTesting.scrollToElement(this.appiumDriver, selector);
|
|
15
|
+
});
|