Skip to content

Commit 48d1145

Browse files
adding screenshot after the test
1 parent 71740af commit 48d1145

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

Library/driver.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
from selenium.common.exceptions import NoSuchElementException
33
from selenium.webdriver.remote import webelement
44
from Library.variable import Var
5-
import os
6-
import datetime
7-
85
from Library.store import Store
96

107

@@ -61,12 +58,6 @@ def execute_script(self, script, locator) -> None:
6158
def current_url(self) -> str:
6259
return self.driver.current_url
6360

64-
def save_screenshot(self) -> str:
65-
root_dir = os.path.dirname(os.path.abspath(__file__))
66-
config_path = os.path.join(root_dir, 'reports/screenshot/img%s.png' % datetime.datetime.now().strftime("%Y%m%d-%H%M%S"))
67-
self.driver.save_screenshot(config_path)
68-
return config_path
69-
7061
def quit(self):
7162
self.driver.quit()
7263

Tests/conftest.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1+
import datetime
2+
import os
13
import pytest
4+
import allure
5+
import glob
6+
from Library.store import Store
27

38

49
@pytest.fixture(autouse=True)
510
def before_each():
611
print('*-* Before each INITIALIZATION')
7-
yield
12+
try:
13+
yield
14+
for driver in Store.drivers:
15+
root_dir = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "")
16+
config_path = root_dir + '/reports/screenshots/img%s.png' % datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
17+
driver.save_screenshot(config_path)
18+
name = 'img%s.png' % datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
19+
allure.attach(config_path, name=name, attachment_type="PNG")
20+
except Exception as e:
21+
print(e)
822
print('*-* After each END')
923

1024

1125
@pytest.fixture(scope='module', autouse=True)
1226
def before_module():
1327
print('*-* Before module INITIALIZATION')
1428
yield
29+
for driver in Store.drivers:
30+
driver.quit()
1531
print('*-* After module END')
1632

1733

@@ -21,27 +37,32 @@ def pytest_configure(config):
2137
This hook is called for every plugin and initial conftest
2238
file after command line options have been parsed.
2339
"""
24-
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_configure")
40+
print("*-* pytest_configure")
41+
root_dir = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "")
42+
config_path = root_dir + '/reports/screenshots/*.png'
43+
for CleanUp in glob.glob(config_path):
44+
print(CleanUp)
45+
os.remove(CleanUp)
2546

2647

2748
def pytest_sessionstart(session):
2849
"""
2950
Called after the Session object has been created and
3051
before performing collection and entering the run test loop.
3152
"""
32-
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_sessionstart")
53+
print("*-* pytest_sessionstart")
3354

3455

3556
def pytest_sessionfinish(session, exitstatus):
3657
"""
3758
Called after whole test run finished, right before
3859
returning the exit status to the system.
3960
"""
40-
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_sessionfinish")
61+
print("*-* pytest_sessionfinish")
4162

4263

4364
def pytest_unconfigure(config):
4465
"""
4566
called before test process is exited.
4667
"""
47-
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ pytest_unconfigure")
68+
print("*-* pytest_unconfigure")

Tests/google.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ def test_google_search():
2020

2121
with allure.step("second step"):
2222
GooglePage.enter_search_text(variable.loc("search_text"))
23-
d.quit()
2423

2524

0 commit comments

Comments
 (0)