Manual Testing With Python: Automate Your First Test in 30 Minutes
If you are a manual tester looking to learn automation, Python is the best starting point. It has readable syntax that resembles English, a massive testing ecosystem, and more job postings than any other automation language in QA.
This guide takes you from zero to a working automated test in 30 minutes. No prior programming experience required. By the end, you will have a Python test that opens a browser, navigates to a page, checks that elements exist, and reports pass or fail.
Why Python for Test Automation
Python dominates QA automation for three reasons:
Readability. Python code reads like pseudocode. A manual tester can look at assert "Login" in driver.title and understand what it does without learning syntax rules first.
Libraries. Selenium, Playwright, pytest, requests, BeautifulSoup: Python has mature, well-documented libraries for browser automation, API testing, data-driven testing, and reporting. You do not need to build infrastructure from scratch.
Community. When you get stuck, a Google search will find answers. Python has the largest testing community on Stack Overflow, and frameworks like pytest have extensive documentation with examples.
Setup: Python and Selenium in 10 Minutes
Install Python from python.org (version 3.10 or later). During installation, check "Add Python to PATH." Open a terminal and run:
pip install selenium pytest
Next, download ChromeDriver from the Chrome for Testing site. Match the version to your Chrome browser version. Place the chromedriver executable in a folder on your system PATH, or use webdriver-manager:
pip install webdriver-manager
Create a file called test_login.py and add this code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://the-internet.herokuapp.com/login")
assert "Login" in driver.title or "Internet" in driver.title
print("Page loaded successfully")
driver.quit()
Run it with python test_login.py. If a browser opens, navigates, and closes without error, your setup works.
Writing Your First Real Test With pytest
The script above works but is not a proper test. Let us convert it to use pytest, the standard Python test framework:
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
@pytest.fixture
def browser():
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
yield driver
driver.quit()
def test_login_page_loads(browser):
browser.get("https://the-internet.herokuapp.com/login")
heading = browser.find_element(By.TAG_NAME, "h2")
assert heading.text == "Login Page"
def test_login_with_valid_credentials(browser):
browser.get("https://the-internet.herokuapp.com/login")
browser.find_element(By.ID, "username").send_keys("tomsmith")
browser.find_element(By.ID, "password").send_keys("SuperSecretPassword!")
browser.find_element(By.CSS_SELECTOR, "button[type=submit]").click()
assert "secure" in browser.current_url
Run with pytest test_login.py -v to see detailed output. pytest discovers test functions (prefixed with test_), manages the browser fixture, and reports results automatically.
From Manual Test Case to Automated Script
Every manual test case maps to an automated test. The translation follows a pattern:
Manual step: "Navigate to the login page" becomes browser.get(url)
Manual step: "Enter username" becomes browser.find_element(By.ID, "username").send_keys("value")
Manual step: "Click Submit" becomes browser.find_element(By.CSS_SELECTOR, "selector").click()
Expected result: "User sees dashboard" becomes assert "dashboard" in browser.current_url
Start by automating your most repetitive manual tests: login flows, form submissions, and navigation checks. These give the highest time savings and are the easiest to automate.
