Automation Languages

In-depth theory of the languages used in test automation. Pick a language to study how it works, its core concepts, and how QA engineers write Selenium / Playwright / Cypress (or Robot) with it.

What is Python?

Python is a high-level, interpreted, dynamically typed language created by Guido van Rossum (first released in 1991). It emphasizes readability — “code is read more often than it is written.” That makes it one of the most popular choices for test automation, scripting, API testing, and data validation.

How Python works (theory)

  • Interpreted: Source runs through the CPython interpreter (bytecode → Virtual Machine). You do not compile a .exe for normal scripts.
  • Dynamic typing: Types are checked at runtime. A variable can hold an int, then later a string (unless you add type hints + tools).
  • Everything is an object: Numbers, strings, functions, and classes are all objects with identity, type, and value.
  • Indentation is syntax: Blocks are defined by spaces (PEP 8 recommends 4 spaces), not braces {}.
  • Garbage collected: Memory is managed automatically (reference counting + cyclic GC).

Core building blocks

1. Variables & types

Common built-in types: int, float, bool, str, list, tuple, dict, set, None.

name = "tester"          # str
age = 28                 # int
passed = True            # bool
roles = ["QA", "SDET"]   # list (mutable)
point = (10, 20)         # tuple (immutable)
user = {"id": 1, "name": "Alex"}  # dict
print(type(name), len(roles))

2. Operators & truthiness

Python treats empty values as falsy: 0, "", [], {}, None, False. Everything else is truthy. Comparison uses == (value) vs is (identity). Prefer == for strings and numbers.

3. Control flow

status = "success"
if status == "success":
    print("PASS")
elif status == "pending":
    print("WAIT")
else:
    print("FAIL")

for role in ["Admin", "User"]:
    print(role)

count = 0
while count < 3:
    count += 1

4. Functions

Functions are first-class (you can pass them as arguments). Use default args, *args, **kwargs, and return values.

def login(username, password="password123"):
    """Return True if credentials look valid."""
    return bool(username and password)

assert login("tester") is True

5. Modules & packages

Reuse code with import. Automation projects usually split pages, tests, and utilities into modules.

from selenium.webdriver.common.by import By
import time

6. OOP for Page Objects

Classes group state + behavior. In automation, a Page Object class stores locators and actions for one page/section.

class LoginPage:
    def __init__(self, driver):
        self.driver = driver

    def login(self, user, password):
        self.driver.find_element(By.ID, "login-username").send_keys(user)
        self.driver.find_element(By.ID, "login-password").send_keys(password)
        self.driver.find_element(By.ID, "login-submit").click()

7. Exceptions (error handling)

Selenium raises exceptions like NoSuchElementException. Catch what you expect; fail fast on unexpected errors.

from selenium.common.exceptions import NoSuchElementException

try:
    driver.find_element(By.ID, "missing").click()
except NoSuchElementException:
    print("Element not found — check locator or wait")

Python mental model for automation

  1. Launch / connect to a browser (driver or page).
  2. Navigate to a URL / section.
  3. Locate elements (By.ID, CSS, XPath…).
  4. Act (click, type, select) and wait for readiness.
  5. Assert outcomes (assert, pytest, unittest).
  6. Clean up (quit browser, close files).

Ecosystem for QA

  • Selenium WebDriver — classic cross-browser UI automation
  • Playwright for Python — modern auto-waits, tracing, multi-browser
  • pytest — test runner, fixtures, parametrize, plugins
  • Robot Framework — keyword-driven layer on top of Python
  • requests — API testing alongside UI

Selenium (Python) example

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://qapracticehub.com/#forms")

driver.find_element(By.ID, "login-username").send_keys("tester")
driver.find_element(By.ID, "login-password").send_keys("password123")
driver.find_element(By.ID, "login-submit").click()

msg = driver.find_element(By.ID, "login-message").text
print(msg)
assert "success" in msg.lower()
driver.quit()

Playwright (Python) example

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://qapracticehub.com/#forms")
    page.locator("#login-username").fill("tester")
    page.locator("#login-password").fill("password123")
    page.locator("#login-submit").click()
    print(page.locator("#login-message").inner_text())
    browser.close()

Best practices in Python automation

  • Follow PEP 8; keep functions small and named by behavior (submit_login).
  • Use explicit waits (or Playwright auto-wait) — avoid fixed time.sleep except debugging.
  • Store locators in Page Objects / constants, not scattered strings.
  • Use virtual environments (venv) and pin dependencies (requirements.txt).
  • Prefer pytest fixtures for driver setup/teardown.

Practice driver / By steps in Try it Yourself.