Test Development Guide

Comprehensive guide for developing automated tests using the mAi™ Framework

This guide covers best practices and patterns for developing automated tests using the framework, including JUnit 5 ? annotations, Page Object Model ? implementation, custom assertions, HTTP security assessment, network diagnostics, and mAi Advisor™ integration.

Test Structure

Basic Test Class Structure

Every test suite follows a consistent structure with JUnit 5 lifecycle hooks:

package testsuites;

import org.junit.jupiter.api.*;
import framework.junit.*;
import framework.driver.FW_Browser;
import pageobjects.*;
import static framework.junit.FW_CustomAssertJU.*;

public class TS_Example_JUnit {
    
    WebDriver driver;
    PO_Login loginPage;
    
    @BeforeAll
    public static void setupTestSuite() {
        String className = new Object() {}.getClass()
            .getEnclosingClass().getSimpleName();
        FW_TestSuiteFormatter.beforeAll(className);
        FW_ConfigMgr.getInstance();
    }
    
    @BeforeEach
    public void setupTestCase(TestInfo testInfo) {
        FW_TestSuiteFormatter.beforeEach(testInfo);
        driver = FW_Browser.createWebDriver();
        loginPage = new PO_Login(driver);
    }
    
    @Test
    @DisplayName("Test: Valid login credentials")
    public void testValidLogin() {
        autoPass("Navigate to login page", 
            loginPage.navigateTo());
        autoPass("Enter valid credentials", 
            loginPage.login("user", "pass"));
        autoPass("Verify successful login", 
            loginPage.verifyLoginSuccess());
    }
    
    @AfterEach
    public void tearDownEach(TestInfo testInfo) {
        FW_TestSuiteFormatter.afterEach(testInfo);
        FW_Browser.disposeWebDriver(driver);
    }
    
    @AfterAll
    public static void tearDownTestSuite() {
        String className = new Object() {}.getClass()
            .getEnclosingClass().getSimpleName();
        FW_TestSuiteFormatter.afterAll(className);
    }
}

Naming Conventions

ElementPatternExample
Test ClassTS_<Feature>_JUnitTS_Authentication_JUnit
Test Methodtest<Action><Context>testValidLogin
Display Name@DisplayName("...")Clear, business-readable description

JUnit 5 Annotations

AnnotationPurposeUsage
@TestMarks a test methodEvery test case
@DisplayNameHuman-readable test nameDescribe test purpose
@OrderTest execution orderControl test sequence
@DisabledSkip test executionTemporarily disable tests
@ParameterizedTestData-driven testsMultiple test data sets
@TagTest categorizationGroup related tests

Custom Assertions

The framework provides enhanced assertions with automatic screenshots:

// Basic assertions with screenshots
autoPass("Step description");  // Pass with screenshot
autoFail("Error description");  // Fail with screenshot
autoWarn("Warning message");    // Warning with screenshot

// Assertions with validation
autoPassValidation("Verify element present", element.isDisplayed());

// Performance assertions
autoPassWithDuration("Page load", startTime, endTime);

// Network assertions
autoPassNetwork("Check connectivity", networkDetails);
💡 Tip

All auto* assertions automatically capture screenshots and log step details to the data collector for reporting.

Page Object Model

The Page Object Model encapsulates page elements and interactions:

Creating Page Objects

package pageobjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import framework.automation.FW_Page;

public class PO_Login extends FW_Page {
    
    // Locators
    private static final String LO_TXT_USERNAME = "//input[@id='user-name']";
    private static final String LO_TXT_PASSWORD = "//input[@id='password']";
    private static final String LO_BUT_LOGIN = "//input[@id='login-button']";
    
    // Constructor
    public PO_Login(WebDriver driver) {
        super(driver);
    }
    
    // Page methods
    public Object enterUsername(String username) {
        String result = enterLocatorText(LO_TXT_USERNAME, username, 
            FW_ConfigMgr.getDefaultTimeout());
        return FW_TestStepUtils.createTestStep(result, Thread.currentThread());
    }
    
    public Object clickLogin() {
        String result = clickLocator(LO_BUT_LOGIN, FW_ConfigMgr.getDefaultTimeout());
        return FW_TestStepUtils.createTestStep(result, Thread.currentThread());
    }
}

HTTP Security Assessment Testing

The framework includes comprehensive HTTP security assessment ? capabilities to audit web application security headers, SSL/TLS configuration, and protocol compliance.

HTTP Assessment Test Suite

