Test Automation Code Generator

Internship project at Brightest: A tool that extracts Page Object Models (POM) from GitHub repositories and generates test code.

Published on: 2025-05-28

Header image for Test Automation Code Generator

Overview

During my internship at Brightest, a company specializing in test automation, I developed a tool to simplify writing test scripts, particularly for employees with less technical background.

While existing frameworks like Playwright and Selenium offer code generation, this tool specifically focuses on extracting methods from Page Object Models (POM) stored in GitHub repositories and generating reusable code compatible with Brightest's internal test framework.

Approach

The project began with a research phase into existing solutions and the technical feasibility of extracting POM data from code files (JavaScript, TypeScript, C#). I collaborated with a fellow student (known from the Atlas Copco project).

After a successful proof-of-concept, we proceeded with developing a full-fledged Next.js web application with a MongoDB database for configurations and Microsoft Authentication Library (MSAL) for login via the Brightest environment.

PomExtractor.ts
// Example of our POM extraction logic
export class PomExtractor {
  // Extract methods from TypeScript/JavaScript files
  static extractMethodsFromTs(fileContent: string): PomMethod[] {
    const methods: PomMethod[] = [];
    
    // Regular expression to match class methods
    const methodRegex = /(?:async\s+)?(\w+)\s*\(([^)]*)\)\s*{/g;
    let match;
    
    while ((match = methodRegex.exec(fileContent)) !== null) {
      const methodName = match[1];
      const paramsString = match[2].trim();
      
      // Skip constructor and private methods
      if (methodName === 'constructor' || methodName.startsWith('_')) {
        continue;
      }
      
      // Parse parameters
      const params = paramsString ? 
        paramsString.split(',').map(param => {
          const [name, type] = param.trim().split(':').map(p => p.trim());
          return { name, type: type || 'any' };
        }) : [];
      
      methods.push({
        name: methodName,
        parameters: params,
        returnType: 'void' // Default, could be enhanced to detect return type
      });
    }
    
    return methods;
  }
}

Features

The "Test Automation Code Generator" offers the following end-to-end flow:

  1. Login: Users log in via their Microsoft account (MSAL)
  2. Repository Configuration: Users can enter a GitHub repository URL (account or specific repo) and a GitHub Access Token
  3. File Selection: The tool displays available repositories, and the user selects relevant code files from which POM methods should be extracted. A custom extractor parses JS, TS, and C# code
  4. Test Case Creation: On a separate tab, users can compose test cases by selecting extracted methods and adding parameters as needed
  5. Code Generation: The application generates the corresponding test code that can be directly copied and pasted into a test environment

Key technical aspects included using the React Context API for state management (single source of truth), setting up custom services, and writing clear backend API endpoints within Next.js.

Challenges

This project was my first experience in a professional development environment, which required adaptation to new workflows and expectations.

Specific challenges included:

  • Deeply understanding the Page Object Model concept itself
  • Effective communication with the project manager (PM) and the "client" (internal stakeholders at Brightest) to clarify requirements
  • Working with MSAL authentication within a corporate context
  • Designing a robust architecture for code extraction and generation

This internship project gave me valuable experience with modern web development in a professional context and improved my skills in designing complex system architectures.