Skip to content

Commit

Permalink
Add allure reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Averkin committed May 7, 2019
1 parent 3ac082e commit 4bde7bd
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 6 deletions.
15 changes: 12 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
wget https://dl.bintray.com/qameta/maven/io/qameta/allure/allure-commandline/2.11.0/allure-commandline-2.11.0.zip
unzip allure-commandline-2.11.0.zip
- save_cache:
paths:
- ./venv
Expand All @@ -24,7 +26,14 @@ jobs:
name: run tests
command: |
. venv/bin/activate
pytest -v
chmod -R 777 ./allure-2.11.0/bin/
pytest --alluredir=./allure-results
- run:
name: run report
when: always
command: |
./allure-2.11.0/bin/allure generate -c
- store_artifacts:
path: test-reports
destination: test-reports
path: allure-report
destination: allure-report
when: always
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.idea/
.DS_Store
.pytest_cache
__pycache__
__pycache__
.allure-report
allure-report
allure-results
16 changes: 16 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import allure
import pytest

@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item):
outcome = yield
rep = outcome.get_result()
marker = item.get_closest_marker("ui")
if marker:
if rep.when == "call" and not rep.passed: # we only look at actual failing test calls, not setup/teardown
try:
allure.attach(item.instance.driver.get_screenshot_as_png(),
name=item.name,
attachment_type=allure.attachment_type.PNG)
except Exception as e:
print(e)
8 changes: 8 additions & 0 deletions pageobjects/base_page.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import allure
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
Expand All @@ -10,18 +11,21 @@ def __init__(self, driver):
self.driver = driver
self.wait = WebDriverWait(driver, 15)

@allure.step
def wait_for_element(self, element, selector_type: By):
self.wait.until(EC.presence_of_element_located((selector_type, element)))
self.wait.until(EC.visibility_of_element_located((selector_type, element)))
self.wait.until(EC.element_to_be_clickable((selector_type, element)))

@allure.step
def click_elem(self, element, selector_type: By):
self.wait.until(EC.presence_of_element_located((selector_type, element)))
self.wait.until(EC.visibility_of_element_located((selector_type, element)))
self.wait.until(EC.element_to_be_clickable((selector_type, element)))
elem = self.driver.find_element(selector_type, element)
elem.click()

