What is the typical automation scenario where decorator design pattern can be applied in UI test automation ?

Please share your practical experiences with small code examples to help us fellow QA engineers.

Decorator Design Pattern: In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class.1 The decorator pattern is often useful for adhering to the Single Responsibility Principle, as it allows functionality to be divided between classes with unique areas of concern.

  • 3
    Interesting question but way too broad for canonical answer. In my experience all of them can be applied but it depends on the specific situation. Apr 18, 2018 at 11:47
  • 1
    ... and you will use those patterns exactly for the same reason as they are used in "standard" programming. Test automation is writing programs, like any other programs they have a certain goal: test another program. Apr 18, 2018 at 13:12
  • Narrowed down to one design pattern. Apr 18, 2018 at 19:35

1 Answer 1


I use a 'decorate' like approach for Page Objects
I create an empty Page Object class
The I read a yaml file of name-locators
For each name-locator I dynamically add (like decorate) a method that will return the locator when passed the name
I can do this partly because I use Ruby which allows this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.