Async Test import before Tests with cy.request #30982
Unanswered
deckdom
asked this question in
Questions and Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
we use Cypress for integration tests and need to perform our setup and cleanup for our service with via the REST API.
We have a dedicated rest-client, where we can change the underlying driver which executes the request.
On default we would use
fetch, but for cypress I made a custom one to usecy.request: Driver in questionSo far, so basic.
Since the setup often depend on correct order and on the responses, everything is done with Promises.
Using it with the
beforeandbeforeAllhooks causes some troubles however:Example Test:
Currently we use a chain of
cy.wrapandthento make everything execute, but this isn't reliable.Sometimes cypress is happy to execute these setups, sometimes it refuses with the following error:
This error sometimes occurs, but usually works when being run in development/head-mode with the cypress app.
Running the tests via the CLI and headless however, consistently breaks on the same tests.
Other tests with the same approach execute fine however.
Therefore quite troublesome and hard to debug.
Of course I tried to use different approaches, but they all had different issues:
Using only a single
wrapCauses the same error as above, so no difference
Using
thencorrectly without additionalwrapThis will lock up the first
cy.requestcall - It'll never complete.It seems to me it is scheduled, but never executed, so the handling of the response can't be handled.
Within the
cypress-driver, we execute the request in a promise:I added a breakpoint to the first line within the
then, but it never stopped there.Adding a
catchor any other standard error handling yielded absolutely nothing, and the initialthenfrom thebeforehook will timeout.Not using
wraporthenat allCan't be used very much, as for certain setups we have to load fixtures (binaries like test images and files) for upload,
therefore we have to mix these sometimes.
I'd greatly appreciate help with this, since I couldn't find anything relating to similar issues or projects which have a setup as complex as we have.
If you want to run the tests in question, then you are of course free to do so from our OSS repository.
In case any questions arise/more input is needed, please let me know.
Beta Was this translation helpful? Give feedback.
All reactions