Extend TestController / TestControllerPromise

492 views Asked by At

I am writing my E2E tests with test cafe. The code I am testing is a library that is loaded into other websites and first needs to initialize itself. So every one of my tests starts with the same code:

t.switchToIframe(iframeSelector)
 .expect(loginSelectorSpinner).exists).ok({timeout: 3000}) // wait for login start
 .expect(loginSelectorSpinner).exists).notOk({timeout: 5000}) // wait for login finish

I would like to move this into helper methods that I can chain like the built-in methods.
So my code would look like this:

t.waitForLoginFinish()
 .except(whatever)...

How can I achieve this?

1

There are 1 answers

0
Alexander Moskovkin On BEST ANSWER

TestCafe doesn't provide API for that for now. Here is a feature suggestion in the TestCafe Github repository: Provide an ability to add custom actions to the test controller. You can vote for it by adding your +1 reaction.