Functions & Object-Oriented Basics
Part of the QA Testing Roadmap
In short
Your first script works. Your tenth script has the same login steps copied ten times, and one change breaks all of them. Functions and classes fix that mess.
Organizing code into reusable functions, and understanding classes and objects — essential for building maintainable automation frameworks rather than one giant, unstructured script.

Think of it like this
The idli mould
The mould tray is the design: round, this size, this deep. Every idli that comes out is its own idli, with its own chutney. A class is the mould, each object is an idli, and a method is something every idli can do.
Watch it happen
Inside a TestUser class
1/4A class is a blueprint. It describes what every test user looks like and can do.
The big ideas
What you need to know
Functions bundle steps
def login(user, pwd) wraps five lines into one name. Call it from every test that needs a login.
Inputs and outputs
Parameters go in, a return value comes out. Same input should give the same output.
Class vs object
A class is the design. An object is one real thing made from it, with its own values.
One place to fix
When the login flow changes, you edit one function, not forty tests.
See it in code
Walk through the code
1class TestUser:2 def __init__(self, name, role):3 self.name = name4 self.role = role5 6 def can_delete(self):7 return self.role == "admin"8 9 10admin = TestUser("Asha", "admin")11viewer = TestUser("Ravi", "viewer")12 13print(admin.name, admin.can_delete()) # Asha True14print(viewer.name, viewer.can_delete()) # Ravi False1/4__init__ runs when you create an object and stores its name and role.
One class, two objects with different data. The same method gives different answers for each.
Save yourself the pain
Common mistakes
Oops
Writing one giant 300-line script with no functions.
Do this instead
Split repeated steps into small functions with clear names like add_to_cart().
Oops
Forgetting self in Python methods, then getting confusing errors.
Do this instead
Every method's first parameter is self. Use self.name, not just name, inside it.
Your mission
Build a tiny Product class
Quick check
You create two objects from the same class. What do they share?
Go deeper
- 1Refactor a script into reusable functions instead of repeated inline code.
- 2Learn the basics of defining a class and creating an object from it.
- 3Understand why object-oriented structure matters specifically for the Page Object Model (Phase 7).
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.