package testsuites;

import org.junit.jupiter.api.*;
import framework.audits.FW_AuditManager;
import framework.formatter.FW_TestSuiteFormatter;
import framework.utilities.FW_ConfigMgr;
import static framework.junit.FW_CustomAssertJU.*;

public class TS_HttpAssessment_JUnit {
    
    @BeforeAll
    public static void setupTestSuite() {
        String className = new Object() {}.getClass()
            .getEnclosingClass().getSimpleName();
        FW_TestSuiteFormatter.beforeAll(className);
        FW_ConfigMgr.getInstance();
    }
    
    @Test
    @DisplayName("Test: HTTP Security Headers Audit")
    @Tag("security")
    public void testHttpSecurityHeaders() {
        String targetUrl = FW_ConfigMgr.getDefaultURL();
        
        autoPass("Initialize FW_AuditManager");
        FW_AuditManager auditManager = new FW_AuditManager();
        
        autoPass("Perform HTTP security audit on: " + targetUrl);
        auditManager.performHttpAudit(targetUrl);
        
        autoPass("HTTP audit complete - review reports in target/http-reports/");
    }
    
    @Test
    @DisplayName("Test: SSL/TLS Configuration Audit")
    @Tag("security")
    public void testSslConfiguration() {
        String targetUrl = FW_ConfigMgr.getDefaultURL();
        FW_AuditManager auditManager = new FW_AuditManager();
        
        autoPass("Audit SSL/TLS configuration for: " + targetUrl);
        auditManager.performSslAudit(targetUrl);
        
        autoPass("SSL audit complete with certificate validation");
    }
    
    @AfterAll
    public static void tearDownTestSuite() {
        String className = new Object() {}.getClass()
            .getEnclosingClass().getSimpleName();
        FW_TestSuiteFormatter.afterAll(className);
    }
}

HTTP Audit Configuration

Configure HTTP audit settings in testConfig.properties:

# HTTP Audit Configuration
http.audit.enabled=true
http.audit.timeout=30000
http.audit.followRedirects=true
http.audit.reportDirectory=target/http-reports

# Security Headers to Check
http.audit.headers=X-Frame-Options,X-Content-Type-Options,Strict-Transport-Security,Content-Security-Policy

Understanding HTTP Audit Reports

HTTP audit reports are generated in target/http-reports/ with:

For complete HTTP assessment documentation, see HTTP Assessment Documentation.

Network Diagnostics Testing

The framework includes network diagnostic capabilities for testing connectivity, performance, and routing.

Network Diagnostics Test Suite

package testsuites;

import org.junit.jupiter.api.*;
import framework.audits.*;
import framework.formatter.FW_TestSuiteFormatter;
import framework.utilities.FW_ConfigMgr;
import static framework.junit.FW_CustomAssertJU.*;

public class TS_Network_JUnit {
    
    @BeforeAll
    public static void setupTestSuite() {
        String className = new Object() {}.getClass()
            .getEnclosingClass().getSimpleName();
        FW_TestSuiteFormatter.beforeAll(className);
        FW_ConfigMgr.getInstance();
    }
    
    @Test
    @DisplayName("Test: Ping Network Connectivity")
    @Tag("network")
    public void testPing() {
        String targetHost = FW_ConfigMgr.getDefaultURL()
            .replace("https://", "").replace("http://", "");
        
        autoPass("Initialize ping audit");
        FW_Audit_Ping pingAudit = new FW_Audit_Ping();
        
        autoPass("Execute ping to: " + targetHost);
        pingAudit.auditPing(targetHost);
        
        autoPass("Ping audit complete - connectivity verified");
    }
    
    @Test
    @DisplayName("Test: Traceroute Network Path")
    @Tag("network")
    public void testTraceroute() {
        String targetHost = "www.google.com";
        
        autoPass("Initialize traceroute audit");
        FW_Audit_Traceroute tracerouteAudit = new FW_Audit_Traceroute();
        
        autoPass("Execute traceroute to: " + targetHost);
        tracerouteAudit.auditTraceroute(targetHost);
        
        autoPass("Traceroute complete - network path mapped");
    }
    
    @Test
    @DisplayName("Test: Network Speed Test")
    @Tag("network")
    @Tag("performance")
    public void testSpeedTest() {
        autoPass("Initialize speed test audit");
        FW_Audit_SpeedTest speedTestAudit = new FW_Audit_SpeedTest();
        
        autoPass("Execute network speed test");
        speedTestAudit.performSpeedTest();
        
        autoPass("Speed test complete - bandwidth measured");
    }
    
