-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy path180 7-util.py
130 lines (112 loc) · 4.16 KB
/
180 7-util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
@package utilities
Util class implementation
All most commonly used utilities should be implemented in this class
Example:
name = self.util.getUniqueName()
"""
import time
import traceback
import random, string
import utilities.custom_logger as cl
import logging
class Util(object):
log = cl.customLogger(logging.INFO)
def sleep(self, sec, info=""):
"""
Put the program to wait for the specified amount of time
"""
if info is not None:
self.log.info("Wait :: '" + str(sec) + "' seconds for " + info)
try:
time.sleep(sec)
except InterruptedError:
traceback.print_stack()
def getAlphaNumeric(self, length, type='letters'):
"""
Get random string of characters
Parameters:
length: Length of string, number of characters string should have
type: Type of characters string should have. Default is letters
Provide lower/upper/digits for different types
"""
alpha_num = ''
if type == 'lower':
case = string.ascii_lowercase
elif type == 'upper':
case = string.ascii_uppercase
elif type == 'digits':
case = string.digits
elif type == 'mix':
case = string.ascii_letters + string.digits
else:
case = string.ascii_letters
return alpha_num.join(random.choice(case) for i in range(length))
def getUniqueName(self, charCount=10):
"""
Get a unique name
"""
return self.getAlphaNumeric(charCount, 'lower')
def getUniqueNameList(self, listSize=5, itemLength=None):
"""
Get a list of valid email ids
Parameters:
listSize: Number of names. Default is 5 names in a list
itemLength: It should be a list containing number of items equal to the listSize
This determines the length of the each item in the list -> [1, 2, 3, 4, 5]
"""
nameList = []
for i in range(0, listSize):
nameList.append(self.getUniqueName(itemLength[i]))
return nameList
def verifyTextContains(self, actualText, expectedText):
"""
Verify actual text contains expected text string
Parameters:
expectedList: Expected Text
actualList: Actual Text
"""
self.log.info("Actual Text From Application Web UI --> :: " + actualText)
self.log.info("Expected Text From Application Web UI --> :: " + expectedText)
if expectedText.lower() in actualText.lower():
self.log.info("### VERIFICATION CONTAINS !!!")
return True
else:
self.log.info("### VERIFICATION DOES NOT CONTAINS !!!")
return False
def verifyTextMatch(self, actualText, expectedText):
"""
Verify text match
Parameters:
expectedList: Expected Text
actualList: Actual Text
"""
self.log.info("Actual Text From Application Web UI --> :: " + actualText)
self.log.info("Expected Text From Application Web UI --> :: " + expectedText)
if actualText.lower() == expectedText.lower():
self.log.info("### VERIFICATION MATCHED !!!")
return True
else:
self.log.info("### VERIFICATION DOES NOT MATCHED !!!")
return False
def verifyListMatch(self, expectedList, actualList):
"""
Verify two list matches
Parameters:
expectedList: Expected List
actualList: Actual List
"""
return set(expectedList) == set(actualList)
def verifyListContains(self, expectedList, actualList):
"""
Verify actual list contains elements of expected list
Parameters:
expectedList: Expected List
actualList: Actual List
"""
length = len(expectedList)
for i in range(0, length):
if expectedList[i] not in actualList:
return False
else:
return True