From 2e486cf684eb5ac5eab7202b5a3546579795fbc4 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Wed, 12 Oct 2022 12:13:18 -0500 Subject: [PATCH 1/3] Update to latest Cypress v9 --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 347b83811d..95a4e80e8a 100644 --- a/package.json +++ b/package.json @@ -169,7 +169,7 @@ "css-loader": "^6.2.0", "css-minimizer-webpack-plugin": "^3.4.1", "cssnano": "^5.0.6", - "cypress": "9.5.1", + "cypress": "9", "cypress-axe": "^0.14.0", "debug-loader": "^0.0.1", "deep-freeze": "0.0.1", diff --git a/yarn.lock b/yarn.lock index 9542bfdbe1..5d057b0d59 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4686,10 +4686,10 @@ cypress-axe@^0.14.0: resolved "https://registry.yarnpkg.com/cypress-axe/-/cypress-axe-0.14.0.tgz#5f5e70fb36b8cb3ba73a8ba01e9262ff1268d5e2" integrity sha512-7Rdjnko0MjggCmndc1wECAkvQBIhuy+DRtjF7bd5YPZRFvubfMNvrxfqD8PWQmxm7MZE0ffS4Xr43V6ZmvLopg== -cypress@9.5.1: - version "9.5.1" - resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.5.1.tgz#51162f3688cedf5ffce311b914ef49a7c1ece076" - integrity sha512-H7lUWB3Svr44gz1rNnj941xmdsCljXoJa2cDneAltjI9leKLMQLm30x6jLlpQ730tiVtIbW5HdUmBzPzwzfUQg== +cypress@9: + version "9.7.0" + resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.7.0.tgz#bf55b2afd481f7a113ef5604aa8b693564b5e744" + integrity sha512-+1EE1nuuuwIt/N1KXRR2iWHU+OiIt7H28jJDyyI4tiUftId/DrXYEwoDa5+kH2pki1zxnA0r6HrUGHV5eLbF5Q== dependencies: "@cypress/request" "^2.88.10" "@cypress/xvfb" "^1.2.4" @@ -4723,7 +4723,7 @@ cypress@9.5.1: listr2 "^3.8.3" lodash "^4.17.21" log-symbols "^4.0.0" - minimist "^1.2.5" + minimist "^1.2.6" ospath "^1.2.2" pretty-bytes "^5.6.0" proxy-from-env "1.0.0" From 14bafd61fe1b317ac872e65c6dc3d1c739ec6bbd Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Thu, 13 Oct 2022 12:19:40 -0500 Subject: [PATCH 2/3] Stabilize random authentication errors in e2e tests by using login form at all times. --- cypress/integration/my-dspace.spec.ts | 18 +++++++++++------ cypress/integration/submission.spec.ts | 15 ++++++++------ cypress/support/commands.ts | 27 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/cypress/integration/my-dspace.spec.ts b/cypress/integration/my-dspace.spec.ts index fa923dbcbc..48f44eecb9 100644 --- a/cypress/integration/my-dspace.spec.ts +++ b/cypress/integration/my-dspace.spec.ts @@ -4,10 +4,11 @@ import { testA11y } from 'cypress/support/utils'; describe('My DSpace page', () => { it('should display recent submissions and pass accessibility tests', () => { - cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - cy.visit('/mydspace'); + // This page is restricted, so we will be shown the login form. Fill it out & submit. + cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); + cy.get('ds-my-dspace-page').should('exist'); // At least one recent submission should be displayed @@ -36,10 +37,11 @@ describe('My DSpace page', () => { }); it('should have a working detailed view that passes accessibility tests', () => { - cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - cy.visit('/mydspace'); + // This page is restricted, so we will be shown the login form. Fill it out & submit. + cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); + cy.get('ds-my-dspace-page').should('exist'); // Click button in sidebar to display detailed view @@ -61,9 +63,11 @@ describe('My DSpace page', () => { // NOTE: Deleting existing submissions is exercised by submission.spec.ts it('should let you start a new submission & edit in-progress submissions', () => { - cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); cy.visit('/mydspace'); + // This page is restricted, so we will be shown the login form. Fill it out & submit. + cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); + // Open the New Submission dropdown cy.get('button[data-test="submission-dropdown"]').click(); // Click on the "Item" type in that dropdown @@ -131,9 +135,11 @@ describe('My DSpace page', () => { }); it('should let you import from external sources', () => { - cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); cy.visit('/mydspace'); + // This page is restricted, so we will be shown the login form. Fill it out & submit. + cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); + // Open the New Import dropdown cy.get('button[data-test="import-dropdown"]').click(); // Click on the "Item" type in that dropdown diff --git a/cypress/integration/submission.spec.ts b/cypress/integration/submission.spec.ts index 009c50115b..9eef596b02 100644 --- a/cypress/integration/submission.spec.ts +++ b/cypress/integration/submission.spec.ts @@ -6,11 +6,12 @@ describe('New Submission page', () => { // NOTE: We already test that new submissions can be started from MyDSpace in my-dspace.spec.ts it('should create a new submission when using /submit path & pass accessibility', () => { - cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - // Test that calling /submit with collection & entityType will create a new submission cy.visit('/submit?collection=' + TEST_SUBMIT_COLLECTION_UUID + '&entityType=none'); + // This page is restricted, so we will be shown the login form. Fill it out & submit. + cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); + // Should redirect to /workspaceitems, as we've started a new submission cy.url().should('include', '/workspaceitems'); @@ -33,11 +34,12 @@ describe('New Submission page', () => { }); it('should block submission & show errors if required fields are missing', () => { - cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - // Create a new submission cy.visit('/submit?collection=' + TEST_SUBMIT_COLLECTION_UUID + '&entityType=none'); + // This page is restricted, so we will be shown the login form. Fill it out & submit. + cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); + // Attempt an immediate deposit without filling out any fields cy.get('button#deposit').click(); @@ -92,11 +94,12 @@ describe('New Submission page', () => { }); it('should allow for deposit if all required fields completed & file uploaded', () => { - cy.login(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); - // Create a new submission cy.visit('/submit?collection=' + TEST_SUBMIT_COLLECTION_UUID + '&entityType=none'); + // This page is restricted, so we will be shown the login form. Fill it out & submit. + cy.loginViaForm(TEST_SUBMIT_USER, TEST_SUBMIT_USER_PASSWORD); + // Fill out all required fields (Title, Date) cy.get('input#dc_title').type('DSpace logo uploaded via e2e tests'); cy.get('input#dc_date_issued_year').type('2022'); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 30951d46f1..04c217aa0f 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -19,6 +19,14 @@ declare global { * @param password password to login as */ login(email: string, password: string): typeof login; + + /** + * Login via form before accessing the next page. Useful to fill out login + * form when a cy.visit() call is to an a page which requires authentication. + * @param email email to login as + * @param password password to login as + */ + loginViaForm(email: string, password: string): typeof loginViaForm; } } } @@ -26,6 +34,8 @@ declare global { /** * Login user via REST API directly, and pass authentication token to UI via * the UI's dsAuthInfo cookie. + * WARNING: WHILE THIS METHOD WORKS, OCCASIONALLY RANDOM AUTHENTICATION ERRORS OCCUR. + * At this time "loginViaForm()" seems more consistent/stable. * @param email email to login as * @param password password to login as */ @@ -81,3 +91,20 @@ function login(email: string, password: string): void { } // Add as a Cypress command (i.e. assign to 'cy.login') Cypress.Commands.add('login', login); + + +/** + * Login user via displayed login form + * @param email email to login as + * @param password password to login as + */ + function loginViaForm(email: string, password: string): void { + // Enter email + cy.get('ds-log-in [data-test="email"]').type(email); + // Enter password + cy.get('ds-log-in [data-test="password"]').type(password); + // Click login button + cy.get('ds-log-in [data-test="login-button"]').click(); +} +// Add as a Cypress command (i.e. assign to 'cy.loginViaForm') +Cypress.Commands.add('loginViaForm', loginViaForm); \ No newline at end of file From 11154d21be0a8e34a66f041fc3e1a19473542bd0 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Thu, 13 Oct 2022 12:50:39 -0500 Subject: [PATCH 3/3] Upgrade to latest axe-core for accessibility checks in e2e tests --- package.json | 4 ++-- yarn.lock | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 95a4e80e8a..fef8e89270 100644 --- a/package.json +++ b/package.json @@ -162,14 +162,14 @@ "@types/sanitize-html": "^2.6.2", "@typescript-eslint/eslint-plugin": "5.11.0", "@typescript-eslint/parser": "5.11.0", - "axe-core": "^4.3.3", + "axe-core": "^4.4.3", "compression-webpack-plugin": "^9.2.0", "copy-webpack-plugin": "^6.4.1", "cross-env": "^7.0.3", "css-loader": "^6.2.0", "css-minimizer-webpack-plugin": "^3.4.1", "cssnano": "^5.0.6", - "cypress": "9", + "cypress": "9.7.0", "cypress-axe": "^0.14.0", "debug-loader": "^0.0.1", "deep-freeze": "0.0.1", diff --git a/yarn.lock b/yarn.lock index 5d057b0d59..7fe021a843 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3221,10 +3221,10 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA== -axe-core@^4.3.3: - version "4.4.1" - resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.1.tgz#7dbdc25989298f9ad006645cd396782443757413" - integrity sha512-gd1kmb21kwNuWr6BQz8fv6GNECPBnUasepcoLbekws23NVBLODdsClRZ+bQ8+9Uomf3Sm3+Vwn0oYG9NvwnJCw== +axe-core@^4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.3.tgz#11c74d23d5013c0fa5d183796729bc3482bd2f6f" + integrity sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w== axios@0.21.4: version "0.21.4" @@ -4686,7 +4686,7 @@ cypress-axe@^0.14.0: resolved "https://registry.yarnpkg.com/cypress-axe/-/cypress-axe-0.14.0.tgz#5f5e70fb36b8cb3ba73a8ba01e9262ff1268d5e2" integrity sha512-7Rdjnko0MjggCmndc1wECAkvQBIhuy+DRtjF7bd5YPZRFvubfMNvrxfqD8PWQmxm7MZE0ffS4Xr43V6ZmvLopg== -cypress@9: +cypress@9.7.0: version "9.7.0" resolved "https://registry.yarnpkg.com/cypress/-/cypress-9.7.0.tgz#bf55b2afd481f7a113ef5604aa8b693564b5e744" integrity sha512-+1EE1nuuuwIt/N1KXRR2iWHU+OiIt7H28jJDyyI4tiUftId/DrXYEwoDa5+kH2pki1zxnA0r6HrUGHV5eLbF5Q==