Introduction
Testing the modern websites with dynamic content requires not just great tools but work with smart strategies. Automated scripts or manual testing are insufficient if your website has hundreds of news articles. This is where automated tests that are dependable, scalable, and repeatable are made possible by Cypress fixtures for large-scale testing.
In this blog, we’ll explore how Cypress fixtures and scripts can efficiently test over 1000+ news items—ensuring your content loads, filters, and displays as expected, without compromising performance.
Identifying the difficulty: Analyzing 1000+ of news items
Cypress automation is renowned for its powerful debugging capabilities, real-time execution, and simplicity of setup. However, there are difficulties in testing big datasets, such as 1000+ news articles:
How do you verify that all items load?
- How can you validate dynamic filters (by year, type, category)?
- How do you avoid timeouts or infinite scroll traps?
Cypress fixtures provide an efficient approach for large-scale testing by facilitating the external loading of test data and enhancing maintainability.
Why use Cypress fixtures for large-scale testing?
Fixtures in Cypress are the external static files like JSON, CSV and also containing test data. Instead of hardcoding expected values or generating them dynamically, and also we can use fixtures to preload test data for validation. This approach enhances not just data-driven testing, but also boosts execution speed and reusability. If you’re looking to improve performance testing even further, check out our detailed guide on optimizing performance testing in Cypress.
Benefits:
- Faster test execution
- Easier maintenance
- Reusable across multiple test cases
- Supports data-driven testing strategies
How to set up Cypress fixtures and Scripts for bulk testing
Step 1: Create a fixture file
In `/cypress/fixtures/newsItems.json`, save sample expected news data:
[
{
"title": "Company achieves record profits",
"year": "2024",
"type": "PRESS RELEASES",
"business": "Finance"
},
{
"title": "New product launch announced",
"year": "2024",
"type": "PRESS RELEASES",
"business": "Tech"
}
// ... add 1000+ items
]
Step 2: Write a custom Cypress command
// Adds a custom Cypress command called scrollToLastNews that accepts newsPom (the Page Object Model for the news page).
Cypress.Commands.add("scrollToLastNews", (newsPom) => {
// Records the starting time so we can calculate how long the scrolling takes.
const startTime = new Date().getTime();
// A flag to track whether we’ve reached the last news item.
let isAtBottom = false;
// Defines a function (with the same name) that will perform the scrolling.
function scrollToLastNews() {
// Accesses the browser’s window object.
cy.window().then((win) => {
// Scrolls the window down by 100 pixels each time.
win.scrollBy(0, 100);
// Selects the last news item element from the list on the page.
newsPom
.get_The_List_All_News()
.last()
.then(($el) => {
// Checks if the last news item is visible in the viewport.
if (Cypress.dom.isVisible($el)) {
// Logs a message in the Cypress test runner.
cy.log("Last news item is visible.");
isAtBottom = true;
}
});
// Gets the current time (to check timeout).
const currentTime = new Date().getTime();
// If we haven’t reached the bottom and timeout hasn’t been exceeded (500 seconds)...
if (!isAtBottom && currentTime - startTime < 500000) {
// Wait for 2 seconds before scrolling again.
cy.wait(2000);
// Recursively calls the function to scroll again.
scrollToLastNews();
// f we haven’t reached the bottom and we ran out of time...
} else if (!isAtBottom) {
// Log a failure message.
cy.log("Failed to reach the last news item within the time limit.");
throw new Error("Failed to reach the last news item within the time limit.");
// Throws an error to fail the test.
}
});
}
Calls the function immediately when the command is used.
scrollToLastNews();
});
Automating news filter selection and validation
it("TC005 ==> Verify that after selecting business, year option and press releases type then selected options should be visible in listing properly.", () => {
// Expected news type.
const actualNewsType = "PRESS RELEASES";
// Expected business and year (randomly picked existing ones).
const actualBusniessName = randomExistBusinessNews;
const actualYearText = randomExistYearNews;
cy.wait(2000)
// Click the news link in the header, forcing it if hidden.
headerPom.news_lnk().click({ force: true });
cy.wait(2000)
// Click the business filter dropdown.
newsPom.busniess_Dropdown().click({ force: true });
cy.wait(2000)
// Select a business option from dropdown and click it.
newsPom.select_Busniess_Option_From_Dropdown(randomExistBusinessNews).click({ force: true });
cy.wait(2000)
// Click the year filter dropdown.
newsPom.year_Dropdown().click({ force: true });
cy.wait(2000)
// Select a year option from dropdown and click it.
newsPom.select_Year_Option_From_Dropdown(randomExistYearNews).click({ force: true });
cy.wait(2000)
// Click the “Press Releases” button.
newsPom.press_Releases_btn().click({ force: true });
cy.wait(2000)
// Call the custom command to scroll to the last news item.
cy.scrollToLastNews(newsPom);
cy.wait(2000)
// Verify that all news type tags include the expected type.
cy.verifyTagsIncludeType(newsPom.get_newType_Tags_From_List, actualNewsType);
// Verify that all business tags match the expected business.
cy.verifyBusinessTags(newsPom.get_Business_Tags_From_List, actualBusniessName);
// Verify that all year tags match the expected year.
cy.verifyYearTags(newsPom.get_Year_Tags_From_List, actualYearText);
});
Real-world use case: News portal testing
A client managing a large news portal wanted to automate testing of filter functionality across 1000+ articles. Before Cypress, it took 4 manual testers 6 hours each per release. With the automation method using Cypress fixtures, it reduce manual testing effort by 90%, increases test coverage, and also reduced regression failures. Curious how automated testing like Cypress compares to manual QA? Explore our blog on cypress vs human tester for deeper insights.
Conclusion
It takes more than click-and-assert tests to test news portals and other dynamic, content-rich websites.You may use custom commands, scalable scripts, and repurposed data to fuel your automation suite with Cypress fixtures for comprehensive testing. You can maintain robust filter validations, efficiently handle more than a thousand news items, and future-proof your test automation using this approach.
August Infotech is a digital solutions provider, specializing in automation testing, web and software development, and scalable enterprise solutions. With expertise in Cypress, Selenium, and other modern test automation tools, we help businesses achieve faster time-to-market with high-quality digital products.