Google Summer of Code
#GSoC Empowering Tomorrow's Coders: Igniting, Innovating, and Inspiring Mauticians of the Future with Google Summer of Code.
Week 5-6: End-to-end test suite for Mautic- The Dance of Locators
Hey everyone! Back again with updates on my GSoC project. We started by building the environment, learned some testing tricks, and started creating tests for contacts.
Now it’s time to make them organized. That's where Page Objects and Step Objects come in! Think of them as filing cabinets and handy tools for keeping our tests clean and easy to understand. Imagine a test for creating a new contact. We'd need to interact with various elements on the "Create Contact" page, like name fields, email addresses, and dropdown menus. Traditionally, these element locators (like IDs or CSS selectors) would be scattered throughout the test code. This can be messy and hard to maintain, especially as the test suite grows.
What is a Page Object?
In simple terms it is storage of UI locators (UI Map). The PageObject pattern represents a web page as a class and the DOM elements on that page as its properties, and some basic interactions as its methods. Do not hard-code complex CSS or XPath locators in your tests but rather move them into PageObject classes.
Creating Page Objects:
ddev exec bin/codecept generate:pageobject acceptance ContactPage
This creates a file ContactPage.php in tests/_support/Page/Acceptance.
Example Page Object:
What is a Step Object?
These represent reusable actions we perform across different pages like logging in or submitting a form. Think of them as reusable tools in your testing toolbox.
Creating Step Objects:
ddev exec bin/codecept generate:stepobject acceptance Contact
This creates a file Contact.php in tests/_support/Step/Acceptance.
Example Step Object:
How do our tests look now?
Implementing Page and Step Objects takes some effort initially, but the benefits are huge!
- Readability: Tests become easier to understand for everyone.
- Maintainability: Updating tests becomes a breeze as element locators are stored in one place.
- Reusability: Common actions can be reused across different tests.
Next week’s focus:
The coming weeks will be focused on:
- Expanding test coverage to include more Mautic features.
- Finalizing Page and Step Object implementation for existing tests.
Let's collaborate: You can review the Pull Request : https://github.com/mautic/mautic/pull/13884
Thanks for following along! See you next week for another update.
Reportar um problema
Este conteúdo é impróprio?
0 comentários
Carregando comentários ...
Adicione seu comentário
Inscreva-se com sua conta ou sign up para adicionar seu comentário.
Carregando comentários ...