At hackfest it was discussed that it would be useful to be able to use the perl TestBuilder module in Cypress along with the new Cypress mysql. This bug is for a proof of concept to discuss
Created attachment 164899 [details] [review] Bug 36607: Add cypress commands to build and delete objects This patch is a proof of concept for using test builder in cypress. The commands take in a Koha class and any data values and pass these to a perl script to run test builder To delete values we can either pass values to identify the data to delete or simply tell the command how many rows to delete from the end of the table
Created attachment 164900 [details] [review] Bug 36607: [DO NOT PUSH] Test for the commands cypress run --spec t/cypress/integration/DataTest_spec.ts
Created attachment 164901 [details] [review] Bug 36607: Add cypress commands to build and delete objects This patch is a proof of concept for using test builder in cypress. The commands take in a Koha class and any data values and pass these to a perl script to run test builder To delete values we can either pass values to identify the data to delete or simply tell the command how many rows to delete from the end of the table
Created attachment 164902 [details] [review] Bug 36607: [DO NOT PUSH] Test for the commands cypress run --spec t/cypress/integration/DataTest_spec.ts
The patch above allows us to use an object builder directly in the test - the alternative would be to just write a perl data generation script and call that directly at the start and end of each test to generate/tidy up data. Ideally the command could also return the newly created value but that is a future step as we can retrieve it with cypress mysql for now Let me know any concerns/feedback
(In reply to Matt Blenkinsop from comment #5) > The patch above allows us to use an object builder directly in the test - > the alternative would be to just write a perl data generation script and > call that directly at the start and end of each test to generate/tidy up > data. > > Ideally the command could also return the newly created value but that is a > future step as we can retrieve it with cypress mysql for now > > Let me know any concerns/feedback We need to cleanup behind us. So for instance if you create a patron you need to remove it AND what has been auto-generated: library + patron's category. So yes, we should retrieve the id of the resource we have created. The "delete the last X entries" approach is not robust enough IMO. See t/db_dependent/selenium/regressions.t: push @cleanup, $patron, $patron->category, $patron->library;
Created attachment 166180 [details] [review] added teardown
hi, I think Jonathan is right, ideally tests should be idempotent ie you have to clean up after testing. I added a "teardown" option in both t/cypress/support/e2e.js t/cypress/support/cypress_builder.pl additionally I think there was an error in t/lib/TestBuilder.pm because it used hashes and not objects when trying to delete objects to run yarn cypress run --config video=false,screenshotOnRunFailure=false --spec t/cypress/integration/DataTestSetupTeardown_spec.ts which creates a patron and then removes exactly this patron + the library/branch created implicitly. If this approach seems worthwhile it needs fleshing out for each object. the point of this approach is that you may not simply create an object randomly but you have to use a identifier, in the case of a patron the cardnumber. with this identifier you "keep state" during the test and in the end you issue a teardown command which not only deletes the explictly created object, but also all dependent object.
Created attachment 166237 [details] [review] Bug 36607: [discuss] setup and teardown patron please checkout/push to https://github.com/HKS3/koha-devel/tree/bug-36607 Current status: In Discussion