I'm writing a cypress test for a webpage that shows a list of posts with filters on the top.
But for the list of posts to be shown, some documents have to be present in the Database so that I can check that they are displayed as required.
How can I add some documents in the test file, for example, say in the beforeEach()
function?
This is the code of posts-summary-test.ts
file:
describe('posts summary page', () => {
beforeEach(() => {
cy.visit('/postssummary');
cy.wait(2000);
});
it('posts must be displayed in descending order of posted time',() => {
cy.findByLabelText(.......
......
......
......
)};
)};
In this file, where can I add few documents to test the webpage?
It sounds like you're looking for Cypress Fixtures.
It's a way, where you can define some static information to test against. So instead of fetching it all the way from the database, then you can load your content on your site and check that it matches the information in your fixtures.
Be careful not to make what you're testing 'too big of an arc', since that'll make it harder to know what broke and how to solve it.
If you really want to load the contents from your database, to test directly against that, then I would suggest making a script that generates the fixtures. But I wouldn't do that in Cypress.