Page Transactions as a new way to organize your testing automation
<h2>The pattern</h2>
<p><strong>Guará</strong> is the Python implementation of the design pattern <strong>Page Transactions</strong>. 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.</p>
<p>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.</p>
<p> </p>
<h2>The Framework in action</h2>
<p>This simple implementation mimics the user switching languages in a Web Page:</p>
<div class="highlight js-code-highlight">
<pre>
<code>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)
</code></pre>
<p>Each user transaction is grouped into its own class (e.g., <strong>ChangeToPortuguese</strong>) which inherits from <strong>AbstractTransaction</strong>. The tester just has to override the <strong>do</strong> method and the framework does the work.</p>
<pre>
<code>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
</code></pre>
<p><a href="https://github.com/douglasdcm/guara" rel="noopener noreferrer" target="_blank">Try Guará today!</a></p>
<p> </p>
</div>