Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

Test your website on
3000+ browsers

Get 100 minutes of automation
test minutes FREE!!

Test NowArrowArrow

KaneAI - GenAI Native
Testing Agent

Plan, author and evolve end to
end tests using natural language

Test NowArrowArrow
  • Home
  • /
  • Blog
  • /
  • How To Find Broken Links Using Cypress [With Examples]
JavaScriptCypress TestingTutorial

How To Find Broken Links Using Cypress [With Examples]

Want to find broken links on your website? Here's how you can do broken link testing on your website using Cypress.

Author

Enrique

January 30, 2026

Have you ever encountered a 404 error? From an end user’s perspective, a broken link can be a major turn-off. Beyond frustrating users, dead links can negatively impact your website’s SEO, increase bounce rates, and reduce site credibility. Regularly detecting and fixing broken links is crucial for maintaining a professional, reliable site. Cypress simplifies this process with its cy.request() function, allowing you to check the status of each link and quickly identify any that aren’t working.

Overview

Why Find Broken Links On A Website?

Broken links can frustrate users and reduce engagement, while also impacting how search engines view your site. Regularly checking links ensures smooth navigation and maintains website credibility.

  • User Retention: Users encountering broken links are more likely to leave your site immediately.
  • Bounce Rate: High bounce rates from dead links can indirectly affect search engine rankings.
  • Trust & Credibility: Broken links reduce trust and professionalism, affecting your brand reputation.
  • Content Accessibility: Preventing 404 errors ensures all content is accessible and functional.
  • Navigation Experience: Helps maintain a seamless navigation experience across all pages.

How To Find Broken Links Using Cypress?

Cypress allows you to automate link verification across your website, helping you quickly identify pages that don’t load correctly or return errors. By leveraging its modern testing capabilities, you can streamline checks and reduce manual effort.

  • Collect Links: Gather all anchor elements (<a> tags) on the page and extract their URLs.
  • Check Response: Loop through each URL and send a request to check the HTTP response code.
  • Flag Errors: Identify links that return error codes (like 404 or 500) to flag broken pages.
  • Use Configs: Utilize configuration files to manage multiple URLs and scale tests across different site sections.
  • Log Results: Record results for easy debugging and track which links need updates.
  • Handle Exceptions: Integrate exception handling to avoid test failures from non-critical errors.

How Can Error Handling Prevent Cypress Tests From Failing Due to Minor Issues?

Error handling in Cypress, such as ignoring uncaught exceptions, ensures that non-critical errors like temporary link failures do not stop the entire test. This makes the testing process more robust and allows teams to focus on actionable failures rather than being blocked by minor issues.

How To Find Broken Links Using Cypress

Till now, you would have understood the importance of checking broken links on your website? So, with the platform all set, let’s look at how to find broken links using Cypress. For starters, Cypress is a next-generation front-end testing tool built for the modern web; Cypress testing enables you to write faster, easier, and more reliable tests.

In case you are coming from a Selenium automation background, make sure to check out the differences between Selenium and Cypress from our blog that covers Cypress vs Selenium comparison. Saying that, let’s focus on our problem about broken links and how to build some tests to validate that using Cypress test automation.

Let’s take a sample HTML page that contains four relative hyperlinks:

<a href="/at-home-coronavirus-testing">Testing</a>
    <a href="/paying-for-covid-19-testing/">Paying for covid Testing</a>
    <a href="/covid-19-antibody-testing">Covid19 antibody Testing</a>
    <a href="/covid-19-testing-statistics">Testing Statistics</a>

As you can see, we have four links, and we need to click on each link, check the redirect URL, and then go back to our main page. So, how do you find broken links using Cypress considering the above HTML page.

What if we come up with an implementation that is limited to finding which out of the four are broken in nature. If the implementation is hardcoded for four links, it will lead to scalability issues, especially if the checker is used on a different web page.

Here is the sample code that uses the Cypress framework to find broken links on the website. As mentioned earlier, this is not a scalable approach and should be avoided when finding broken links on large-scale websites.

describe('Test Navigation', () => {
  it('can navigate and test the pages', () => {
    cy.visit('https://www.testing.com/at-home-coronavirus-testing/');
 
    cy.get('main:contains("Testing")');
    cy.go('back');
 
   cy.visit('https://www.testing.com/paying-for-covid-19-testing/');
   cy.get('main:contains("Test")');
   cy.go('back');
 
   cy.visit('https://www.testing.com/covid-19-antibody-testing/');
   cy.get('main:contains("Testing")');
   cy.go('back');
 
 
   cy.visit('https://www.testing.com/covid-19-testing-statistics/');
   cy.get('main:contains("Testing")');
   cy.go('back');
  
  });
});

In our example below, we are clicking on every page and checking the specific assertion, it does not follow the design patterns, and we can improve the way we get the links on our website.

Let’s take a look at the following example.

it('Navigate through the links using loops', () => {
 
  const pages = ['Testing Covid', 'Paying for Covid19 Test', 'Test Antibody Covid19', 'Testing Statistics']
 
  cy.visit('/')
 
  pages.forEach(page => {
 
    cy.contains(page).click()
    cy.location('pathname').should('eq', `/${page}`)
    cy.go('back')
 
  })
 
})