    @AfterAll
    public static void tearDownTestSuite() {
        String className = new Object() {}.getClass()
            .getEnclosingClass().getSimpleName();
        FW_TestSuiteFormatter.afterAll(className);
    }
}

Network Test Configuration

Configure network diagnostic settings in testConfig.properties:

# Network Diagnostics Configuration
network.audit.enabled=true
network.ping.count=4
network.ping.timeout=5000
network.traceroute.maxHops=30
network.speedtest.enabled=true
network.speedtest.duration=10000

Network Test Patterns

For complete network diagnostics documentation, see Network Diagnostics Guide.

Using mAi Advisor™ Recommendations

mAi Advisor™ provides intelligent, context-aware recommendations for test failures and audit findings using a multi-tier, multi-audience model.

mAi Advisor™ Architecture

TierPurposeAudience
UnderstandingWhat the finding means, why it matters, business impactAll audiences
ActionStep-by-step remediation, code examples, configurationImplementers only

Six Audience Types

AudienceFocus
DeveloperCode examples, implementation details
DevOpsServer configs, deployment procedures
QATest cases, validation steps
SecurityThreat analysis, compliance requirements
PMBusiness impact, resource requirements
ExecutiveStrategic overview, high-level recommendations

Accessing Advisor Recommendations

// HTTP audit automatically triggers advisor
FW_AuditManager auditManager = new FW_AuditManager();
auditManager.performHttpAudit(targetUrl);
// Recommendations available in HTTP report

// Manually access advisor for custom scenarios
FW_AdvisorEngine advisor = new FW_AdvisorEngine();
FW_AdvisorRecommendation recommendation = advisor
    .getRecommendation("no-https", FW_AdvisorAudience.DEVELOPER);

Advisor Template Example

{
  "finding": "no-https",
  "title": "No HTTPS - Site Uses Insecure HTTP",
  "understanding": {
    "what": "Website uses HTTP instead of HTTPS protocol",
    "why": "Exposes data to interception and manipulation",
    "impact": "Critical security vulnerability affecting all users"
  },
  "actions": {
    "developer": {
      "code": "// Redirect all HTTP to HTTPS\napp.use((req, res, next) => {...})"
    },
    "devops": {
      "servers": {
        "nginx": {
          "config": "server { listen 80; return 301 https://$host$request_uri; }"
        }
      }
    }
  }
}

Configuring mAi Advisor™

# mAi Advisor Configuration
advisor.enabled=true
advisor.audience=developer
advisor.templatePath=src/test/java/framework/advisor/templates
advisor.includeActions=true
advisor.verbosity=detailed

For complete mAi Advisor™ documentation, see mAi Advisor™ System.

Test Organization

Test Suite Structure

testsuites/
├── TS_Authentication_JUnit.java    # Login/logout tests
├── TS_Ordering_JUnit.java          # E-commerce flow tests
├── TS_HttpAssessment_JUnit.java    # Security audit tests
└── TS_Network_JUnit.java           # Network diagnostic tests

Best Practices

Advanced Patterns

Wait Strategies ?

// Explicit waits (preferred)
WebElement element = waitForElement(locator, 10);

// Fluent waits for complex conditions
Wait<WebDriver> wait = new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofSeconds(1))
    .ignoring(NoSuchElementException.class);

Error Handling

try {
    autoPass("Perform risky operation");
    riskyOperation();
} catch (Exception e) {
    autoFail("Operation failed: " + e.getMessage());
    throw e; // Re-throw to fail the test
}

Parallel Execution ?

# In junit-platform.properties
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent

Debugging Tests

Logging

// Framework logging
FW_DebugUtils.log("Debug message");
FW_DebugUtils.logWithTimestamp("Operation completed");

// Console output with colors
System.out.println(FW_ConsoleColors.GREEN + "Test passed" + FW_ConsoleColors.RESET);

Screenshots

// Manual screenshot capture
FW_ScreenUtils.captureScreenshot(driver, "screenshot-name");

// Automatic on assertion
autoPass("Visual checkpoint"); // Includes screenshot

Next Steps

DocumentDescription
Test Execution GuideRunning tests in VSCode
HTTP AssessmentSecurity auditing
Network DiagnosticsNetwork testing
mAi Advisor™Intelligent recommendations
Architecture DiagramsVisual framework overview