# dna-qa-automation

# Playwright-based Test Automation Framework for the DNA web application
Read more about current project in confluence: 
https://data-analytics.atlassian.net/wiki/spaces/DNA/pages/2531950610/UI+Automation

Overview
=============
* Require Python 3.8+ version
* Framework is based on the page object model.
* Added Allure as reporting tool.
* Reading credentials from environment variables.
* Supports taking screenshots during failure and verification step.* 

### Coverage:
Here are 3 types of tests:
* UI tests located in _gui/_
* Visual(pixel-perfect) tests in _gui/visual_ tests using https://pypi.org/project/pytest-playwright-visual/
* api tests in _api/_
### Limitations:
* not included load tests
* not included performance tests
* visual tests is implemented only for separate elements

# SETUP with PLAYWRIGHT:
https://playwright.dev/python/docs/intro

**Install locally:**
1. Setup Playwright for python:
https://pypi.org/project/pytest-playwright/
   1. pip install pytest-playwright
   2. playwright install

2. Install requirements and dependencies:
pip install -r requirements/base.txt


RUN:
====
Run tests using pytest
### Run specific test suite:

sh
py.test --html=report.html --self-contained-html  --alluredir=allure_report src/tests/gui/test_saved_discoveries.py -n 4 --reruns 1

To run tests in parallel add option: -n {streams_count}


To add reruns for failed test:
--reruns {reruns_count}

**Or create run configuration in IDE.**
- Use parameters specified in [.env.sample](.env.sample)
- Contact DevOps in case you have no some values 

# RUN TESTS ON UAT:
1. With open DevTools login manually into UAT app
2. Grab refresh_token from token request
3. Put saved refresh_token in appropriate place in [state.json](state.json)
4. Start running any test locally with such env variables:
   - USER_EMAIL="your email"
   - NO_MFA=False
   - PWDEBUG=1
   - UAT endpoints in appropriate params 

How to run tests for UAT on CI find in confluence https://data-analytics.atlassian.net/wiki/spaces/DNA/pages/2531950610/UI+Automation#Run-process

REPORTING:
===
Both Allure and pytests reports are available

Generating allure report:
sh
make report

PyTest report is available after run as report.html file


CREATION OF YOUR OWN UI TEST:
===
All application-related code is stored in app/ directory.
Pages, actions and business logic are stored in app/pages/ directory and named accordingly to represented page.

    class LoginPage:
        def __init__(self, page: Page):
            self.page = page

        def check_title(self):
            expect(self.page).to_have_title('DNA')

        def start_searching(self):
            self.page.click("text=Start Searching")

        def menu_searches(self):
            self.page.click("xpath=//*[@id=\"root\"]/div/aside/div/nav/ul/li[2]/a")

        def start_new_search(self):
            self.page.click("text=Start new Search")

UI elements described in src/locators/ directory  in .py files named accordingly to represented page. Locator description includes related page, location strategy (xpath, css..) and locator itself.

         PASSWORD_FIELD = ("name", "passwd")

Tests are stored in src/tests/ dir and describe test flow, test file should contain 'test' in file name in order to pytest can collect it (test_login.py)':

    @allure.story("POC scope")
    @allure.severity(allure.severity_level.CRITICAL)
    @allure.title("Verifying all users notifications")
    def test_login(self):
        self.app.go_to('')

        self.login_page.check_title()

        self.login_page.start_searching()
        self.login_page.menu_searches()
        self.login_page.start_new_search()


TAKING SCREENSHOTS
===
Screenshots will be automatically taken during failure and attached to the allure report.
All screenshots will be saved under app/src/screenshots/ dir