Description
Jonathan Druart
2022-11-08 08:13:15 UTC
Best approach imo would be to use set the syspref using before() instead of beforeEach() we're already using for cy.login. However, this implies the following: 1) Because before() runs previous to beforeEach() this means we would also have to move login to before() - previous to setting sys pref. 2) If we're doing 1) we also need to re-implement how login is being done, using cy.session, see https://www.cypress.io/blog/2021/08/04/authenticate-faster-in-tests-cy-session-command/ 3) That said, to use cy.session, we also need to put experimentalSessionAndOrigin: true in cypress.json since this is still an experimental thing added in Cypress 8.2, we're using cypress 9.5 last time I checked. Lastly, before() can save the original ERMModule sys pref value in some variable and we restore its' value using after(). I tried all this, and is half-working. It works as expected for the first test in a spec, but for some reason it's not authenticating for the second test in the spec. Will keep at it. Created attachment 143803 [details] [review] Bug 32131: Cypress tests are failing if ERMModule is off This patch solves this by enabling the system preference before each test, right after login. It also sets the system preference back to its original initial value after the tests finish running. To test: 1) Disable ERMModule system preference 2) Run cypess tests: yarn cypress open / yarn cypress run 3) Verify that tests run successfully (Optional): While tests are running, visit the system preferences panel and verify that the system preference is now "Enable". 4) Wait for the tests to finish and confirm that the system preference is set back to its original "Disable" value. Further analysis: login() doesn't work if called in before(), with or without cy.session, so it needs to remain in beforeEach() which means the setting of the ERM sys pref also needs to happen in beforeEach(), after logging in. Tried to shorten the tests suite runtime duration by preventing visiting sys pref panel in case we are trying to enable the already enabled sys pref. Did this using env vars but this could cause it to fail if tests are paused and redone, leading to the real value and env var value to differ, i.e. env var value persists through subsequent test runs (this happened while using cypress open). Finally, using cy.session for login works (and shortens tests suite duration slightly), but again, only if in beforeEach(), not in before(). I think this should also be implemented, but with its' own bug # and only if the use of experimentalSessionAndOrigin is considered reasonable by others. Pedro, thanks for your time on this. Yes, we need to use beforeEach, and that's not nice. But we can go with this solution for 22.11 and improve later. You should: 1. Build the patch on top of bug 32147 (that will certainly make the tests fail) 2. Set ERMProviders as well (some tests will fail if EBSCO is selected) (In reply to Jonathan Druart from comment #4) > You should: > 1. Build the patch on top of bug 32147 (that will certainly make the tests > fail) Tomas, are you going to push it into 22.11? (In reply to Jonathan Druart from comment #5) > (In reply to Jonathan Druart from comment #4) > > You should: > > 1. Build the patch on top of bug 32147 (that will certainly make the tests > > fail) > > Tomas, are you going to push it into 22.11? Yes, was waiting for it to be PQA. Created attachment 143938 [details] [review] Bug 32131: Cypress tests are failing if ERMModule is off This patch solves this by enabling the system preference before each test, right after login. It also sets the system preference back to its original initial value after the tests finish running. To test: 1) Disable ERMModule system preference 2) Run cypess tests: yarn cypress open / yarn cypress run 3) Verify that tests run successfully (Optional): While tests are running, visit the system preferences panel and verify that the system preference is now "Enable". 4) Wait for the tests to finish and confirm that the system preference is set back to its original "Disable" value. Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Created attachment 143939 [details] [review] Bug 32131: Move set_ERM_sys_pref_value to before We cannot (yet) move login to before, but we can set the pref before all the tests. We need to login in before anyway to retrieve the value of the pref. Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Created attachment 143940 [details] [review] Bug 32131: Make sure we login before we restore original pref's value Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Created attachment 143941 [details] [review] Bug 32131: (to-squash) Cypress tests are failing if ERMModule is off Please squash this with the first patch if 32147 is pushed before 32131. Created attachment 144006 [details] [review] Bug 32131: Cypress tests are failing if ERMModule is off This patch solves this by enabling the system preference before each test, right after login. It also sets the system preference back to its original initial value after the tests finish running. To test: 1) Disable ERMModule system preference 2) Run cypess tests: yarn cypress open / yarn cypress run 3) Verify that tests run successfully (Optional): While tests are running, visit the system preferences panel and verify that the system preference is now "Enable". 4) Wait for the tests to finish and confirm that the system preference is set back to its original "Disable" value. Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 144007 [details] [review] Bug 32131: Move set_ERM_sys_pref_value to before We cannot (yet) move login to before, but we can set the pref before all the tests. We need to login in before anyway to retrieve the value of the pref. Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 144008 [details] [review] Bug 32131: Make sure we login before we restore original pref's value Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Created attachment 144009 [details] [review] Bug 32131: (to-squash) Cypress tests are failing if ERMModule is off Please squash this with the first patch if 32147 is pushed before 32131. Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> All works as described and makes sense. Passing QA Pushed to master for 22.11. Nice work everyone, thanks! |