Skip to content

Commit 23b54e7

Browse files
adding library files
1 parent bc4435e commit 23b54e7

File tree

12 files changed

+177
-2
lines changed

12 files changed

+177
-2
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ __pycache__/
66
# Distribution
77
.DS_Store
88
.cache/
9+
10+
# python identifiers
11+
.python-version
12+
13+
# pytest reports
14+
reports/

Data/DynamicData/sample.yml

Whitespace-only changes.

Data/GlobalData/global_data.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
URL: https://naresh.free.beeceptor.com
2+
timeout: 10

Data/StaticData/sample.yml

Whitespace-only changes.

Data/__init__.py

Whitespace-only changes.

Library/__init__.py

Whitespace-only changes.

Library/store.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Store:
2+
3+
URL = None
4+
global_data_path = None
5+
dynamic_data_path = None
6+
static_data_path = None

Library/variable.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import os
2+
import yaml
3+
import allure
4+
from Library.store import Store
5+
6+
7+
class Var:
8+
file_name = None
9+
static_variable = None
10+
dynamic_variable = None
11+
file_path = None
12+
static_data_path = Store.static_data_path
13+
dynamic_data_path = Store.dynamic_data_path
14+
global_data_path = Store.global_data_path
15+
16+
def __init__(self, file_name, type):
17+
self.file_name = file_name
18+
if type == "static":
19+
try:
20+
self.file_path = self.static_data_path + '/' + file_name
21+
with open(self.file_path) as file:
22+
self.static_variable = yaml.load(file, Loader=yaml.FullLoader)
23+
allure.attach.file(self.file_path, name=self.file_name, attachment_type=allure.attachment_type.TEXT)
24+
except Exception as e:
25+
print(e)
26+
if type == "dynamic":
27+
try:
28+
self.file_path = self.dynamic_data_path + '/' + file_name
29+
if not os.path.isfile(self.file_path):
30+
if str(self.env("snap")) == "1":
31+
f = open(self.file_path, "w")
32+
f.close()
33+
with open(self.file_path) as file:
34+
self.dynamic_variable = yaml.load(file, Loader=yaml.FullLoader)
35+
allure.attach.file(self.file_path, name=self.file_name, attachment_type=allure.attachment_type.TEXT)
36+
except IOError as e:
37+
print("File is not accessible\n" + str(e))
38+
except Exception as e:
39+
print(e)
40+
41+
@staticmethod
42+
def env(string):
43+
try:
44+
return os.environ[string]
45+
except Exception as e:
46+
print(e)
47+
return "None"
48+
49+
@staticmethod
50+
def glob(string):
51+
try:
52+
with open(Var.global_data_path) as file:
53+
global_data = yaml.load(file, Loader=yaml.FullLoader)
54+
return global_data[string]
55+
except Exception as e:
56+
print(e)
57+
return "None"
58+
59+
def static_value_for(self, string) -> str:
60+
try:
61+
return self.static_variable[string]
62+
except Exception as e:
63+
print(e)
64+
return ""
65+
66+
def write(self, params):
67+
if self.env("snap") == "1":
68+
with open(self.file_path, 'w') as file:
69+
documents = yaml.dump(params, file)
70+
print(documents)
71+
72+
def dynamic_value_for(self, string) -> str:
73+
try:
74+
return self.dynamic_variable[string]
75+
except Exception as e:
76+
print(e)
77+
return ""
78+
79+
def compare(self, displayed_variable):
80+
if self.env("snap") == "1":
81+
self.write(displayed_variable)
82+
for key, value in displayed_variable.items():
83+
try:
84+
file_value = self.dynamic_variable[key]
85+
except Exception as e:
86+
print(e)
87+
file_value = "key_not_available"
88+
if file_value == "key_not_available":
89+
with allure.step("Verifying the key: " + str(key)):
90+
assert (file_value == value), "Key is not available in the dynamic data file\n Key:- " + key \
91+
+ "\nTo store the displayed value try running the suite with\n" \
92+
+ "snap=1 pytest"
93+
else:
94+
with allure.step("Verifying the key: " + str(key)):
95+
assert (str(file_value) == str(value)), "Value for the Key:- " + str(key) + ", Mismatches\n" \
96+
+ "File Value:- " + str(file_value) \
97+
+ "\nDisplayed Value:- " + str(value) \
98+
+ "\nFile used for validation is:" + self.file_name \
99+
+ "\nTo change the Dynamic file value run the suite with" \
100+
+ "\nsnap=1 pytest"

Tests/__init__.py

Whitespace-only changes.

Tests/conftest.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import datetime
2+
import os
3+
import pytest
4+
import allure
5+
import glob
6+
from Library.store import Store
7+
8+
9+
@pytest.fixture(autouse=True)
10+
def before_each():
11+
print('*-* Before each INITIALIZATION')
12+
try:
13+
yield
14+
# After each test case taking screen shots form the available drivers
15+
except Exception as e:
16+
print(e)
17+
print('*-* After each END')
18+
19+
20+
@pytest.fixture(scope='module', autouse=True)
21+
def before_module():
22+
print('*-* Before module INITIALIZATION')
23+
yield
24+
# after each module ensuring the browsers are closed
25+
print('*-* After module END')
26+
27+
28+
def pytest_configure(config):
29+
"""
30+
Allows plugins and conftest files to perform initial configuration.
31+
This hook is called for every plugin and initial conftest
32+
file after command line options have been parsed.
33+
"""
34+
print("*-* pytest_configure")
35+
# Configuring the selpy with data path location
36+
Store.global_data_path = os.path.dirname(
37+
os.path.abspath(__file__)).replace("/Tests", "") + '/Data/GlobalData/global_data.yml'
38+
Store.static_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/TestData/'
39+
Store.dynamic_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/DynamicData/'
40+
41+
42+
def pytest_sessionstart(session):
43+
"""
44+
Called after the Session object has been created and
45+
before performing collection and entering the run test loop.
46+
"""
47+
print("*-* pytest_sessionstart")
48+
49+
50+
def pytest_sessionfinish(session, exitstatus):
51+
"""
52+
Called after whole test run finished, right before
53+
returning the exit status to the system.
54+
"""
55+
print("*-* pytest_sessionfinish")
56+
57+
58+
def pytest_unconfigure(config):
59+
"""
60+
called before test process is exited.
61+
"""
62+
print("*-* pytest_unconfigure")

Tests/sample.py

Whitespace-only changes.

pytest.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
markers =
33
sanity: sanity tests marker
44
regression: regression tests marker
5-
ui: UI tests marker
6-
api: API tess marker
5+
snap: Snap feature enabled for this case, should have separate file for validating the response
76
python_files=*.py
87
python_functions=test_*
98
addopts = -rsxX

0 commit comments

Comments
 (0)