'Error in fixture.before hook TypeError: t.maximizeWindow is not a function TestCafe
I want to do some tests on a website which the tasks come after login. So I created a role for login and call it in beforeEach method. When running tests, the login function happens before every test. But I didn't want to happen that and then I moved the role and maximize window function into the before method. Now it gives an error
Error in fixture.before hook TypeError: t.maximizeWindow is not a function
Even if I removed the maximizeWindow function and then run, it shows errorError in fixture.before hook TypeError: t.useRole is not a function
Can anyone help?
Solution 1:[1]
You cannot use t.maximizeWindow and other t methods inside the before fixture. The before and after fixture hooks run before or after the content of the fixture. They cannot access the browser.
Please take a look at the https://testcafe.io/documentation/403435/guides/advanced-guides/hooks#fixture-hooks article for more details
Solution 2:[2]
If you do not wish to use roles for every test in fixture you can simply add the t.useRole method inside the test body without any hooks.
Please also note that when you are using the Roles mechanism in the beforeEach hook, the login process runs only for the first time. For the remaining tests you will be automatically logged in.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alex Kamaev |
| Solution 2 | Alexey Filin |
