-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
63 lines (51 loc) · 1.85 KB
/
utils.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
import csv
import random
import sqlite3
import string
import xml.etree.ElementTree as ET
import requests
from config import STORAGE, FILE
import logging
import os
import json
def get_test_data():
"""
Return list of values from the file specified in config.py
"""
if STORAGE == "csv":
with open(FILE) as f:
test_data = list(csv.reader(f))[1:]
elif STORAGE == "xml":
with open(FILE) as f:
tree = ET.parse(f)
container = tree.findall("account")
test_data = [[i.find('from_username').text,
i.find('from_password').text,
i.find('to_username').text,
i.find('to_password').text] for i in container]
elif STORAGE == "sqlite":
con = sqlite3.connect(FILE)
cur = con.cursor()
cur.execute("""SELECT from_username, from_password,
to_username, to_password FROM accounts""")
test_data = cur.fetchall()
cur.close()
con.close()
else:
raise ValueError('Invalid data type. Specify correct STORAGE in settings.py')
return test_data
def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
def get_screenshot(driver):
file_path = os.path.join(os.getcwd(), "logs", "screenshots",
"{}.png".format(random_string_generator(size=5)))
driver.save_screenshot(file_path)
file_link = img_uploader(file_path)
logging.error(
"Element can't be located. Check screenshot for details: {}".format(file_link))
def img_uploader(img_path):
url = os.environ.get("upload_api")
file = {"file": open(img_path, "rb")}
my_session = requests.Session()
res = my_session.post(url, files=file)
return res.text