From accfbab4f67243d206703175d3b8b0ae81c8724b Mon Sep 17 00:00:00 2001 From: Alicia Zangger Date: Tue, 6 Oct 2020 16:50:20 +0200 Subject: [PATCH] cypress: create test for collections * Creates e2e tests for collections. * Replaces 'goToMenu' custom command in order not to go to the frontpage each time we navigate in the app. * Adds an empty template to re-use for test creation. * Renames 'templates' in 'examples' in order to avoid confusion with rero-ils template resource. * Adds cookies preservation to keep authentication information between tests. * Improves login and logout methods. * Allows language preservation in professional interface. * Closes #1220. Co-Authored-by: Alicia Zangger --- .../cypress/cypress/fixtures/collections.json | 44 +++++++++++ .../application/test-login-logout.spec.js | 43 ++++++++++ .../circulation/scenario-a.spec.js | 21 +++-- .../circulation/scenario-b.spec.js | 18 +++-- .../collections/test-collections.spec.js | 79 +++++++++++++++++++ .../document/create-simple-document.spec.js | 7 +- .../examples/empty-template.spec.js.disabled | 54 +++++++++++++ .../example-test-request.spec.js} | 18 ++--- .../e2e/cypress/cypress/support/collection.js | 77 ++++++++++++++++++ tests/e2e/cypress/cypress/support/index.js | 7 +- .../e2e/cypress/cypress/support/navigation.js | 22 +----- tests/e2e/cypress/cypress/support/record.js | 2 +- tests/e2e/cypress/cypress/support/user.js | 38 ++++----- 13 files changed, 354 insertions(+), 76 deletions(-) create mode 100644 tests/e2e/cypress/cypress/fixtures/collections.json create mode 100644 tests/e2e/cypress/cypress/integration/application/test-login-logout.spec.js create mode 100644 tests/e2e/cypress/cypress/integration/collections/test-collections.spec.js create mode 100644 tests/e2e/cypress/cypress/integration/examples/empty-template.spec.js.disabled rename tests/e2e/cypress/cypress/integration/{templates/template-test-request.spec.js => examples/example-test-request.spec.js} (91%) create mode 100644 tests/e2e/cypress/cypress/support/collection.js diff --git a/tests/e2e/cypress/cypress/fixtures/collections.json b/tests/e2e/cypress/cypress/fixtures/collections.json new file mode 100644 index 0000000000..f3d6c23ceb --- /dev/null +++ b/tests/e2e/cypress/cypress/fixtures/collections.json @@ -0,0 +1,44 @@ +{ + "course": { + "collection_id": "CRS 1", + "title": "Course number 1", + "collection_type": "course", + "teachers": [ + { + "name": "Pr. Smith, John" + } + ], + "libraries": [ + { + "$ref": "https://ils.rero.ch/api/libraries/22" + } + ], + "description": "List of items for course 1", + "subjects": [ + { + "name": "Anne Nonyme" + }, + { + "name": "geographic" + } + ], + "start_date": "2020-09-01", + "end_date": "2020-12-31", + "organisation": { + "$ref": "https://ils.rero.ch/api/organisations/4" + }, + "published": true + }, + "exhibition": { + "collection_id": "Expo 1", + "title": "Expo \u2013 The Number 1", + "collection_type": "exhibition", + "description": "List of items for the exhibition", + "start_date": "2020-10-01", + "end_date": "2021-06-30", + "organisation": { + "$ref": "https://ils.rero.ch/api/organisations/4" + }, + "published": true + } +} diff --git a/tests/e2e/cypress/cypress/integration/application/test-login-logout.spec.js b/tests/e2e/cypress/cypress/integration/application/test-login-logout.spec.js new file mode 100644 index 0000000000..ca0218d960 --- /dev/null +++ b/tests/e2e/cypress/cypress/integration/application/test-login-logout.spec.js @@ -0,0 +1,43 @@ +/// +/* + +RERO ILS +Copyright (C) 2020 RERO + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +*/ + +before(function () { + cy.fixture('users').then(function (userData) { + this.users = userData; + }); + cy.fixture('common').then(function (commonData) { + this.common = commonData; + }); +}); + +describe('Describe test suite here', function() { + afterEach('Add description if needed', function() { + cy.logout(); + }); + + it('Login as a librarian', function() { + cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); + + }); + + it('Login as a patron', function() { + cy.login(this.users.patrons.james.email, this.common.uniquePwd); + }); +}); diff --git a/tests/e2e/cypress/cypress/integration/circulation/scenario-a.spec.js b/tests/e2e/cypress/cypress/integration/circulation/scenario-a.spec.js index 697e7648c2..d2d9ee3326 100644 --- a/tests/e2e/cypress/cypress/integration/circulation/scenario-a.spec.js +++ b/tests/e2e/cypress/cypress/integration/circulation/scenario-a.spec.js @@ -46,15 +46,11 @@ describe('Circulation scenario A: standard loan', function() { before('Login as a professional and create a document and an item', function() { // Create server to watch api requests cy.server(); - // Open app on frontpage - cy.visit(''); - // Check language and force to english - cy.setLanguageToEnglish(); // Login as librarian (Leonard) cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); // Create a document // Go to document editor - cy.goToMenu('create-bibliographic-record-menu-frontpage'); + cy.visit('/professional/records/documents/new'); // Populate form with simple record cy.populateSimpleRecord(this.documents.book); //Save record @@ -69,7 +65,7 @@ describe('Circulation scenario A: standard loan', function() { }); after('Clean data: remove item and document', function() { - // TODO: find a way to preserve cookies (auth) and server after a test + cy.logout(); cy.server(); cy.route({method: 'DELETE', url: '/api/items/*'}).as('deleteItem'); cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); @@ -106,7 +102,8 @@ describe('Circulation scenario A: standard loan', function() { */ cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); // Go to requests list - cy.goToMenu('requests-menu-frontpage') + cy.get('#user-services-menu').click(); + cy.get('#requests-menu').click(); // Check that the document is present cy.get('table').should('contain', this.itemBarcode) // Enter the barcode and validate @@ -114,7 +111,8 @@ describe('Circulation scenario A: standard loan', function() { // The item should be marked as available in user profile view // Go to patrons list - cy.goToMenu('users-menu-frontpage') + cy.get('#user-services-menu').click(); + cy.get('#users-menu').click(); // Go to James patron profile cy.get('#' + this.users.patrons.james.barcode + '-loans').click() // Click on tab called "To pick up" @@ -129,7 +127,8 @@ describe('Circulation scenario A: standard loan', function() { */ cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); // Go to circulation search bar - cy.goToMenu('circulation-menu-frontpage'); + cy.get('#user-services-menu').click(); + cy.get('#circulation-menu').click(); // Checkout cy.scanPatronBarcodeThenItemBarcode(this.users.patrons.james, this.itemBarcode); // Item barcode should be present @@ -143,13 +142,13 @@ describe('Circulation scenario A: standard loan', function() { */ cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); // Go to circulation search bar - cy.goToMenu('circulation-menu-frontpage'); + cy.get('#user-services-menu').click(); + cy.get('#circulation-menu').click(); // Checkin cy.scanItemBarcode(this.itemBarcode); // CHeck that the item was checked in and that it is on shelf cy.get('#item-' + this.itemBarcode).should('contain', this.itemBarcode); cy.get('#item-' + this.itemBarcode).should('contain', 'on shelf'); cy.get('#item-' + this.itemBarcode).should('contain', 'checked in'); - cy.logout(); }); }); diff --git a/tests/e2e/cypress/cypress/integration/circulation/scenario-b.spec.js b/tests/e2e/cypress/cypress/integration/circulation/scenario-b.spec.js index 93e4374ae9..e6b0e381da 100644 --- a/tests/e2e/cypress/cypress/integration/circulation/scenario-b.spec.js +++ b/tests/e2e/cypress/cypress/integration/circulation/scenario-b.spec.js @@ -54,7 +54,8 @@ describe('Circulation scenario B: standard loan with transit', function() { cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); // Create a document // Go to document editor - cy.goToMenu('create-bibliographic-record-menu-frontpage'); + cy.get('#catalog-menu').click(); + cy.get('#create-bibliographic-record-menu').click(); // Populate form with simple record cy.populateSimpleRecord(this.documents.book); //Save record @@ -106,7 +107,8 @@ describe('Circulation scenario B: standard loan with transit', function() { // Login as librarian (Leonard) cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); // Go to requests list - cy.goToMenu('requests-menu-frontpage') + cy.get('#user-services-menu').click(); + cy.get('#requests-menu').click(); // Check that the document is present cy.get('table').should('contain', this.itemBarcode); // Enter the barcode and validate @@ -122,7 +124,8 @@ describe('Circulation scenario B: standard loan with transit', function() { // Login as librarian cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd); // Go to checkin view - cy.goToMenu('circulation-menu-frontpage'); + cy.get('#user-services-menu').click(); + cy.get('#circulation-menu').click(); // Enter item barcode for receive cy.get('#search').type(this.itemBarcode).type('{enter}'); // Check that the item has been received @@ -135,7 +138,8 @@ describe('Circulation scenario B: standard loan with transit', function() { // Login as librarian cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd); // Go to checkin view - cy.goToMenu('circulation-menu-frontpage'); + cy.get('#user-services-menu').click(); + cy.get('#circulation-menu').click(); // Checkout cy.scanPatronBarcodeThenItemBarcode(james, this.itemBarcode) // Check that the checkout has been done @@ -148,7 +152,8 @@ describe('Circulation scenario B: standard loan with transit', function() { // Login as librarian cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd); // Go to checkin view - cy.goToMenu('circulation-menu-frontpage'); + cy.get('#user-services-menu').click(); + cy.get('#circulation-menu').click(); // Checkin cy.scanItemBarcode(this.itemBarcode); // Check that the checkin has been done @@ -164,7 +169,8 @@ describe('Circulation scenario B: standard loan with transit', function() { // Login as librarian cy.adminLogin(this.users.librarians.leonard.email, this.common.uniquePwd); // Go to checkin view - cy.goToMenu('circulation-menu-frontpage'); + cy.get('#user-services-menu').click(); + cy.get('#circulation-menu').click(); // Receive cy.scanItemBarcode(this.itemBarcode); // Check that the item has been received diff --git a/tests/e2e/cypress/cypress/integration/collections/test-collections.spec.js b/tests/e2e/cypress/cypress/integration/collections/test-collections.spec.js new file mode 100644 index 0000000000..e5f1d1e50d --- /dev/null +++ b/tests/e2e/cypress/cypress/integration/collections/test-collections.spec.js @@ -0,0 +1,79 @@ +/// +/* + +RERO ILS +Copyright (C) 2020 RERO + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +*/ + +before(function () { + cy.fixture('users').then(function (userData) { + this.users = userData; + }); + cy.fixture('common').then(function (commonData) { + this.common = commonData; + }); + cy.fixture('collections').then(function (collections) { + this.collections = collections; + }); +}); + +describe('Collections', function() { + /** + * DESCRIPTION + * + */ + before('Login as a professional', function() { + Cypress.Cookies.debug(true); + this.spock = this.users.librarians.spock; + // Create server to watch api requests + cy.server(); + // Open app on frontpage + cy.visit(''); + // Check language and force to english + cy.setLanguageToEnglish(); + // Login as librarian + cy.adminLogin(this.spock.email, this.common.uniquePwd); + // Create a course + cy.createCollection(this.collections.course); + // Check the course + cy.checkCollection(this.collections.course); + }); + + beforeEach(() => { + Cypress.Cookies.preserveOnce('session'); + }); + + after('Clean data: remove collection', function() { + // Delete collection and confirm + cy.get('#detail-delete-button').click(); + cy.get('#modal-confirm-button').click(); + cy.logout(); + }); + + it('Create a collection', function() { + // Create a course + cy.createCollection(this.collections.course); + // Check the course + cy.checkCollection(this.collections.course); + }); + + it('Edit a collection', function() { + // Edit a collection to change it as an exhibition + cy.editCollection(this.collections.exhibition); + // Check the exhibition + cy.checkCollection(this.collections.exhibition); + }); +}); diff --git a/tests/e2e/cypress/cypress/integration/editor/document/create-simple-document.spec.js b/tests/e2e/cypress/cypress/integration/editor/document/create-simple-document.spec.js index c01be891a0..a041daf5c1 100644 --- a/tests/e2e/cypress/cypress/integration/editor/document/create-simple-document.spec.js +++ b/tests/e2e/cypress/cypress/integration/editor/document/create-simple-document.spec.js @@ -32,10 +32,6 @@ before(function () { describe('Document editor', function() { before('Login as a professional and create an item', function() { this.spock = this.users.librarians.spock; - //Open app on frontpage - cy.visit(''); - // Check language and force to english - cy.setLanguageToEnglish(); // Login as librarian cy.adminLogin(this.spock.email, this.common.uniquePwd); }); @@ -43,11 +39,12 @@ describe('Document editor', function() { after('Clean data: remove document', function() { // Delete record cy.deleteRecordFromDetailView(); + cy.logout(); }); it('Creates a document with only essential fields', function() { // Go to document editor - cy.goToMenu('create-bibliographic-record-menu-frontpage'); + cy.visit('/professional/records/documents/new'); // Populate form with simple record cy.populateSimpleRecord(this.documents.book); //Save record diff --git a/tests/e2e/cypress/cypress/integration/examples/empty-template.spec.js.disabled b/tests/e2e/cypress/cypress/integration/examples/empty-template.spec.js.disabled new file mode 100644 index 0000000000..2f6b27cd6b --- /dev/null +++ b/tests/e2e/cypress/cypress/integration/examples/empty-template.spec.js.disabled @@ -0,0 +1,54 @@ +/// +/* + +RERO ILS +Copyright (C) 2020 RERO + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +*/ + +before(function () { + // Run once before all + // Use to load fixtures and set variable needed in all tests +}); + +describe('Describe test suite here', function() { + // Run once before all tests in the block + // These steps are not part of the test, but need to be done in order to have + // the app in the right state to run the test + before('Login and prepare app for tests', function() { + // Create server to watch api requests (if needed) + cy.server(); + // Open app on frontpage + cy.visit(''); + // Check language and force to english + cy.setLanguageToEnglish(); + }); + + beforeEach('Add description if needed', function() { + // Preserve authentication information between the tests + Cypress.Cookies.preserveOnce('session'); + }); + + afterEach('Add description if needed', function() { + }); + + after('Clean data: ...', function() { + + }); + + it('Describe the test here', function() { + + }); +}); diff --git a/tests/e2e/cypress/cypress/integration/templates/template-test-request.spec.js b/tests/e2e/cypress/cypress/integration/examples/example-test-request.spec.js similarity index 91% rename from tests/e2e/cypress/cypress/integration/templates/template-test-request.spec.js rename to tests/e2e/cypress/cypress/integration/examples/example-test-request.spec.js index e8fb577921..f51cc59505 100644 --- a/tests/e2e/cypress/cypress/integration/templates/template-test-request.spec.js +++ b/tests/e2e/cypress/cypress/integration/examples/example-test-request.spec.js @@ -42,7 +42,6 @@ describe('Template: librarian request', function() { // the app in the right state to run the test before('Login as a professional and create an item', function() { console.log('before'); - Cypress.Cookies.debug(true); // Create server to watch api requests cy.server(); // Open app on frontpage @@ -53,7 +52,8 @@ describe('Template: librarian request', function() { cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd); // Create a document // Go to document editor - cy.goToMenu('create-bibliographic-record-menu-frontpage'); + cy.get('#catalog-menu').click(); + cy.get('#create-bibliographic-record-menu').click(); // Populate form with simple record cy.populateSimpleRecord(this.documents.book); //Save record @@ -64,7 +64,8 @@ describe('Template: librarian request', function() { // Runs before each test in the block beforeEach('Action to perform before each test', function() { - console.log('before each'); + // Preserve authentication information between the tests + Cypress.Cookies.preserveOnce('session'); }); // Runs after each test in the block @@ -80,7 +81,7 @@ describe('Template: librarian request', function() { // TODO: find a way to preserve cookies (auth) and server after a test cy.server(); cy.route({method: 'DELETE', url: '/api/items/*'}).as('deleteItem'); - cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd); + // cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd); // Go to item detail view cy.goToProfessionalDocumentDetailView(this.itemBarcode); cy.get('#item-' + this.itemBarcode + ' div a[name=barcode]').click(); @@ -93,8 +94,9 @@ describe('Template: librarian request', function() { cy.get('#modal-confirm-button').click(); cy.wait('@deleteItem'); // Remove document - cy.reload(); // Bug: need to reload the page to unable the remove button + cy.reload(); // Bug: need to reload the page to enable the remove button cy.deleteRecordFromDetailView(); + cy.logout(); }); // First test @@ -112,17 +114,15 @@ describe('Template: librarian request', function() { cy.get('#item-' + this.itemBarcode + ' div a[name=barcode]').click({force:true}); // Check that the request has been done cy.get('.card').should('contain', this.users.patrons.james.barcode); - cy.logout(); }); // Second test it('Second test: check the request in admin patron profile view', function() { console.log('second test'); - cy.adminLogin(this.users.librarians.spock.email, this.common.uniquePwd); - cy.goToMenu('users-menu-frontpage'); + cy.get('#user-services-menu').click(); + cy.get('#users-menu').click(); cy.get('#' + this.users.patrons.james.barcode + '-loans').click(); cy.get('#pending-tab').click(); cy.get('admin-main.ng-star-inserted > :nth-child(2)').should('contain', this.itemBarcode); - cy.logout(); }); }); diff --git a/tests/e2e/cypress/cypress/support/collection.js b/tests/e2e/cypress/cypress/support/collection.js new file mode 100644 index 0000000000..da811cdd16 --- /dev/null +++ b/tests/e2e/cypress/cypress/support/collection.js @@ -0,0 +1,77 @@ +/// +/* + +RERO ILS +Copyright (C) 2020 RERO + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +*/ + +/** + * Create collection + */ +Cypress.Commands.add("createCollection", (collection) => { + // Go to collection list + cy.get('#user-services-menu').click(); + cy.get('#collections-menu').click(); + // Click add button + cy.get('#search-add-button').click(); + // Fill in the form + cy.fillCollectionEditor(collection); +}); + +/** + * Edit collection from detailed view + */ +Cypress.Commands.add("editCollection", (collection) => { + // Go to editor + cy.get('#detail-edit-button').click(); + // Fill in the form + cy.fillCollectionEditor(collection); +}); + +/** + * Fill collection editor + */ +Cypress.Commands.add("fillCollectionEditor", (collection) => { + // Fill in the form + cy.get('#collection_type').select(collection.collection_type); + cy.get('#start_date').clear(); + cy.get('#start_date').type(collection.start_date); + cy.get('body').click(); // Leave datepicker + cy.get('#end_date').clear(); + cy.get('#end_date').type(collection.end_date); + cy.get('body').click(); // Leave datepicker + cy.get('#title').clear(); + cy.get('#title').type(collection.title); + cy.get('#collection_id').clear(); + cy.get('#collection_id').type(collection.collection_id); + if (collection.teachers) { + cy.get('#teachers-0-name').clear(); + cy.get('#teachers-0-name').type(collection.teachers[0].name); + } + cy.get('#editor-save-button').click(); +}); + +/** + * Check collection in detailed view + */ +Cypress.Commands.add("checkCollection", (collection) => { + cy.get('.d-inline').should('contain', collection.title); + cy.get('#collection-type').should('contain', collection.collection_type); + if (collection.teachers) { + cy.get('#collection #teacher').should('contain', collection.teachers[0].name); + } +}); + diff --git a/tests/e2e/cypress/cypress/support/index.js b/tests/e2e/cypress/cypress/support/index.js index c400914223..26ce06c814 100644 --- a/tests/e2e/cypress/cypress/support/index.js +++ b/tests/e2e/cypress/cypress/support/index.js @@ -14,12 +14,13 @@ // *********************************************************** // Import commands.js using ES2015 syntax: -import './commands' -import './utils' import './circulation' -import './user' +import './collection' +import './commands' import './navigation' import './record' +import './user' +import './utils' // Alternatively you can use CommonJS syntax: // require('./commands') diff --git a/tests/e2e/cypress/cypress/support/navigation.js b/tests/e2e/cypress/cypress/support/navigation.js index 562857c19c..e3c4d6a583 100644 --- a/tests/e2e/cypress/cypress/support/navigation.js +++ b/tests/e2e/cypress/cypress/support/navigation.js @@ -29,28 +29,10 @@ Cypress.Commands.add("userProfile", (tabId) => { } }) -// Go to a specific menu from professional homepage -// menuId: `id=` attribute content -Cypress.Commands.add("goToMenu", (menuId) => { - // Go to professional homepage - cy.get('#homepage-logo').click() - // if already on professional, do nothing - cy.url().then((url) => { - if (!url.includes('/professional/')) { - cy.get('#my-account-menu').click() - cy.get('#professional-interface-menu').click() - } - }) - - // Check we're on admin page - cy.url(1000).should('include', '/professional/') - // Click on 'menuTitle' from Catalog menu - cy.get('#' + menuId).click() -}) - Cypress.Commands.add("goToPublicDocumentDetailView", (itemBarcode) => { // Go to homepage - cy.get('#homepage-logo').click() + cy.visit(''); + cy.setLanguageToEnglish(); // on public context cy.get('.d-none > main-search-bar > .flex-grow-1 > .rero-ils-autocomplete > .form-control').clear() cy.get('.d-none > main-search-bar > .flex-grow-1 > .rero-ils-autocomplete > .form-control').type(itemBarcode).type('{enter}') diff --git a/tests/e2e/cypress/cypress/support/record.js b/tests/e2e/cypress/cypress/support/record.js index c1ded399c6..9d156a7a97 100644 --- a/tests/e2e/cypress/cypress/support/record.js +++ b/tests/e2e/cypress/cypress/support/record.js @@ -32,7 +32,7 @@ Cypress.Commands.add("createItemFromDocumentDetailView", (barcode, item) => { // Select location cy.get('select').eq(1).select(item.location) // Submit form - cy.get('.mt-4 > [type="submit"]').click() + cy.get('#editor-save-button').click() // Assert that the item has been created cy.get('.main-content').should('contain', barcode) }) diff --git a/tests/e2e/cypress/cypress/support/user.js b/tests/e2e/cypress/cypress/support/user.js index 1111c24f70..0645ed6e58 100644 --- a/tests/e2e/cypress/cypress/support/user.js +++ b/tests/e2e/cypress/cypress/support/user.js @@ -17,34 +17,30 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ -// Logout + Cypress.Commands.add("logout", () => { - // click on username - cy.get('#my-account-menu').click() - // Wait for the menu to open - // TODO: find a better way (same as setLanguageToEnglish command) - cy.wait(1000) - // then click on Logout link - cy.get('#logout-menu').click() + cy.visit('/signout'); + cy.get('#login-menu') }) Cypress.Commands.add("login", (email, password) => { - // click on "My account" - cy.get('#my-account-menu').click() - cy.wait(1000) - cy.get('#login-menu').click() - cy.get('#email').type(email) - cy.get('#password').type(password) - cy.get('form[name="login_user_form"]').submit() + cy.request({ + method: 'POST', + url: '/api/login', + followRedirect: false, + body: { + 'email': email, + 'password': password + } + }).then(response => { + cy.visit('/lang/en'); + cy.get('#logout-menu') // raise an error if not found + }); }) // Login to professional interface Cypress.Commands.add("adminLogin", (email, password) => { cy.login(email, password) - // set language to english BEFORE going to professional interface - cy.setLanguageToEnglish() - // go to professional interface - cy.get('#my-account-menu').click() - cy.get('#professional-interface-menu').click() - cy.url(60000).should('include', '/professional/') + cy.visit('/professional'); + cy.contains('RERO ILS administration'); })