Skip to content

Commit b083963

Browse files
Merge pull request #5129 from nextcloud/test/better-cy-logs
Cypress: Improve request token handling, attachments test
2 parents 72397d1 + 2263c8f commit b083963

File tree

5 files changed

+23
-51
lines changed

5 files changed

+23
-51
lines changed

.github/workflows/cypress.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ jobs:
168168

169169

170170
- name: Upload test failure screenshots
171-
uses: actions/upload-artifact@v2
171+
uses: actions/upload-artifact@v3
172172
if: failure()
173173
with:
174174
name: Upload screenshots
@@ -178,10 +178,10 @@ jobs:
178178
retention-days: 5
179179

180180
- name: Upload nextcloud logs
181-
uses: actions/upload-artifact@v2
181+
uses: actions/upload-artifact@v3
182182
if: failure()
183183
with:
184-
name: Upload nextcloud log
184+
name: cypress-${{ matrix.containers }}.log
185185
path: data/nextcloud.log
186186
retention-days: 5
187187

cypress/e2e/attachments.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,14 @@ describe('Test all attachment insertion methods', () => {
401401
})
402402

403403
cy.login(recipient)
404+
cy.showHiddenFiles()
404405

405406
cy.visit('/apps/files')
406407
// check the file list
407408
cy.getFile('testShared.md')
408409
.should('exist')
409410
cy.getFile('github.png')
410411
.should('not.exist')
411-
cy.showHiddenFiles()
412412

413413
// check the attachment folder is not there
414414
cy.getFile('testShared.md')

cypress/support/commands.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import axios from '@nextcloud/axios'
2424
import { addCommands } from '@nextcloud/cypress'
25-
import 'cypress-if'
2625
import compareSnapshotCommand from 'cypress-visual-regression/dist/command.js'
2726

2827
// eslint-disable-next-line no-unused-vars,n/no-extraneous-import
@@ -32,6 +31,7 @@ compareSnapshotCommand()
3231

3332
const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '')
3433
Cypress.env('baseUrl', url)
34+
const silent = { log: false }
3535

3636
addCommands()
3737

@@ -40,44 +40,36 @@ addCommands()
4040
// and also to determine paths, urls and the like.
4141
let auth
4242
Cypress.Commands.overwrite('login', (login, user) => {
43-
cy.window().then((win) => {
43+
cy.window(silent).then((win) => {
4444
win.location.href = 'about:blank'
4545
})
4646
auth = { user: user.userId, password: user.password }
47+
cy.wrap(null).as('requesttoken')
4748
login(user)
4849
})
4950

5051
Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
5152
// Make sure that each visit call that triggers a page load will update the stored requesttoken
5253
return originalFn(url, options).then((result) => {
53-
cy.window()
54-
.then((win) => cy.wrap(win?.OC?.requestToken))
55-
.as('requesttoken')
54+
cy.window(silent)
55+
.then((win) => {
56+
cy.wrap(win?.OC?.requestToken)
57+
.as('requesttoken')
58+
})
5659
})
5760
})
5861

5962
Cypress.Commands.add('getRequestToken', () => {
60-
cy.get('@requesttoken')
61-
.if((token) => !token)
62-
.then(() => {
63-
cy.window()
64-
.then((win) => cy.wrap(win?.OC?.requestToken))
65-
.if((token) => !!token)
66-
.then((token) => {
67-
cy.log('Request token from window', token)
68-
})
63+
cy.then(function() {
64+
if (this.requesttoken) {
65+
return this.requesttoken
66+
} else {
67+
cy.log('Fetching request token')
68+
return cy.request('/csrftoken')
69+
.its('body.token')
6970
.as('requesttoken')
70-
.else()
71-
.then((token) => {
72-
cy.log('Request token fetching', token)
73-
return cy.request('/csrftoken')
74-
.then(({ body }) => {
75-
return body.token
76-
})
77-
}).as('requesttoken')
78-
})
79-
80-
return cy.get('@requesttoken')
71+
}
72+
})
8173
})
8274

8375
Cypress.Commands.add('ocsRequest', (options) => {
@@ -339,7 +331,7 @@ Cypress.Commands.add('getFileContent', (path) => {
339331
})
340332

341333
Cypress.Commands.add('propfindFolder', (path, depth = 0) => {
342-
return cy.window()
334+
return cy.window(silent)
343335
.then(win => {
344336
const files = win.OC.Files
345337
const PROPERTY_WORKSPACE_FILE
@@ -490,7 +482,7 @@ Cypress.Commands.add('openWorkspace', (folder) => {
490482
})
491483

492484
Cypress.Commands.add('configureText', (key, value) => {
493-
return cy.window().then(win => {
485+
return cy.window(silent).then(win => {
494486
return axios.post(
495487
`${url}/index.php/apps/text/settings`,
496488
{ key, value },

package-lock.json

Lines changed: 0 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
"@vue/vue2-jest": "^29.2.6",
130130
"@vueuse/core": "^10.7.0",
131131
"cypress": "^13.6.1",
132-
"cypress-if": "^1.10.5",
133132
"cypress-split": "^1.17.1",
134133
"cypress-visual-regression": "^3.0.0",
135134
"eslint-plugin-cypress": "^2.15.1",

0 commit comments

Comments
 (0)