Test Integration

Tutorial 4 of 4

Introduction

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.

Prerequisites

  • Basic knowledge of HTML, CSS, and JavaScript
  • Familiarity with Git and GitHub
  • Basic understanding of CI/CD concepts

Step-by-Step Guide

Automated Testing

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

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

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

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.

Code Examples

HTML Validation

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.

Broken Links

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.

Cross-Browser Testing

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.

Summary

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.

Practice Exercises

  1. Exercise 1: Validate your personal website's HTML code using the W3C Markup Validator.
  2. Exercise 2: Check for broken links in your website using the JavaScript code provided.
  3. Exercise 3: Perform a cross-browser test on your website using LambdaTest.

Solutions with Explanations

  1. Solution 1: Just paste your HTML code into the W3C Markup Validator and it will provide any errors or warnings.
  2. Solution 2: Replace the 'http://your-website.com' in the JavaScript code with your website's URL and run the script. It will log all the broken links in your console.
  3. Solution 3: Enter your website's URL in LambdaTest and select the browsers and screen sizes you want to test. It will show you how your website looks on different browsers and screen sizes.