The goal of this tutorial is to familiarize you with the concepts of testing as part of a CI/CD (Continuous Integration/Continuous Deployment) pipeline. By the end of this tutorial, you will learn how to automate the process of validating your HTML code, checking for broken links, and testing your website in different browsers and screen sizes.
Automated testing is an essential part of CI/CD pipeline. It allows developers to validate their code changes quickly, ensuring that they didn't break anything with their latest changes.
HTML validation is a process that checks your HTML code against the formal syntax rules defined by the W3C standards. If your HTML code doesn’t follow these rules, the HTML validator will generate an error or a warning message.
Broken links are links that lead to web pages that have been deleted or moved. These can negatively impact your website’s SEO and provide a poor user experience.
Cross-browser testing is a process of checking compatibility of your website or web application in various web browsers. This is important because different browsers can render your website differently, leading to potential issues for some users.
There are many online tools available for HTML validation. Here we will use W3C Markup Validator. No code is required for this. Just paste your HTML code into the tool and it will provide any errors or warnings.
You can use below JavaScript code to check for broken links -
const brokenLinkChecker = require('broken-link-checker');
const http = require('http');
const url = 'http://your-website.com';
const server = http.createServer((req, res) => {
const htmlChecker = new brokenLinkChecker.HtmlUrlChecker({ excludeInternalLinks: true }, {
link: (result) => {
if (result.broken) {
console.log('Broken link: ', result.url.original);
}
}
});
htmlChecker.enqueue(url);
});
server.listen(8080);
This script will log all the broken links in your console.
There are many online tools available for cross-browser testing. Here we will use LambdaTest. No code is required for this. Just enter your website's URL and select the browsers and screen sizes you want to test.
In this tutorial, we covered the basics of testing in a CI/CD pipeline, including HTML validation, broken link checking, and cross-browser testing. Moving forward, you can learn more about advanced testing techniques and tools.