Documentation Biome

website·Indexed 30 days ago

https://www.documentation-biome.xyz/

A comprehensive learning guide covering JavaScript fundamentals, Playwright automation, and CI/CD. Topics include JavaScript arrays and functions, Playwright Page Object Model (POM), API testing with JSON schema validation and snapshots, Git version control, and GitHub Actions workflow triggers and reusable workflows.

Tokens
22.4K
Snippets
133
Records
165
Agent score
51%

What's inside Documentation Biome

  1. Introduction to API Testing Fundamentals

    An Application Programming Interface (API) acts as an intermediary messenger that allows two applications to communicate by delivering requests to a supplier and returning the response. Testing APIs allows developers to quickly and efficiently verify that the system performs as expected when handling both expected and unexpected requests. While RESTful APIs are the most common, other types include SOAP and GraphQL.
  2. Implement a CharacterCreation class for a game

    Create a CharacterCreation class to manage game character attributes and behaviors. The class uses a constructor to initialize the character's name, class, and level. It includes a greeting() method for a formatted introduction and an attack() method that returns a specific action string based on the character's charClass (e.g., Wizard, Barbarian, Rogue, Ranger, Fighter).
    class CharacterCreation {
        constructor(name, charClass, level) {
            this.name = name;
            this.charClass = charClass;
            this.level = level;
        }
        greeting() {
            return `Hello my name is ${this.name} and im a level ${this.level} ${this.charClass}`
        }
        attack() {
            if (this.charClass === "Wizard") {
                return `${this.name} casts FIREBALL!`
            }
            else if (this.charClass === "Barbarian") {
                return `${this.name} swings an axe!`
            }
            else if (this.charClass === "Rogue") {
                return `${this.name} Attacks with a dagger`
            }
            else if (this.charClass === "Ranger") {
                return `${this.name} Fires an arrow`
            }
            else if (this.charClass === "Fighter") {
                return `${this.name} Swings a sword`
            } else {
                return `Hey, check for spelling on the ${this.charClass} charClass`
            }
        }
    }
    module.exports = { CharacterCreation }
  3. Understand Git forking

    Forking creates an exact replica of another user's repository under your own account. This allows you to experiment with changes, evaluate code, or propose updates to the original project via pull requests without affecting the main repository.
  4. Generate assertions using Playwright Codegen

    Starting with Playwright v1.40.0, the Codegen tool includes a horizontal bar at the top of the browser window that allows users to record assertions. This closes the loop on test creation by generating expect statements automatically based on UI interactions.
  5. Install Playwright using npm

    To install Playwright, you must have NodeJS installed on your machine. Start by creating a project folder, then run the initialization command. During the setup process, the following options are recommended for a standard installation:

    • Language: JavaScript
    • e2e test location: tests
    • GitHub Actions Workflow: true
    • Install Playwright Browsers: true
    # Verify NodeJS installation
    npm -v
    node -v
    
    # Initialize Playwright project
    npm init playwright@latest
  6. Control program flow using if, else if, and else statements

    JavaScript uses conditional statements to determine whether specific blocks of code should execute based on a boolean condition.

    • if statement: Executes the block of code if the specified condition is true.
    • else if statement: Provides a new condition to test if the preceding if or else if conditions were false.
    • else statement: Executes the block of code if all preceding conditions in the chain were false.

    Key behavior: Only the first truthy condition in a chain is executed. If multiple else if blocks are true, only the first one encountered will run. If no conditions are true and no else block is provided, the program simply continues to the next line of code after the conditional block.

    let conditionIsFalse = false;
    let conditionIsTrue = true;
    
    if (conditionIsFalse) {
        // This will not run
        console.log("This block of code runs");
    } else if (conditionIsTrue) {
        // This is the first truthy condition, so it runs
        console.log("This is the else if block");
    } else if (conditionIsTrue) {
        // This will NOT run even though it is true, because a previous block already executed
        console.log("This is the else if block 2");
    } else {
        // This runs only if all above are false
        console.log("This is the else block");
    }
  7. Return values from a JavaScript function

    Use the return statement to output a value from a function to the caller. When the return statement is reached, the function stops executing immediately.
    function addTwoNumbers(a, b) {
        return a + b;
    }
    
    const sum = addTwoNumbers(5, 5);
    console.log(sum); // 10
  8. Define and instantiate a JavaScript class

    JavaScript classes act as templates for creating objects. A class is defined using the class keyword followed by the class name and a block of code. To create an instance of a class, use the new keyword followed by the class constructor.

    Key constraints:

    • Class names must be unique within their scope; declaring two classes with the same name will result in a syntax error.
    • The constructor() method is a special method used to initialize object properties. It is executed automatically when a new object is created via new. If no constructor is explicitly defined, JavaScript provides an empty one by default.
    class Person {
        constructor(firstName, lastName) {
            this.firstName = firstName;
            this.lastName = lastName;
        }
        
        greeting() {
            return `Hello my name is ${this.firstName} ${this.lastName}`
        }
    }
    
    // Creating instances of the Person class
    let person1 = new Person("Frodo", "Baggins");
    console.log(person1.greeting()); // Output: Hello my name is Frodo Baggins
  9. Use const for immutable variable declarations

    The const keyword is used to declare variables that cannot be updated (reassigned) or redeclared. Attempting to change the value of a const variable or declare it again will result in an error.
    const firstName = "Steve";
    
    // Attempting to update will fail
    // firstName = "will"; 
    
    // Attempting to redeclare will fail
    // const firstName = "will"; 
  10. Externalize API test data using JSON files

    To improve maintainability and readability, move large request bodies into a separate JSON file. This allows you to reuse the data across multiple tests and dynamically reference fields (like IDs) for assertions instead of hard-coding them.
    // @ts-check
    const { test, expect } = require('@playwright/test');
    const petData = require('../data/pet.json');
    
    test('adding a pet', async ({ request }) => {
      const response = await request.put('pet', {
        data: petData 
      });
      expect(response.status()).toBe(200);
    });
    
    test('check that pet was added', async ({ request }) => {
      // Use the ID from the JSON file to avoid hard-coding
      const response = await request.get(`pet/${petData.id}`); 
      const json = await response.json(); 
      
      // Assert that the returned name matches the data file
      expect(json.name).toBe(petData.name);
    });