Design Patterns – Running Automated Tests on Cross Platforms

Design Patterns – Running Automated Tests on Cross Platforms

Running automated tests on multiple platforms can at times turn into a nightmare. In order to avoid falling prey, careful thought needs to be given to ensuring the Test Code logic is reliable, clear, flexible, and maintainable.

With these regards understanding design patterns become crucial. The best way to use design patterns is to ensure they are registered in your mind and applying them then comes naturally and matures with experience.

Structural Patterns to structure test code are important. When dealing with large lines of code indirectly involves using huge chunks of locators dealing with various functionality. One of the popular patterns to ensure you have clear segregation of your locators and functions is using the Page Object pattern. When we deal with applications spanning across multiple pages it is always advisable to split and bifurcate them page-wise. Also, it is a good practice to name the functions and locators well, so they are easily identifiable and maintainable. This also makes the code readable and adaptable to change.

Page Object Pattern

Don’t Repeat Yourself DRY should be kept in mind with an aim to avoid repetition in code. Always avoid copy/paste. One thing to remember is that duplication increases maintenance costs. Blind inheritance and overrides cause a huge problem. Look at ways of how to attach additional responsibilities to object dynamically using the Decorator pattern.

Decorator Pattern

Creational Patterns allow for the best ways on how to create objects in your test code. When dealing with cross-platforms it is also very important that you are creating a single point of control. One needs to also ensure we are allowing control of concurrent access to shared resources. Here the Singleton pattern comes very handy. This ensures that a class has only one instance and provides a global point to access it.

Singleton Pattern

Always ensure to keep code clean doing so ensure it easily understood by everyone in the team. It’s worthwhile to remember KISS – Keep it simple, stupid to ensure code is kept as simple and possible and any sort of complexity is avoided. Separate data management from test logic to allow for better readability and maintainability. Use a Builder pattern to separate the construction of a complex object from its representation.

No alt text provided for this image

Behavioral Patterns help identify common communication patterns. When dealing with testing cross-platform algorithms would vary and change. It’s important to encapsulate each strategy and allow it to make them interchangeable. This helps with increasing the flexibility in the code and still being loosely coupled. Here, a Strategy Pattern can be followed which enables selecting an algorithm at runtime. The code receives run-time instructions as to which family of the algorithm to use.

No alt text provided for this image

Hope these design patterns would help guide you in overcoming commonly occurring problems while writing automation code. As they say,

Learning from your mistakes makes you smart but Learning from others mistakes makes you a genius. 
Dhanalaxmi Otari

Tester with the vision of intensifying software testing righteously and simplified, by implementing test design techniques, test methodologies, planning and selecting relevant testing.

3 年

Thanks for posting

要查看或添加评论,请登录

社区洞察

其他会员也浏览了