Page Transactions as a new way to organize your testing automation

The pattern

Guará is the Python implementation of the design pattern Page Transactions. It is more of a programming pattern than a tool. As a pattern, it can be bound to any driver other than Selenium including the ones used to Linux, Window and Mobile automation.

The intent of this pattern is to simplify test automation. It was inspired by Page Objects, App Actions, and Screenplay. Page Transactions focus on the operations (transactions) a user can perform on an application, such as Login, Logout, or Submit Forms.

 

The Framework in action

This simple implementation mimics the user switching languages in a Web Page:

from selenium import webdriver
from guara.transaction import Application
from guara import it, setup
import home 

def test_language_switch():
    app = Application(webdriver.Chrome())

    # Open the application
    app.at(setup.OpenApp, url="https://example.com/")

    # Change language and assert
    app.at(home.ChangeToPortuguese).asserts(it.IsEqualTo, "Conteúdo em Português")
    app.at(home.ChangeToEnglish).asserts(it.IsEqualTo, "Content in English")

    # Close the application
    app.at(setup.CloseApp)

Each user transaction is grouped into its own class (e.g., ChangeToPortuguese) which inherits from AbstractTransaction. The tester just has to override the do method and the framework does the work.

from guara.transaction import AbstractTransaction

class ChangeToPortuguese(AbstractTransaction):
    def do(self, **kwargs):
        self._driver.find_element(By.CSS_SELECTOR, ".btn-pt").click()
        return self._driver.find_element(By.CSS_SELECTOR, ".content").text

Try Guará today!