Requirements

The goal of the assignment is to write a few tests for a web application which is available here: https://mystifying-beaver-ee03b5.netlify.app/. It displays a table with some fake data about cyber security attacks: name, number of cases, average impact, and complexity of the attack. Above the table, there are 2 controls: sorting selection and filtering.

The task is to write a set of tests that will ensure that the combination of sorting and filtering works correctly. However there's a catch: you need to write your tests in such a way that if I modify the data on the website (if I remove some rows or add new ones), your tests still correctly verify the functionality.

For the sorting part, you can choose 2 fields that you will validate (instead of doing all 4). Here's additional information that can help you:

  • capital letters are ignored by both filtering and sorting (it works as if all letters were small letters)
  • sorting works only in one direction: from low to high, from A to Z, sorting by complexity sorts from low to high
  • number of cases uses special formatting, thousands might be expressed as letter "k" (5000 = 5k), millions as M (1200000 = 1.2M), billions as "B" (1580000000 = 1.58B)In order to write the tests you can use any programming language and framework of your choice as long as it is possible to run your tests in UNIX-like environment.

sorting-filtering-table-data

This project is written in Python, using Pytest and Selenium WebDriver. The Page Object Model pattern has been applied.

Used resources

Python 3: | https://www.python.org/downloads/
Selenium: | https://selenium-python.readthedocs.io/
Pytest: | https://docs.pytest.org/en/7.2.x/
Pytest-HTML: | https://pytest-html.readthedocs.io/en/latest/
pytest-xdist: | https://www.tutorialspoint.com/pytest/pytest_run_tests_in_parallel.htm

Installed libraries

selenium==4.5.0
pytest-html==3.2.0
pytest-xdist==3.0.2
pytest==7.2.0
webdriver-manager==3.8.4
pytest-html-reporter==0.2.9

Folder structure

|___ sorting-filtering-table-data
    |___ pages
        |_____ __init__.py
        |_____ base_page.py
        |_____ statistics_page.py
    |___ tests
        |_____ __init__.py
        |_____ base_test.py
        |_____ test_suite.py.py
        |_____ conftest.py
    |___ utils
        |_____ __init__.py
        |_____ test_data.py
        |_____ utils.py
    |___ resources
    |___ reports
        |_____  html*
    |___ pyproject.toml
    |___ pytest.ini
    |___ README.md
    |___ requirements.txt

Package description

Contains page objects that are visible from any page,

Contains the base_page which is the parent page for other pages like: statistics_page, ..., in the base_page are functions used in its children pages:

check_page_loaded()
select_by_value()
find_element()
find_elemens()
wait_element()

rest of the pages contains functions (page actions) strictly related to their individual pages

Contains the base_test and the actual test file test_suite, in the base test it is initialized the web driver and before and after functions.

Contains the "conf_data.py" and "helpers.py" files.
The "conf_data.py" contains configuration data
The "helpers.py" contains the helper functions needed for this project

Config Files Description

It is configuration file for pytest

It is project settings file

This is a list of all of a project’s dependencies.

Project description

BaseTest

BaseTest is marked to use pytest fixture init_driver which take as argument a list of webdrivers name default is set ["chrome"] in tests/conftest::init_driver(), if add one more element in that list (e.g. ["chrome", "firefox"]) then both drivers will start

Run Tests in Parallel

For parallel running another library is used pytest-xdist, for running in parallel just add one more argument -n <number of parallel runs> to this command pytest -n 3 tests/test_suite.py --html=path/to/reports

Reporting

After the test execution is finished a html report will be created in reports/html the reports are generated by pytest-html reporter.
For generate the report it needs to be run in this way pytest tests/test_suite.py --html=path/to/reports unless this argument is set in pyproject.tomlsettings file.

Project expansion

Just create new page objects in pages package, by inheriting BasePage and init it's using super().__init__(driver) in page object __init__ function, init locators class inside the __init__ function of the page object, then create page specific actions, like in the bellow example

from pages.base_page import BasePage
from pages.another_page import AnotherPage


class SamplePage(BasePage):
    
    def __init__(self, driver)
    super().__init__(sriver)
    
    def click_on_specific_button(self):
        self.find_element(*self.locator.SAMPLE_LOCATOR).click()
        return AnotherPage(self.driver)

Usage Steps:

  1. clone the project locally git clone https://github.com/mottwan/sorting-filtering-table-data.git
  2. install python on your local machine
  3. make sure at least google-chrome web browser it is installed on your local machine
  4. install virtualenv python3 -m pip install --user virtualenv
  5. create virtualenv python3 -m venv venv
  6. activate virtual env source env/bin/activate
  7. from project root folder install project dependencies pip install -r requirements.txt
  8. run the test from command line pytest tests/test_suite.py