Library › Book 12 › Methods and Properties
Methods and Properties
9.1🔒OverviewA class without methods is just a data container. Methods give objects behavior -- the ability to do things. In test automation, methods…
9.2🔒Instance MethodsAn instance method operates on a specific object. It accesses that object's data through self (Python) or this (JavaScript/TypeScript).
9.3🔒Static MethodsA static method belongs to the class itself, not to any particular object. It cannot access self or this instance data. Use static methods…
9.4🔒Class Methods (Python) and Factory PatternsPython has a special @classmethod decorator that receives the class itself as the first argument. This is commonly used for alternative…
9.5🔒Getters and Setters (Computed Properties)Getters and setters let you access computed values as if they were simple properties. They are ideal for derived data that should stay in…
9.6🔒Exercises: Chapter 9Easy: Add a duration_display() method to a TestResult class that returns a human-readable string like "1.42s" or "890ms" depending on…
9.7🔒Q&AQuiz: Chapter 91. What is the difference between an instance method and a static method? 2. In Python, what does the @property decorator do? 3. How do…
9.8🔒Career Translation- Designed page object classes with computed properties for URLs, titles, and element visibility, ensuring derived values always reflected…
9.9🔒Q&AInterview Depth CheckPrompt: Why would you use a computed property (getter) for a page object's URL instead of storing it as a regular string property? What a…