From 1cc4ef374ff7b83713f54541c31d55e2ae499c34 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 15 Dec 2023 14:34:53 +0100 Subject: [PATCH 1/6] test(cy): skip test failing due to server issue https://github.com/nextcloud/server/issues/42306 causes the DELETE request to fail with 423 Locked. Signed-off-by: Max --- cypress/e2e/attachments.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/attachments.spec.js b/cypress/e2e/attachments.spec.js index 0222f949768..5030bd06c79 100644 --- a/cypress/e2e/attachments.spec.js +++ b/cypress/e2e/attachments.spec.js @@ -371,7 +371,8 @@ describe('Test all attachment insertion methods', () => { }) }) - it('test if attachment folder is deleted after having deleted a markdown file', () => { + // Skip as https://github.com/nextcloud/server/issues/42306 causes this to fail. + it.skip('test if attachment folder is deleted after having deleted a markdown file', () => { const fileName = 'deleteSource.md' cy.createMarkdown(fileName, '![git](.attachments.123/github.png)', false).then((fileId) => { const attachmentsFolder = `.attachments.${fileId}` From 2c8e2268dedc7ea1d28ea9c61bcd16b1028ab86e Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Dec 2023 12:54:33 +0100 Subject: [PATCH 2/6] test(cy): simplify requesttoken handling * Use `this.requesttoken` rather than `cy.get(@requesttoken)` to use the same value rather than re-evaluating the query. * After visit `this.requesttoken` will be set. No need to attempt to load the token from the window if it is not. * Use a simple `if` statement instead of `cypress-if`. * This also cleans up the cypress logs significantly. Signed-off-by: Max --- cypress/support/commands.js | 30 +++++++++--------------------- package-lock.json | 19 ------------------- package.json | 1 - 3 files changed, 9 insertions(+), 41 deletions(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c6a5c5cd502..5dc3203ca1a 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -22,7 +22,6 @@ import axios from '@nextcloud/axios' import { addCommands } from '@nextcloud/cypress' -import 'cypress-if' import compareSnapshotCommand from 'cypress-visual-regression/dist/command.js' // eslint-disable-next-line no-unused-vars,n/no-extraneous-import @@ -57,27 +56,16 @@ Cypress.Commands.overwrite('visit', (originalFn, url, options) => { }) Cypress.Commands.add('getRequestToken', () => { - cy.get('@requesttoken') - .if((token) => !token) - .then(() => { - cy.window() - .then((win) => cy.wrap(win?.OC?.requestToken)) - .if((token) => !!token) - .then((token) => { - cy.log('Request token from window', token) - }) + cy.then(function() { + if (this.requesttoken) { + return this.requesttoken + } else { + cy.log('Fetching request token') + return cy.request('/csrftoken') + .its('body.token') .as('requesttoken') - .else() - .then((token) => { - cy.log('Request token fetching', token) - return cy.request('/csrftoken') - .then(({ body }) => { - return body.token - }) - }).as('requesttoken') - }) - - return cy.get('@requesttoken') + } + }) }) Cypress.Commands.add('ocsRequest', (options) => { diff --git a/package-lock.json b/package-lock.json index fac6abfb537..ec7689702e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -99,7 +99,6 @@ "@vue/vue2-jest": "^29.2.6", "@vueuse/core": "^10.7.0", "cypress": "^13.6.1", - "cypress-if": "^1.10.5", "cypress-split": "^1.17.1", "cypress-visual-regression": "^3.0.0", "eslint-plugin-cypress": "^2.15.1", @@ -8863,15 +8862,6 @@ "node": "^16.0.0 || ^18.0.0 || >=20.0.0" } }, - "node_modules/cypress-if": { - "version": "1.10.5", - "resolved": "https://registry.npmjs.org/cypress-if/-/cypress-if-1.10.5.tgz", - "integrity": "sha512-7EJSTvoUM+6XumIA7T0cU69dkkdUEmncvIuFFgQ3ry57m2kXc9vtNTCdGjfnGQgMBDRR6vtx7no1ZDDg8IOICA==", - "dev": true, - "dependencies": { - "debug": "^4.3.4" - } - }, "node_modules/cypress-split": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/cypress-split/-/cypress-split-1.17.1.tgz", @@ -32177,15 +32167,6 @@ } } }, - "cypress-if": { - "version": "1.10.5", - "resolved": "https://registry.npmjs.org/cypress-if/-/cypress-if-1.10.5.tgz", - "integrity": "sha512-7EJSTvoUM+6XumIA7T0cU69dkkdUEmncvIuFFgQ3ry57m2kXc9vtNTCdGjfnGQgMBDRR6vtx7no1ZDDg8IOICA==", - "dev": true, - "requires": { - "debug": "^4.3.4" - } - }, "cypress-split": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/cypress-split/-/cypress-split-1.17.1.tgz", diff --git a/package.json b/package.json index b6756ba1f4e..dd2006f6d71 100644 --- a/package.json +++ b/package.json @@ -129,7 +129,6 @@ "@vue/vue2-jest": "^29.2.6", "@vueuse/core": "^10.7.0", "cypress": "^13.6.1", - "cypress-if": "^1.10.5", "cypress-split": "^1.17.1", "cypress-visual-regression": "^3.0.0", "eslint-plugin-cypress": "^2.15.1", From 8268961b95720ffa8719bb301a8078e7ca4e31d0 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Dec 2023 13:43:40 +0100 Subject: [PATCH 3/6] fix(cy): attachment spec share test * call `cy.showHiddenfiles()` before loading the page. * Clear `requesttoken` in `cy.login()`. Signed-off-by: Max --- cypress/e2e/attachments.spec.js | 2 +- cypress/support/commands.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/attachments.spec.js b/cypress/e2e/attachments.spec.js index 5030bd06c79..7a2e6066739 100644 --- a/cypress/e2e/attachments.spec.js +++ b/cypress/e2e/attachments.spec.js @@ -402,6 +402,7 @@ describe('Test all attachment insertion methods', () => { }) cy.login(recipient) + cy.showHiddenFiles() cy.visit('/apps/files') // check the file list @@ -409,7 +410,6 @@ describe('Test all attachment insertion methods', () => { .should('exist') cy.getFile('github.png') .should('not.exist') - cy.showHiddenFiles() // check the attachment folder is not there cy.getFile('testShared.md') diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 5dc3203ca1a..dc2b1e6cc64 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -43,6 +43,7 @@ Cypress.Commands.overwrite('login', (login, user) => { win.location.href = 'about:blank' }) auth = { user: user.userId, password: user.password } + cy.wrap(null).as('requesttoken') login(user) }) From e9f295793ff04e48cbbbc49cddd528584ef1f178 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Dec 2023 13:44:21 +0100 Subject: [PATCH 4/6] test(cy): silence `cy.window` Signed-off-by: Max --- cypress/support/commands.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index dc2b1e6cc64..edcd59375c8 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -31,6 +31,7 @@ compareSnapshotCommand() const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '') Cypress.env('baseUrl', url) +const silent = { log: false } addCommands() @@ -39,7 +40,7 @@ addCommands() // and also to determine paths, urls and the like. let auth Cypress.Commands.overwrite('login', (login, user) => { - cy.window().then((win) => { + cy.window(silent).then((win) => { win.location.href = 'about:blank' }) auth = { user: user.userId, password: user.password } @@ -50,9 +51,11 @@ Cypress.Commands.overwrite('login', (login, user) => { Cypress.Commands.overwrite('visit', (originalFn, url, options) => { // Make sure that each visit call that triggers a page load will update the stored requesttoken return originalFn(url, options).then((result) => { - cy.window() - .then((win) => cy.wrap(win?.OC?.requestToken)) - .as('requesttoken') + cy.window(silent) + .then((win) => { + cy.wrap(win?.OC?.requestToken) + .as('requesttoken') + }) }) }) @@ -328,7 +331,7 @@ Cypress.Commands.add('getFileContent', (path) => { }) Cypress.Commands.add('propfindFolder', (path, depth = 0) => { - return cy.window() + return cy.window(silent) .then(win => { const files = win.OC.Files const PROPERTY_WORKSPACE_FILE @@ -479,7 +482,7 @@ Cypress.Commands.add('openWorkspace', () => { }) Cypress.Commands.add('configureText', (key, value) => { - return cy.window().then(win => { + return cy.window(silent).then(win => { return axios.post( `${url}/index.php/apps/text/settings`, { key, value }, From c83beee6e207da2a9a58efae8383cdcce2241dc2 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Dec 2023 14:05:55 +0100 Subject: [PATCH 5/6] chore(ci): use current upload-artifact action Fix the warning in CI. Signed-off-by: Max --- .github/workflows/cypress.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index e6f282da88f..75ffd65e36f 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -169,7 +169,7 @@ jobs: - name: Upload test failure screenshots - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: Upload screenshots @@ -179,7 +179,7 @@ jobs: retention-days: 5 - name: Upload nextcloud logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: Upload nextcloud log From ee99bc13852b9cbf2e3b328af41a689eb76407a7 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 13 Dec 2023 14:29:21 +0100 Subject: [PATCH 6/6] test(ci): upload nextcloud.log to different files Signed-off-by: Max --- .github/workflows/cypress.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 75ffd65e36f..3be3bd6be9d 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -182,7 +182,7 @@ jobs: uses: actions/upload-artifact@v3 if: failure() with: - name: Upload nextcloud log + name: cypress-${{ matrix.containers }}.log path: data/nextcloud.log retention-days: 5