vendredi 31 juillet 2020

TestCafe Studio: How do I import ES modules so I can use them in a TestCafe Script?

I want to use imported functions in TestCafe Scripts (which are basically copied into the test method). To me these scripts would be great to create reusable code snippets.

But I did not find a place where I could import a module which is then added to the import statements in the header of the test file.

An example:

I have a test-function I use for visual regression tests. It basically takes a screenshot of the page and compares it to a screenshot stored on disk. Since this also includes reading and writing files from/to disk using nodes fs API and calling packages like graphicsmagik, it quickly becomes a huge script. I might be able to copy it into a a TestCafe Script block, but it is not reusable and hardly scales.

Is there something I missed?

Of course I could create some command-line task that adds the import line to the top of all generated js files. But the test would only work after someone made them js files and ran my script. It would not be possible to run these tests directly from TestCafe Studio.

Aucun commentaire:

Enregistrer un commentaire