What type of hook should be used if previous tests need to be executed before subsequent tests in testcafe?

50 Views Asked by At

The web application I am using has a static url which remains same for all the pages/modules inside it. Since testcafe closes the browser after each test execution, I have included all the selectors, fixtures and tests in a single big test which is not efficient.

My test is like this:

  1. Selector declaration
  2. Fixture 3.Test 3.1 *Steps to test Homepage 3.2 *Steps to test Page 2 3.3 *Steps to test page 3 and so on..

Now to execute the logic for third screen, either i need to have the browser remain opened from second screen logic or execute the logic for first, second screen etc as the url is same across the screens.

I want to move the selectors to a Page-model file and divide the logic for each screen into their own fixture/tests. But I am not sure how to do that from the options mentioned above?

Thanks.

1

There are 1 best solutions below

3
On

I'm not sure that I understand your final goal. Do you want to keep the state of the site between tests? It's impossible as in our experience all tests should be executed separately.

If you just want to place Selectors in the Page model and reuse them, you are free to do this - there are no limitations.