Home > database >  Error in fixture.before hook TypeError: t.maximizeWindow is not a function TestCafe
Error in fixture.before hook TypeError: t.maximizeWindow is not a function TestCafe

Time:03-03

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 error
Error in fixture.before hook TypeError: t.useRole is not a function

Can anyone help?

CodePudding user response:

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

CodePudding user response:

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.

  • Related