Skip to content

Commit 56b7f6f

Browse files
Merge pull request #758 from nextcloud-libraries/e2e-test-server
E2e test server
2 parents b09d5a4 + e21dd10 commit 56b7f6f

25 files changed

Lines changed: 17950 additions & 27910 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ typings/
6565
/dist
6666
cypress/screenshots
6767
cypress/videos
68+
69+
# playwright artifacts
70+
test-results/
71+
playwright-report/

README.md

Lines changed: 69 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
- SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
- SPDX-License-Identifier: AGPL-3.0-or-later
44
-->
5-
# \@nextcloud/cypress
5+
# \@nextcloud/e2e-test-server
66

7-
[![REUSE status](https://api.reuse.software/badge/github.com/nextcloud-libraries/nextcloud-cypress)](https://api.reuse.software/info/github.com/nextcloud-libraries/nextcloud-cypress) [![npm last version](https://img.shields.io/npm/v/@nextcloud/cypress.svg?style=flat-square)](https://www.npmjs.com/package/@nextcloud/cypress) ![Codecov](https://img.shields.io/codecov/c/github/nextcloud/nextcloud-cypress?style=flat-square)
7+
[![REUSE status](https://api.reuse.software/badge/github.com/nextcloud-libraries/nextcloud-cypress)](https://api.reuse.software/info/github.com/nextcloud-libraries/nextcloud-cypress) [![npm last version](https://img.shields.io/npm/v/@nextcloud/e2e-test-server.svg?style=flat-square)](https://www.npmjs.com/package/@nextcloud/e2e-test-server) ![Codecov](https://img.shields.io/codecov/c/github/nextcloud/nextcloud-cypress?style=flat-square)
88

9-
Nextcloud cypress helpers for Nextcloud apps and libraries
9+
Nextcloud e2e test server and utils for cypress and playwright.
1010

1111
## New package available
1212

@@ -16,50 +16,45 @@ that will work nicely with both cypress and playwright.
1616
It will eventually superseed `@nextcloud/cypress`.
1717
When starting a new project we recommend using `@nextcloud/e2e-test-server`.
1818

19-
## Commands
19+
## Status
2020

21-
You can import individual commands or all at once
22-
You can find [the list of all available commands here](https://nextcloud.github.io/nextcloud-cypress/modules/commands.html)
23-
24-
```js
25-
// cypress/support/commands.js
26-
import { addCommands } from '@nextcloud/cypress'
27-
28-
addCommands()
29-
```
21+
This package is currently work in progress and will change significantly until version 1.0.
22+
In particular cypress specific utils such as selectors will be dropped unless they are widely used.
3023

31-
```js
32-
// cypress/support/commands.js
33-
import { getNc } from '@nextcloud/cypress/commands'
34-
35-
Cypress.Commands.add('getNc', getNc)
36-
```
24+
## Starting Nextcloud Docker container
3725

38-
## Selectors
26+
### Playwright
3927

40-
You can find [the list of all available selectors here](https://nextcloud.github.io/nextcloud-cypress/modules/selectors.html)
28+
1. Copy `playwright.config.mjs` and `playwright` folder from this repository!
29+
2. Add the `@playwright/test` dependency:
30+
```
31+
npm install --save-dev '@playwright/test'
32+
```
33+
3. Add the `start:nextcloud` script to your package.json
34+
```json
35+
{
36+
"start:nextcloud": "node playwright/start-nextcloud-server.mjs",
37+
}
38+
```
39+
4. Install chromium for playwright:
40+
```
41+
npx playwright install chromium --only-shell
42+
```
43+
5. Run playwright tests:
44+
```
45+
npx playwright test
46+
```
47+
6. Add `.github/workflows/playwright.yml` to your repository!
48+
7. Write your own tests!
4149

42-
```js
43-
import { UploadPicker as UploadPickerComponent} from '../../dist/index.js'
44-
import { UploadPicker, UploadPickerInput } from '@nextcloud/cypress/selectors'
4550

46-
describe('UploadPicker rendering', () => {
47-
it('Renders default UploadPicker', () => {
48-
cy.mount(UploadPickerComponent)
49-
cy.getNc(UploadPicker).should('exist')
50-
.should('have.class', 'upload-picker')
51-
cy.getNc(UploadPickerInput).should('exist')
52-
})
53-
})
54-
```
5551

56-
## Starting Nextcloud Docker container
52+
### Cypress
5753

58-
It is possible to automatically start a docker container providing a Nextcloud instance for testing.
59-
Therefor adjust your `cypress.config.ts` (or `.js`):
54+
You can use the `cypress` folder and the `cypress.config.ts` in this repository as starting points or adjust your `cypress.config.ts` (or `.js`):
6055

6156
```js
62-
import { configureNextcloud, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/cypress/docker'
57+
import { configureNextcloud, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/e2e-test-server'
6358

6459
export default defineConfig({
6560
// ...
@@ -89,3 +84,40 @@ export default defineConfig({
8984
},
9085
})
9186
```
87+
88+
## Cypress commands
89+
90+
You can import individual commands or all at once
91+
You can find [the list of all available commands here](https://nextcloud.github.io/nextcloud-cypress/modules/commands.html)
92+
93+
```js
94+
// cypress/support/commands.js
95+
import { addCommands } from '@nextcloud/e2e-test-server/cypress'
96+
97+
addCommands()
98+
```
99+
100+
```js
101+
// cypress/support/commands.js
102+
import { login } from '@nextcloud/e2e-test-server/commands'
103+
104+
Cypress.Commands.add('login', login)
105+
```
106+
107+
## Selectors (:warn: deprecated)
108+
109+
You can find [the list of all available selectors here](https://nextcloud.github.io/nextcloud-cypress/modules/selectors.html)
110+
111+
```js
112+
import { UploadPicker as UploadPickerComponent} from '../../dist/index.js'
113+
import { UploadPicker, UploadPickerInput } from '@nextcloud/cypress/selectors'
114+
115+
describe('UploadPicker rendering', () => {
116+
it('Renders default UploadPicker', () => {
117+
cy.mount(UploadPickerComponent)
118+
cy.getNc(UploadPicker).should('exist')
119+
.should('have.class', 'upload-picker')
120+
cy.getNc(UploadPickerInput).should('exist')
121+
})
122+
})
123+
```

REUSE.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
22
# SPDX-License-Identifier: AGPL-3.0-or-later
33
version = 1
4-
SPDX-PackageName = "nextcloud-cypress"
4+
SPDX-PackageName = "nextcloud-e2e-test-server"
55
SPDX-PackageSupplier = "Nextcloud <info@nextcloud.com>"
6-
SPDX-PackageDownloadLocation = "https://github.com/nextcloud-libraries/nextcloud-cypressg"
6+
SPDX-PackageDownloadLocation = "https://github.com/nextcloud-libraries/nextcloud-cypress"
77

88
[[annotations]]
99
path = ["package-lock.json", "package.json", "tsconfig.json", "__tests__/tsconfig.json", "cypress/tsconfig.json"]

cypress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
// Making sure we're forcing the development mode
66
process.env.NODE_ENV = 'development'
7-
process.env.npm_package_name = 'nextcloud-cypress'
7+
process.env.npm_package_name = 'nextcloud-e2e-test-server'
88

99
/* eslint-disable import/first */
1010
import { configureNextcloud, createSnapshot, setupUsers, startNextcloud, stopNextcloud, waitOnNextcloud } from './lib/docker'

cypress/e2e/sessions.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import { User } from '../../dist'
5+
import { User } from '../../dist/cypress'
66

77
describe('Login and logout', function() {
88
it('Login and see the default files list', function() {

cypress/e2e/snapshots.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import { User } from '../../dist'
5+
import { User } from '../../dist/cypress'
66
import { randHash } from '../utils'
77

88
describe('Create a snapshot and a user', function() {

cypress/e2e/users.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import { User } from '../../dist'
5+
import { User } from '../../dist/cypress'
66
import { randHash } from '../utils'
77

88
describe('Create user and login', function() {

cypress/support/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
// ***********************************************
1515
//
1616

17-
import { addCommands } from '../../dist/'
17+
import { addCommands } from '../../dist/cypress'
1818
addCommands()

jest.config.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/User.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
export class User {
7+
userId: string
8+
password: string
9+
language: string
10+
11+
constructor(user: string, password: string = user, language = 'en') {
12+
this.userId = user
13+
this.password = password
14+
this.language = language
15+
}
16+
17+
static createRandom() {
18+
const uid = (Math.random() + 1).toString(36).substring(7)
19+
return new User(uid)
20+
}
21+
}
22+

0 commit comments

Comments
 (0)