generator-jhipster-playwright 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 +176 -0
- package/README.md +137 -0
- package/cli/cli.cjs +37 -0
- package/generators/cypress/command.js +5 -0
- package/generators/cypress/files.js +75 -0
- package/generators/cypress/generator.js +111 -0
- package/generators/cypress/index.js +2 -0
- package/generators/cypress/templates/playwright.config.ts.ejs +30 -0
- package/generators/cypress/templates/src/test/javascript/cypress/e2e/account/login-page.spec.ts.ejs +83 -0
- package/generators/cypress/templates/src/test/javascript/cypress/e2e/account/logout.spec.ts.ejs +39 -0
- package/generators/cypress/templates/src/test/javascript/cypress/e2e/account/password-page.spec.ts.ejs +88 -0
- package/generators/cypress/templates/src/test/javascript/cypress/e2e/account/register-page.spec.ts.ejs +124 -0
- package/generators/cypress/templates/src/test/javascript/cypress/e2e/account/reset-password-page.spec.ts.ejs +57 -0
- package/generators/cypress/templates/src/test/javascript/cypress/e2e/account/settings-page.spec.ts.ejs +85 -0
- package/generators/cypress/templates/src/test/javascript/cypress/e2e/administration/administration.spec.ts.ejs +73 -0
- package/generators/cypress/templates/src/test/javascript/cypress/e2e/entity/_entity_.spec.ts.ejs +378 -0
- package/generators/cypress/templates/src/test/javascript/cypress/fixtures/integration-test.png +0 -0
- package/generators/cypress/templates/src/test/javascript/cypress/support/account.ts.ejs +26 -0
- package/generators/cypress/templates/src/test/javascript/cypress/support/commands.ts.ejs +200 -0
- package/generators/cypress/templates/src/test/javascript/cypress/support/entity.ts.ejs +73 -0
- package/generators/cypress/templates/src/test/javascript/cypress/support/index.ts.ejs +3 -0
- package/generators/cypress/templates/src/test/javascript/cypress/support/management.ts.ejs +12 -0
- package/generators/cypress/templates/src/test/javascript/cypress/support/navbar.ts.ejs +54 -0
- package/generators/cypress/templates/src/test/javascript/cypress/support/oauth2.ts.ejs +64 -0
- package/generators/cypress/templates/src/test/javascript/cypress/tsconfig.json.ejs +14 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://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
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# generator-jhipster-playwright
|
|
2
|
+
|
|
3
|
+
> A JHipster blueprint that replaces the generated Cypress end-to-end suite with Playwright.
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
This is a JHipster blueprint. It overrides the `cypress` sub-generator and writes Playwright files instead of Cypress files for generated applications.
|
|
8
|
+
|
|
9
|
+
Verified against fresh generated JHipster applications:
|
|
10
|
+
|
|
11
|
+
- React + JWT: `53 passed`, `0 skipped`
|
|
12
|
+
- Angular + JWT: `59 passed`, `0 failed`, `0 skipped`
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
To install or update this blueprint:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g generator-jhipster-playwright
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### How to Generate Code
|
|
25
|
+
|
|
26
|
+
This package exposes a dedicated CLI:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
jhipster-playwright
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
It can also be used through the standard JHipster CLI:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
jhipster --blueprints playwright
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For available options, you can run:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
jhipster-playwright app --help
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Enable the Cypress Test Framework
|
|
45
|
+
|
|
46
|
+
This blueprint overrides JHipster's `cypress` sub-generator. Upstream JHipster only composes that generator when `testFrameworks` includes `cypress`, so Playwright generation must be triggered with Cypress selected.
|
|
47
|
+
|
|
48
|
+
Use one of these approaches:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
jhipster --blueprints playwright --test-frameworks cypress
|
|
52
|
+
jhipster-playwright --test-frameworks cypress
|
|
53
|
+
jhipster jdl app.jdl --blueprints playwright --test-frameworks cypress
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
You can also express this directly in JDL:
|
|
57
|
+
|
|
58
|
+
```jdl
|
|
59
|
+
application {
|
|
60
|
+
config {
|
|
61
|
+
baseName myApp
|
|
62
|
+
clientFramework react
|
|
63
|
+
testFrameworks [cypress]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### How to Run the Generated Tests
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
jhipster jdl app.jdl --blueprints playwright --test-frameworks cypress --skip-install --force
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
After generation, install dependencies, install the Playwright browser, start the backend, and run the suite:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm install
|
|
78
|
+
npx playwright install chromium
|
|
79
|
+
./mvnw
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
In a second terminal:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx playwright test
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The generated `playwright.config.ts` starts the frontend dev server automatically. The Spring Boot backend still needs to be running before the tests execute.
|
|
89
|
+
|
|
90
|
+
### Generated Output
|
|
91
|
+
|
|
92
|
+
The blueprint writes:
|
|
93
|
+
|
|
94
|
+
- `playwright.config.ts`
|
|
95
|
+
- Playwright support utilities under `src/test/javascript/playwright/support`
|
|
96
|
+
- Account, administration, and entity specs under `src/test/javascript/playwright/e2e`
|
|
97
|
+
- `@playwright/test` and Playwright npm scripts in the generated application's `package.json`
|
|
98
|
+
|
|
99
|
+
For Angular applications, the blueprint also adds `@popperjs/core` to the generated app dependencies so the generated frontend has the required Popper peer dependency available.
|
|
100
|
+
|
|
101
|
+
## Local Development
|
|
102
|
+
|
|
103
|
+
To work on the blueprint locally:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm install
|
|
107
|
+
npm test
|
|
108
|
+
npm pack --dry-run --cache ./.npm-cache
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
To exercise the blueprint locally against a generated app, link it first:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm link
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Then in the target app directory:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm link generator-jhipster-playwright
|
|
121
|
+
jhipster --blueprints playwright --test-frameworks cypress --skip-install --force
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Updated generator-jhipster
|
|
125
|
+
|
|
126
|
+
This blueprint currently targets `generator-jhipster` `9.0.0`.
|
|
127
|
+
|
|
128
|
+
If you want to run it through the standard JHipster CLI, install a compatible JHipster version and use:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm install -g generator-jhipster@9.0.0
|
|
132
|
+
jhipster --blueprints playwright --test-frameworks cypress
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
Apache 2.0, see [LICENSE](LICENSE).
|
package/cli/cli.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const { bin, version } = require('../package.json');
|
|
6
|
+
|
|
7
|
+
// Get package name to use as namespace.
|
|
8
|
+
// Allows blueprints to be aliased.
|
|
9
|
+
const packagePath = path.dirname(__dirname);
|
|
10
|
+
const packageFolderName = path.basename(packagePath);
|
|
11
|
+
const devBlueprintPath = path.join(packagePath, '.blueprint');
|
|
12
|
+
const blueprint = packageFolderName.startsWith('jhipster-') ? `generator-${packageFolderName}` : packageFolderName;
|
|
13
|
+
|
|
14
|
+
(async () => {
|
|
15
|
+
const { runJHipster, done, logger } = await import('generator-jhipster/cli');
|
|
16
|
+
const executableName = Object.keys(bin)[0];
|
|
17
|
+
|
|
18
|
+
runJHipster({
|
|
19
|
+
executableName,
|
|
20
|
+
executableVersion: version,
|
|
21
|
+
defaultCommand: 'app',
|
|
22
|
+
devBlueprintPath,
|
|
23
|
+
blueprints: {
|
|
24
|
+
[blueprint]: version,
|
|
25
|
+
},
|
|
26
|
+
printBlueprintLogo: () => {
|
|
27
|
+
console.log('===================== JHipster Playwright =====================');
|
|
28
|
+
console.log('');
|
|
29
|
+
},
|
|
30
|
+
lookups: [{ packagePaths: [packagePath] }],
|
|
31
|
+
}).catch(done);
|
|
32
|
+
|
|
33
|
+
process.on('unhandledRejection', up => {
|
|
34
|
+
logger.error('Unhandled promise rejection at:');
|
|
35
|
+
logger.fatal(up);
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playwright template file mappings.
|
|
3
|
+
* Mirrors the Cypress files.ts structure from generator-jhipster v9.
|
|
4
|
+
*
|
|
5
|
+
* Pattern from Cypress:
|
|
6
|
+
* path: source template directory (relative to templates/)
|
|
7
|
+
* renameTo: (ctx, file) => output path in generated app
|
|
8
|
+
* templates: ['filename'] — JHipster auto-appends .ejs
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const PLAYWRIGHT_TEMPLATE_SOURCE_DIR = 'src/test/javascript/cypress/';
|
|
12
|
+
|
|
13
|
+
export const playwrightFiles = {
|
|
14
|
+
common: [
|
|
15
|
+
{
|
|
16
|
+
templates: ['playwright.config.ts'],
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
clientTestFw: [
|
|
20
|
+
{
|
|
21
|
+
path: PLAYWRIGHT_TEMPLATE_SOURCE_DIR,
|
|
22
|
+
renameTo: (ctx, file) => `${ctx.clientTestDir}playwright/${file}`,
|
|
23
|
+
templates: [
|
|
24
|
+
'fixtures/integration-test.png',
|
|
25
|
+
'e2e/administration/administration.spec.ts',
|
|
26
|
+
'support/commands.ts',
|
|
27
|
+
'support/navbar.ts',
|
|
28
|
+
'support/index.ts',
|
|
29
|
+
'support/entity.ts',
|
|
30
|
+
'support/management.ts',
|
|
31
|
+
'tsconfig.json',
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
condition: generator => !generator.applicationTypeMicroservice,
|
|
36
|
+
path: PLAYWRIGHT_TEMPLATE_SOURCE_DIR,
|
|
37
|
+
renameTo: (ctx, file) => `${ctx.clientTestDir}playwright/${file}`,
|
|
38
|
+
templates: ['e2e/account/logout.spec.ts'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
condition: generator => !generator.authenticationTypeOauth2,
|
|
42
|
+
path: PLAYWRIGHT_TEMPLATE_SOURCE_DIR,
|
|
43
|
+
renameTo: (ctx, file) => `${ctx.clientTestDir}playwright/${file}`,
|
|
44
|
+
templates: ['e2e/account/login-page.spec.ts'],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
condition: generator => Boolean(generator.generateUserManagement),
|
|
48
|
+
path: PLAYWRIGHT_TEMPLATE_SOURCE_DIR,
|
|
49
|
+
renameTo: (ctx, file) => `${ctx.clientTestDir}playwright/${file}`,
|
|
50
|
+
templates: [
|
|
51
|
+
'e2e/account/register-page.spec.ts',
|
|
52
|
+
'e2e/account/settings-page.spec.ts',
|
|
53
|
+
'e2e/account/password-page.spec.ts',
|
|
54
|
+
'e2e/account/reset-password-page.spec.ts',
|
|
55
|
+
'support/account.ts',
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
condition: generator => generator.authenticationTypeOauth2,
|
|
60
|
+
path: PLAYWRIGHT_TEMPLATE_SOURCE_DIR,
|
|
61
|
+
renameTo: (ctx, file) => `${ctx.clientTestDir}playwright/${file}`,
|
|
62
|
+
templates: ['support/oauth2.ts'],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const entityPlaywrightFiles = {
|
|
68
|
+
tests: [
|
|
69
|
+
{
|
|
70
|
+
path: PLAYWRIGHT_TEMPLATE_SOURCE_DIR,
|
|
71
|
+
renameTo: ctx => `${ctx.clientTestDir}playwright/e2e/entity/${ctx.entityFileName}.spec.ts`,
|
|
72
|
+
templates: ['e2e/entity/_entity_.spec.ts'],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import BaseApplicationGenerator from 'generator-jhipster/generators/base-application';
|
|
2
|
+
import { createFaker } from 'generator-jhipster/generators/base-application/support';
|
|
3
|
+
import { generateTestEntity } from 'generator-jhipster/generators/client/support';
|
|
4
|
+
|
|
5
|
+
import { entityPlaywrightFiles, playwrightFiles } from './files.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Simple Java-style string hash code (same as JHipster internal stringHashCode).
|
|
9
|
+
* Used to seed faker for reproducible test data.
|
|
10
|
+
*/
|
|
11
|
+
function stringHashCode(str) {
|
|
12
|
+
let hash = 0;
|
|
13
|
+
for (let i = 0; i < str.length; i++) {
|
|
14
|
+
const char = str.charCodeAt(i);
|
|
15
|
+
hash = ((hash << 5) - hash) + char;
|
|
16
|
+
hash |= 0; // Convert to 32-bit integer
|
|
17
|
+
}
|
|
18
|
+
return hash;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default class extends BaseApplicationGenerator {
|
|
22
|
+
constructor(args, opts, features) {
|
|
23
|
+
super(args, opts, { ...features, checkBlueprint: true });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async beforeQueue() {
|
|
27
|
+
await this.dependsOnJHipster('bootstrap-application');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get [BaseApplicationGenerator.PREPARING]() {
|
|
31
|
+
return this.asPreparingTaskGroup({
|
|
32
|
+
setPlaywrightProperties({ application }) {
|
|
33
|
+
application.playwrightDir = `${application.clientTestDir}playwright/`;
|
|
34
|
+
// Set Cypress-specific defaults expected by entity template
|
|
35
|
+
// (normally set by the Cypress generator's PREPARING phase)
|
|
36
|
+
application.cypressBootstrapEntities ??= true;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get [BaseApplicationGenerator.POST_PREPARING_EACH_ENTITY]() {
|
|
42
|
+
return this.asPreparingEachEntityTaskGroup({
|
|
43
|
+
prepareEntityForTemplates({ entity }) {
|
|
44
|
+
// Set entity-level defaults expected by entity test template
|
|
45
|
+
// (normally set by Cypress generator's POST_PREPARING_EACH_ENTITY phase)
|
|
46
|
+
entity.workaroundEntityCannotBeEmpty ??= false;
|
|
47
|
+
entity.workaroundInstantReactiveMariaDB ??= false;
|
|
48
|
+
entity.generateEntityCypress ??= !entity.skipClient || entity.builtInUserManagement;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get [BaseApplicationGenerator.WRITING]() {
|
|
54
|
+
return this.asWritingTaskGroup({
|
|
55
|
+
async writePlaywrightFiles({ application }) {
|
|
56
|
+
const faker = await createFaker();
|
|
57
|
+
faker.seed(stringHashCode(application.baseName));
|
|
58
|
+
const context = { ...application, faker };
|
|
59
|
+
await this.writeFiles({
|
|
60
|
+
sections: playwrightFiles,
|
|
61
|
+
context,
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get [BaseApplicationGenerator.WRITING_ENTITIES]() {
|
|
68
|
+
return this.asWritingEntitiesTaskGroup({
|
|
69
|
+
async writeEntityPlaywrightFiles({ application, entities }) {
|
|
70
|
+
for (const entity of entities.filter(
|
|
71
|
+
e => e.generateEntityCypress && !e.builtInUser && !e.embedded && !e.entityClientModelOnly
|
|
72
|
+
)) {
|
|
73
|
+
const context = { ...application, ...entity };
|
|
74
|
+
await this.writeFiles({
|
|
75
|
+
sections: entityPlaywrightFiles,
|
|
76
|
+
context,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get [BaseApplicationGenerator.POST_WRITING]() {
|
|
84
|
+
return this.asPostWritingTaskGroup({
|
|
85
|
+
addPlaywrightDependencies({ application }) {
|
|
86
|
+
if (!application.clientFrameworkBuiltIn) return;
|
|
87
|
+
|
|
88
|
+
const packageJsonStorage = this.createStorage(
|
|
89
|
+
this.destinationPath(application.clientRootDir || '', 'package.json'),
|
|
90
|
+
);
|
|
91
|
+
const dependencies = packageJsonStorage.createStorage('dependencies');
|
|
92
|
+
const devDependencies = packageJsonStorage.createStorage('devDependencies');
|
|
93
|
+
devDependencies.set('@playwright/test', '1.58.2');
|
|
94
|
+
|
|
95
|
+
if (application.clientFrameworkAngular) {
|
|
96
|
+
// ng-bootstrap and Bootstrap both declare Popper as a peer dependency.
|
|
97
|
+
dependencies.set('@popperjs/core', '^2.11.8');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const scriptsStorage = packageJsonStorage.createStorage('scripts');
|
|
101
|
+
scriptsStorage.set('playwright', 'npx playwright test --ui');
|
|
102
|
+
scriptsStorage.set('e2e', 'npx playwright test --headed');
|
|
103
|
+
scriptsStorage.set('e2e:headless', 'npx playwright test');
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
generateTestEntity(fields) {
|
|
109
|
+
return generateTestEntity(fields);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineConfig, devices } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
testDir: '<%= clientTestDir %>playwright/e2e',
|
|
5
|
+
fullyParallel: false,
|
|
6
|
+
forbidOnly: !!process.env.CI,
|
|
7
|
+
retries: process.env.CI ? 2 : 0,
|
|
8
|
+
workers: process.env.CI ? 1 : 2,
|
|
9
|
+
reporter: 'html',
|
|
10
|
+
use: {
|
|
11
|
+
baseURL: 'http://localhost:<%= devServerPortProxy || devServerPort || gatewayServerPort || serverPort %>/',
|
|
12
|
+
trace: 'on-first-retry',
|
|
13
|
+
viewport: { width: 1200, height: 720 },
|
|
14
|
+
},
|
|
15
|
+
expect: {
|
|
16
|
+
timeout: 10_000,
|
|
17
|
+
},
|
|
18
|
+
projects: [
|
|
19
|
+
{
|
|
20
|
+
name: 'chromium',
|
|
21
|
+
use: { ...devices['Desktop Chrome'] },
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
webServer: {
|
|
25
|
+
command: 'npm run webapp:dev<% if (clientFrameworkAngular) { %> -- --open=false<% } %>',
|
|
26
|
+
url: 'http://localhost:<%= devServerPortProxy || devServerPort || gatewayServerPort || serverPort %>/',
|
|
27
|
+
reuseExistingServer: !process.env.CI,
|
|
28
|
+
timeout: 120_000,
|
|
29
|
+
},
|
|
30
|
+
});
|
package/generators/cypress/templates/src/test/javascript/cypress/e2e/account/login-page.spec.ts.ejs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<%#
|
|
2
|
+
Source EJS variables: authenticationTypeSession, clientFrameworkAngular, clientFrameworkReact
|
|
3
|
+
-%>
|
|
4
|
+
import { test, expect } from '@playwright/test';
|
|
5
|
+
import {
|
|
6
|
+
titleLoginSelector,
|
|
7
|
+
errorLoginSelector,
|
|
8
|
+
usernameLoginSelector,
|
|
9
|
+
passwordLoginSelector,
|
|
10
|
+
submitLoginSelector,
|
|
11
|
+
credentials,
|
|
12
|
+
} from '../../support/commands';
|
|
13
|
+
import { clickOnLoginItem } from '../../support/navbar';
|
|
14
|
+
|
|
15
|
+
test.describe('login page', () => {
|
|
16
|
+
let username: string;
|
|
17
|
+
let password: string;
|
|
18
|
+
|
|
19
|
+
test.beforeAll(() => {
|
|
20
|
+
const creds = credentials();
|
|
21
|
+
username = creds.username;
|
|
22
|
+
password = creds.password;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test.beforeEach(async ({ page }) => {
|
|
26
|
+
await page.goto('/');
|
|
27
|
+
await clickOnLoginItem(page);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('greets with signin', async ({ page }) => {
|
|
31
|
+
await expect(page.locator(titleLoginSelector)).toBeVisible();
|
|
32
|
+
});
|
|
33
|
+
<%_ if (clientFrameworkAngular) { _%>
|
|
34
|
+
|
|
35
|
+
test('greets visiting /login directly', async ({ page }) => {
|
|
36
|
+
await page.goto('/login');
|
|
37
|
+
await expect(page.locator(titleLoginSelector)).toBeVisible();
|
|
38
|
+
});
|
|
39
|
+
<%_ } _%>
|
|
40
|
+
|
|
41
|
+
test('requires username', async ({ page }) => {
|
|
42
|
+
await page.locator(passwordLoginSelector).fill('a-password');
|
|
43
|
+
await page.locator(submitLoginSelector).click();
|
|
44
|
+
<%_ if (!clientFrameworkReact) { _%>
|
|
45
|
+
const response = await page.waitForResponse('**/api/<% if (authenticationTypeSession) { %>authentication<% } else { %>authenticate<% } %>');
|
|
46
|
+
expect(response.status()).toBe(<% if (authenticationTypeSession) { %>401<% } else { %>400<% } %>);
|
|
47
|
+
<%_ } _%>
|
|
48
|
+
// login page should stay open when login fails
|
|
49
|
+
await expect(page.locator(titleLoginSelector)).toBeVisible();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('requires password', async ({ page }) => {
|
|
53
|
+
await page.locator(usernameLoginSelector).fill('a-login');
|
|
54
|
+
await page.locator(submitLoginSelector).click();
|
|
55
|
+
<%_ if (!clientFrameworkReact) { _%>
|
|
56
|
+
const response = await page.waitForResponse('**/api/<% if (authenticationTypeSession) { %>authentication<% } else { %>authenticate<% } %>');
|
|
57
|
+
expect(response.status()).toBe(<% if (authenticationTypeSession) { %>401<% } else { %>400<% } %>);
|
|
58
|
+
await expect(page.locator(errorLoginSelector)).toBeVisible();
|
|
59
|
+
<%_ } else { _%>
|
|
60
|
+
// login page should stay open when login fails
|
|
61
|
+
await expect(page.locator(titleLoginSelector)).toBeVisible();
|
|
62
|
+
<%_ } _%>
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('errors when password is incorrect', async ({ page }) => {
|
|
66
|
+
await page.locator(usernameLoginSelector).fill(username);
|
|
67
|
+
await page.locator(passwordLoginSelector).fill('bad-password');
|
|
68
|
+
const responsePromise = page.waitForResponse('**/api/<% if (authenticationTypeSession) { %>authentication<% } else { %>authenticate<% } %>');
|
|
69
|
+
await page.locator(submitLoginSelector).click();
|
|
70
|
+
const response = await responsePromise;
|
|
71
|
+
expect(response.status()).toBe(401);
|
|
72
|
+
await expect(page.locator(errorLoginSelector)).toBeVisible();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('go to home page when successfully logs in', async ({ page }) => {
|
|
76
|
+
await page.locator(usernameLoginSelector).fill(username);
|
|
77
|
+
await page.locator(passwordLoginSelector).fill(password);
|
|
78
|
+
const responsePromise = page.waitForResponse('**/api/<% if (authenticationTypeSession) { %>authentication<% } else { %>authenticate<% } %>');
|
|
79
|
+
await page.locator(submitLoginSelector).click();
|
|
80
|
+
const response = await responsePromise;
|
|
81
|
+
expect(response.status()).toBe(200);
|
|
82
|
+
});
|
|
83
|
+
});
|