@allure.step
def type_to_elem(self, element, selector_type: By, text, clean=True, click_enter=False, type_delay=False):
self.wait.until(EC.presence_of_element_located((selector_type, element)))
self.wait.until(EC.visibility_of_element_located((selector_type, element)))
Expand All @@ -38,21 +42,25 @@ def type_to_elem(self, element, selector_type: By, text, clean=True, click_enter
if click_enter:
elem.send_keys(Keys.ENTER)

@allure.step
def get_field_data(self, element, selector_type: By):
self.wait.until(EC.presence_of_element_located((selector_type, element)))
self.wait.until(EC.visibility_of_element_located((selector_type, element)))
elem = self.driver.find_element(selector_type, element)
return elem.get_attribute('value')

@allure.step
def presence_of_element(self, element, selector_type: By):
for i in range(10):
time.sleep(0.3)
if not self.driver.find_elements(selector_type, element):
return False
return True

@allure.step
def count_issues(self, element, selector_type: By):
return self.driver.find_elements(selector_type, element)

@allure.step
def browser_refresh(self):
self.driver.refresh()
9 changes: 8 additions & 1 deletion pageobjects/issues_page.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from selenium.webdriver.common.by import By
import time
import allure

from pageobjects.base_page import BasePage

Expand All @@ -21,9 +21,11 @@

class IssuePage(BasePage):

@allure.step
def get_title(self):
return self.driver.title

@allure.step
def create_issue(self, summary=None, priority=None, assignee=None, new_issue=True):
if new_issue:
self.click_elem(create_issue_button_id, By.ID)
Expand All @@ -34,6 +36,7 @@ def create_issue(self, summary=None, priority=None, assignee=None, new_issue=Tru
return False
return True

@allure.step
def update_issue(self, summary=None, priority=None, assignee=None):
self.type_to_elem(summary_field_id, By.ID, summary, True)
self.type_to_elem(priority_field_css, By.CSS_SELECTOR, priority, True, True)
Expand All @@ -42,11 +45,13 @@ def update_issue(self, summary=None, priority=None, assignee=None):
return False
return True

@allure.step
def open_issue_in_list(self, summary):
self.click_elem('.issue-list [title="%s"] a' % summary, By.CSS_SELECTOR)
self.wait_for_element(edit_issue_button_id, By.ID)
self.click_elem(edit_issue_button_id, By.ID)

@allure.step
def get_issue_fields(self, close_edit=True):
fields_data_list = []
fields_data_list.append(self.get_field_data(summary_field_id, By.ID))
Expand All @@ -55,6 +60,7 @@ def get_issue_fields(self, close_edit=True):
self.click_elem(cancel_issue_button_css, By.CSS_SELECTOR)
return fields_data_list

@allure.step
def search_issues(self, summary):
self.type_to_elem(search_field_id, By.ID, summary, True, True)
self.wait_for_element(edit_issue_button_id, By.ID)
Expand All @@ -63,6 +69,7 @@ def search_issues(self, summary):
else:
return 0

@allure.step
def search_nonexistent_issues(self, summary):
self.type_to_elem(search_field_id, By.ID, summary, True, True)
if self.driver.find_elements(By.CSS_SELECTOR, issues_list_css):
Expand Down
5 changes: 5 additions & 0 deletions pageobjects/login_page.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from selenium.webdriver.common.by import By
from pageobjects.base_page import BasePage
import allure

login_form_id = 'login-form-username'
password_form_id = 'login-form-password'
Expand All @@ -10,18 +11,22 @@

class LoginPage(BasePage):

@allure.step
def get_title(self):
return self.driver.title

@allure.step
def login_to_jira(self, login, password):
self.type_to_elem(login_form_id, By.ID, login)
self.type_to_elem(password_form_id, By.ID, password)
self.click_elem(submit_button_id, By.ID)
return self.presence_of_element(create_issue_id, By.ID)

@allure.step
def on_page(self):
return self.presence_of_element(create_issue_id, By.ID)

@allure.step
def open(self, url):
self.driver.get(url)
return self
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
allure-pytest==2.6.2
allure-python-commons==2.6.2
appdirs==1.4.0
astroid==1.4.9
atomicwrites==1.3.0
Expand Down Expand Up @@ -34,4 +36,4 @@ urllib3==1.24.2
webdriver-manager==1.7
wrapt==1.10.8
xmltodict==0.12.0
pytest==4.4.0
pytest==4.4.0
24 changes: 24 additions & 0 deletions tests/test_jira_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

import allure
import pytest

creds = "OlegAverkin"
base_url = "http://jira.hillel.it:8080"
auth_url = base_url + "/secure/RapidBoard.jspa?projectKey=WEBINAR"
Expand All @@ -19,25 +22,46 @@ def setup_method(self):
self.login_page.open(my_issues)
self.login_page.login_to_jira(creds, creds)

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Create issue")
def test_create_issue(self):
assert self.issue_page.create_issue("OA_new_issue", "Blocker", "OlegAverkin") is True

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Verify created issue")
def test_verify_created_issue(self):
self.issue_page.open_issue_in_list("OA_new_issue")
assert self.issue_page.get_issue_fields() == ["OA_new_issue", "Blocker"]

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Create issue with long summary")
def test_create_issue_with_long_summary(self):
assert self.issue_page.create_issue("x" * 256, "Blocker", "OlegAverkin") is False

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Vreate issue with empty summary")
def test_create_issue_with_empty_summary(self):
assert self.issue_page.create_issue("", "Blocker", "OlegAverkin", True) is False

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Search issue")
def test_search_issue(self):
assert self.issue_page.search_issues("OA_new_issue") == 1

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Search nonexistent issue")
def test_search_nonexistent_issue(self):
assert self.issue_page.search_nonexistent_issues("somethingwrong") == 0

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Update issue")
def test_update_issue(self):
self.issue_page.open_issue_in_list("OA_new_issue")
assert self.issue_page.update_issue("OA_updated_issue", "Low", "OlegAverkin") is True
Expand Down
14 changes: 14 additions & 0 deletions tests/test_login_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pageobjects.login_page import LoginPage
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import allure
import pytest

creds = "OlegAverkin"
fake_creds = "fake_user"
Expand All @@ -15,20 +17,32 @@ def setup_method(self):
self.driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
self.login_page = LoginPage(self.driver)

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Check title")
def test_check_title(self):
self.login_page.open(auth_url)
assert self.login_page.get_title() == login_title

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Login with wrong password")
def test_login_with_wrong_password(self):
self.login_page.open(auth_url)
self.login_page.login_to_jira(creds, fake_creds)
assert self.login_page.get_title() == login_title

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Login with wrong username")
def test_login_with_wrong_username(self):
self.login_page.open(auth_url)
self.login_page.login_to_jira(creds, fake_creds)
assert self.login_page.get_title() == login_title

@pytest.mark.ui
@allure.tag('ui')
@allure.title("Login with correct credentials")
def test_login_with_correct_credentials(self):
self.login_page.open(auth_url)
self.login_page.login_to_jira(creds, creds)
Expand Down

0 comments on commit 4bde7bd

Please sign in to comment.