UI automation - Web

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

qawa

qawa stands for QA Web Automation.

Page object model

qawa uses POM (page object model), also called the page object pattern.

Read up on it here.

Example of a page class

from utilities.base_page import BasePage
from selenium.webdriver.common.by import By

class BlogPage(BasePage):

slug = "/the-capsized-eight"
shameless_link_locator = (By.LINK_TEXT, "Shameless")
topic_label_locator = (By.CLASS_NAME, "__highlight")

def navigate_to_page(self):
    self.navigate(self.slug)

@property
def shameless_link(self):
    return self.get_present_element(self.shameless_link_locator)

@property
def topic_label(self):
    return self.get_present_element(self.topic_label_locator)

Example of a test class

from utilities.base_test import BaseTest
from utilities.loggers import log_message
from pages.blog_page import BlogPage


class BlogTests(BaseTest):
    def setUp(self):
        super().setUp()
        self.blog_page = BlogPage(self.driver)

def test_navigate_to_shameless_posts(self):
    log_message(
        "Navigates to Shameless blog posts and verifies that the topic label is Shameless."
    )

    self.blog_page.navigate_to_page()
    self.blog_page.shameless_link.click()
    self.blog_page.save_screenshot("shameless")

    self.assertTrue(self.blog_page.topic_label.text == "Shameless")

Writing assertions

Some common assertion methods in unittest.

Checking that something exists:

self.assertTrue(self.page.button)

Checking that something does not exist:

self.assertFalse(self.page.button)

Checking that something is equal:

self.assertEqual(self.page.button.text, "Logout")

Checking that something is not equal:

self.assertNotEqual(self.page.button.text, "Logout")

Additional resources


dil-ai.png