-1

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.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47

1 Answers1

0

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.

Alexey Popov
  • 1,033
  • 1
  • 4
  • 12
  • @Aleksey28, thanks for the comment. so basically the site has a single same url across all the screens. So the landing page begins with www.test.com. After providing some inputs and clikcing buttons, it moves to next page whose url is still the same and so on. So if I create a test to validate the the first page, testcafe will close the browser and thus to test page 2, I will again have to execute the test for page 1 in order to reach 2. I am not able to figure out what is the best way so that I do not have to write a single big test for all the pages. – Ansh Aggarwal May 30 '23 at 13:21
  • Also secondly, can there be a multiple page models which can be used in a single test? – Ansh Aggarwal May 30 '23 at 13:23
  • Page Model is not a strict instruction, it's a recommendation on how you can reuse selectors, action sequences, and so on. The only limitation is JavaScript. You can't keep states between tests, but you can create a [custom action](https://testcafe.io/documentation/404150/guides/advanced-guides/custom-test-actions) or just a simple function that you can call to execute all preparations before tests. If you need to run the same preparation for several tests, you can use [`beforeEach` hook](https://testcafe.io/documentation/402784/reference/test-api/fixture/beforeeach). – Alexey Popov Jun 01 '23 at 07:13