As you can deduce from the code above, we are looping against the specific pages and validating the page information. We created a ‘forEach’ loop that will iterate through the array where the entire procedure is repeated. Particularly useful if, for any reason, our navigation bar changes items. We’ll add an item to the array, and our test works.

Comma

Navigating to subdomains works fine, but Cypress will throw an error if you visit two different superdomains. Thus, you can see different superdomains in other tests but not in the same test.

Instead of opening every link on the test website, we can simply check links with the href attribute and check their HTTP status code. If the return code is 404, it means that that particular link is a broken (or dead) link.

Austin Siewert

Austin Siewert

CEO, Vercel

Discovered @TestMu AI yesterday. Best browser testing tool I've found for my use case. Great pricing model for the limited testing I do 👏

2M+ Devs and QAs rely on TestMu AI

Deliver immersive digital experiences with Next-Generation Mobile Apps and Cross Browser Testing Cloud

How to find broken links using Cypress on Cloud Grid

Cypress testing on cloud grid like TestMu AI helps in running tests on a wide range of browser and OS combinations. Parallel execution helps in accelerated test execution as well as achieving optimal browser coverage.

Cypress on TestMu AI helps you run Cypress tests at scale. You can check out our earlier blog that deep dives into the essentials on how to perform Cypress testing at scale with TestMu AI.

To get started, you have to install TestMu AI Cypress CLI on your machine. Trigger the following command to install the same:

npm install -g lambdatest-cypress-cli

After installation is completed, setup the configuration using the below command:

lambdatest-cypress init

Once the command is completed, lambdatest-config.json is created in the project folder. Next, enter the TestMu AI credentials from the TestMu AI profile section.

"lambdatest_auth": {
      "username": "<Your LambdaTest username>",
      "access_key": "<Your LambdaTest access key>"

Here is how you can configure the required browser & OS combinations in lambdatest-config.json:

"browsers": [
      {
         "browser": "Chrome",
         "platform": "Windows 10",
         "versions": [
            "latest-2"
         ]
      },
      {
         "browser": "Firefox",
         "platform": "Windows 10",
         "versions": [
            "latest"
         ]
      },
      {
         "browser": "MicrosoftEdge",
         "platform": "Windows 10",
         "versions": [
            "latest"
         ]
      }
   ],

run_settings section in the JSON file contains the desired Cypress test suite capabilities, including Cypress_version, build_name, visual feedback settings, number of parallel sessions, etc.

"run_settings": {
      "Cypress_config_file": "Cypress.json",
      "build_name": "build-broken-links",
      "parallels": 1,
      "specs": "./Cypress/integration/e2e_tests/*.spec.js",
      "ignore_files": "",
      "feature_file_suppport": false
   },

Tunnel_settings in the JSON file lets you connect your local system with TestMu AI servers via an SSH-based integration tunnel. Once this tunnel is established, you can test your locally hosted pages on all the browsers currently supported by Cypress on TestMu AI.

"tunnel_settings": {
    "tunnel": false,
    "tunnelName": null
}

Now that the setup is ready, it’s time to run the tests by triggering the following command:

lambdatest-cypress run

Shown below is the test execution status from the Automation Dashboard:

automation dashboard

After the test execution, click on the test name to view the automation logs for debugging the respective test.

automation log

You can view the live video feed, screenshots for each test run, view console logs, terminal logs, and do much more using Cypress on TestMu AI.

One crucial aspect of running the tests using TestMu AI and Cypress is parallel testing. This can be achieved using two methods. The first option is passing the parallelization level from the command line:

lambdatest-cypress run --parallels 5

The other option is to set the parallelization level using the parallels key in lambdatest-config.json.

{
  "run_settings": {
    ...
    "parallels": 5,
    ...
  }
}

Here is the execution snapshot, which indicates the progress of test execution:

automation test execution

Here’s quick video if you have doubts regarding how to handle iframes in Cypress.

To summarize, the major benefit of Cypress testing on the cloud is achieving optimal test coverage without making modifications to the core logic of the test code.

It’s A Wrap

It’s inevitable 404 errors will appear on your site. Broken links can also impact the rankings on search engines; make sure you proactively monitor the links of your website. Finding broken links on your website or an HTTP 404 is as vital as posting unique and high-quality content.

pasted image 0 (2)

Source

Check your 404s as a part of continuous testing, and you can include Cypress tests as part of your testing tools. Putting time aside to update your website and perform technical testing will help you stay ahead of the competition.

We know that we must enable, nurture, and foster an ecosystem that includes high-quality success. Every line of test code is an investment in our codebase. Tests will be able to run and work independently always. Lastly, in this Cypress tutorial, we saw how TestMu AI and Cypress integration ensure seamless user experience across different browsers on 40+ browser versions simultaneously.

Happy Bug Hunting with Cypress!!

Author

Enrique DeCoss, Senior Quality Assurance Manager at FICO is an industry leader in quality strategy with 16+ of experience implementing automation tools. Enrique has a strong background in Testing Tools, API testing strategies, performance testing, Linux OS and testing techniques. Enrique loves to share his in-depth knowledge in competencies including, Selenium, JavaScript, Python, ML testing tools, cloud computing, agile methodologies, and people Management.

Frequently asked questions

Did you find this page helpful?

More Related Hubs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests