Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Test automation and frameworks

Practical study notes on test automation and frameworks: definitions, framework types (data-driven, keyword-driven, POM), architecture, CI/CD integration, example automated tests and an ROI worked example.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Engineers use test automation to run repeatable checks of software quickly and reliably during development and release. Automated tests and frameworks reduce manual effort, catch regressions early, and integrate into CI/CD pipelines so teams can deliver quality software faster.

Key ideas

  • Required properties (state as assumptions universities expect): tests must be repeatable (produce same results given same inputs and environment), maintainable (easy to update when application changes), scalable (handle growing test suites), and deterministic (no flaky/timing-dependent failures).

  • Common framework types (define each):

    • Record–playback framework — records user actions and replays them. Simple but brittle and poor for maintenance.
    • Linear scripting framework — tests are written as independent scripts without reuse structures. Good for quick smoke checks, poor reuse.
    • Modular (function) framework — test logic split into modules/functions and reused. Assumption: functions are stable and map to application features.
    • Library architecture framework — reusable libraries for common actions; tests call libraries. More structured than modular.
    • Data-driven framework — separates test logic from test data. Test inputs and expected results come from external sources (CSV, Excel, JSON, DB). Definition: if tests iterate over data sets from files, it is data-driven.
    • Keyword-driven framework — uses a table of keywords representing actions; a driver executes keywords mapping to implementation functions. Useful for non-programmers to author tests.
    • Hybrid framework — combines two or more frameworks (data-driven + keyword + POM) to get benefits of each. Also commonly seen: Behavior-Driven (BDD) frameworks (e.g., Cucumber, SpecFlow, Behave) that use Given–When–Then (Gherkin) to define tests; BDD is often combined with POM/data-driven in a hybrid.
  • Page Object Model (POM) — a design pattern for UI automation where each page (or component) is represented by a class exposing actions and locators. Exact statement: For every distinct UI page or component, create a class that encapsulates locators and methods representing user operations, so tests use these methods rather than direct locators. Assumption: UI elements are stable enough to group logically. Best practice: avoid assertions inside Page Objects; keep verifications in tests.

  • Automation pyramid (draw and label): Draw a triangle divided into three horizontal layers. Bottom (largest): Unit tests (fast, many). Middle: Service/API tests. Top (smallest): UI/end-to-end tests (slow, few). Label each layer with typical tools (unit: JUnit/pytest, API: Postman/REST Assured, UI: Selenium/Appium) and goals (speed vs coverage).

  • CI/CD integration — hooking automated tests into Continuous Integration systems (e.g., Jenkins, GitHub Actions, GitLab CI) so tests run on code changes. Key idea: tests should be fast and reliable enough for CI; slow tests run nightly or in a release pipeline. Also configure parallel execution (e.g., pytest-xdist, TestNG parallel, Selenium Grid) to keep build times low.

  • Test selection and scheduling principles — choose tests by value: critical tests every commit, regression/smoke on merge, full suite nightly. Define entry/exit criteria for automation runs (refer to "Test planning and test strategy" topic).

  • Test stability techniques: use explicit waits, retry-on-fail only for known transient issues, avoid hard-coded sleeps, and isolate tests (no shared state). Define flaky test: a test that passes and fails intermittently without code change.

  • Reporting and metrics — frameworks must produce machine-readable and human-readable reports (JUnit XML, HTML) and metrics like pass/fail counts, execution time, flaky rates, and coverage of requirements.

  • Assertions and verification — an assertion is a statement that compares actual vs expected result. Strong tests use clear, single-purpose assertions per test to make failures easy to diagnose.

Formulas

(Syntax and short lines to remember for common automation tools and patterns)

WebDriver driver = new ChromeDriver(); — Java Selenium: create browser driver (requires a matching ChromeDriver binary, or Selenium Manager/WebDriverManager to resolve it automatically). Applies when using Selenium WebDriver.

driver.get("https://example.com"); — navigate browser to URL.

driver.findElement(By.id("username")).sendKeys("user"); — find element by id and type.

driver.findElement(By.cssSelector(".btn-primary")).click(); — click using CSS selector.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.elementToBeClickable(By.id("login"))); — explicit wait until condition.

@Test — JUnit/TestNG annotation to mark a test method (Java).

assert expected == actual — Python/pytest basic assertion (raises on false).

@pytest.mark.parametrize("input,expected", [(1,2),(3,4)]) — pytest syntax for data-driven tests.

driver.quit(); — close browser and end session.

ROI / break-even formula (automation economics):

Automation ROI time (runs) = Automation cost / (Manual time saved per run) — when runs exceed this number, automation pays off.

Symbols: Automation cost (time to automate in hours or money), Manual time saved per run (hours saved for each automated run). Units: hours or currency; apply when test is repeated frequently.

Example monetary form: Break-even runs = Cost_to_automate (INR) / Cost_saved_per_run (INR).

Worked examples

Example 1 — Small Selenium + POM data-driven test (algorithm trace):

Problem: Test login on example.com with two credential sets (one valid, one invalid). Use Page Object Model and CSV data.

Steps (numbered):

  1. Create LoginPage class with methods: open(), enterUsername(u), enterPassword(p), clickLogin(), getErrorText().
  2. Test driver script reads CSV file with rows: (user1, pass1, expected=success), (user2, pass2, expected=fail).
  3. For each row: call LoginPage.open(), enterUsername, enterPassword, clickLogin.
  4. If expected==success, assert user is on dashboard: assert driver.findElement(By.id("dashboard")).isDisplayed(); else assert LoginPage.getErrorText().toLowerCase().contains("invalid").

Trace for first row (valid):

  • open() navigates to /login
  • sendKeys username -> element value set
  • sendKeys password -> element value set
  • click login -> navigation to /dashboard
  • assert dashboard displayed -> pass

Trace for second row (invalid):

  • open login
  • fill credentials
  • click -> page shows error
  • getErrorText returns "Invalid username or password"
  • assertion lower-cases the text and checks it contains "invalid" -> pass

Expected output: two test runs, one pass for success and one pass for expected failure. Tests report should show 2 tests, 2 passed.

Example 2 — Automation economics (numerical) — compute break-even runs:

Given: Time to automate a test = 10 hours. Manual execution time per run = 0.5 hours. Developer/tester salary cost = 400 INR per hour. All times costed at same rate.

Compute automation cost in INR: 10 h * 400 INR/h = 4000 INR.

Manual cost saved per run: 0.5 h * 400 INR/h = 200 INR.

Break-even runs = 4000 / 200 = 20 runs.

Interpretation: If you run this test more than 20 times (e.g., daily/regression), automation saves money. Bold final answer: Break-even runs = 20.

(Assumptions: same person does automation and manual runs at same rate; maintenance cost of automated test is not included.)

Common mistakes

  • Using hard-coded sleeps (Thread.sleep) rather than explicit waits, causing flaky tests. Do not confuse this with Selenium implicit waits, which are different and should not be mixed with explicit waits.
  • Tightly coupling tests to UI layout rather than using POM methods.
  • Not cleaning test state (shared data), causing tests to fail intermittently.
  • Running full heavy UI suite on every commit instead of a small smoke/regression subset in CI.
  • Lack of assertions or multiple asserts that hide the real failure cause.

For your exam

Question types you will see: definitions (define test automation, framework, POM), short notes (compare framework types), diagrams (draw automation pyramid or framework architecture), derivations (show ROI/break-even computation), programs/algorithms (write a simple Selenium or pytest test), and case-study answers (design a framework for a given application).

What a full-marks answer includes:

  • For definitions: precise bold definition, assumptions, and an example.
  • For diagrams: a clear labeled drawing (describe what to draw, e.g., a pyramid with layers and labels) and short explanation of each label.
  • For design questions: name chosen framework type, justify choice (ROI, test stability), list main components (test runner, locators, data store, reporting, CI), and show a simple sequence diagram or step list of test execution.
  • For code questions: correct syntax, necessary setup/teardown, and at least one meaningful assertion.

Quick check

  1. What is the Page Object Model (POM)?
  2. Give two benefits of data-driven testing.
  3. Calculate break-even runs if automation cost = 3000 INR and saved per run = 150 INR.

Answers: POM is a design pattern that represents each UI page as a class encapsulating locators and actions; benefits: separates test logic from data enabling reuse and easier maintenance, allows running same test logic with many data sets; break-even runs = 3000 / 150 = 20.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?