import os,importlib
import yaml
#from conf import P1
#from conf import all
from conf import sitepush1017th
from common import suite
import sys
from time import ctime
from conf import config
import xlrd
from threading import Thread
importlib.reload(config)
from common.compareImages import CompareImages
def count_images(path,path1):
image_pairs = []
no_expect = []
for image in os.listdir(path):
if image.endswith("jpeg"):
actual_path = os.path.join(path+"\\"+image)
expect_path = os.path.join(path1+"\\"+image)
if os.path.exists(expect_path):
image_pairs.append([actual_path,expect_path])
else:
no_expect.append(actual_path)
print ("No Such file or directory in baseline",no_expect)
return image_pairs
def loop(image_pairs,start,stop):
compare = CompareImages()
for i in range(start,stop):
actual_path = image_pairs[i][0]
expect_path = image_pairs[i][1]
compare.compare_images(actual_path,expect_path)
def multi_thread_compare(path,path1):
image_pairs = count_images(path,path1)
count = len(image_pairs)
THREAD_LIMIT = 50
threads=[]
for j in range(THREAD_LIMIT):
step = count/THREAD_LIMIT
start = max((j)*step,1)
if j == THREAD_LIMIT -1:
stop = max((j+1)*step, count)
else:
stop = (j+1)*step
t=Thread(target=loop,args=(image_pairs,start,stop))
threads.append(t)
print ('start:', ctime())
for m in threads:
m.start()
for m in threads:
m.join()
print ('end:', ctime())
def run(documents):
for test_data in yaml.load_all(documents,Loader=yaml.FullLoader):
for site in test_data.keys():
browsers = test_data[site].keys()
for browser in browsers:
# open config file and write the browser and url information
# print "test site: " + site + " on browser: " , browser
with open ("E:\\Python\\Thrive\\src\\conf\\config.py",'r') as f:
lines = f.readlines()
for line in lines:
if line.startswith("URL"):
index = lines.index(line)
lines[index] = "URL = '" + site + "'\n"
elif line.startswith("BROWSER"):
index = lines.index(line)
lines[index] = "BROWSER = '" + browser + "'\n"
f = open("E:\\Python\\Thrive\\src\\conf\\config.py",'w+')
f.writelines(lines)
f.close()
diction = test_data[site][browser]
#create test suite
sys.path.append("E:\\Python\\Thrive\\src\\testCases")
cases = suite.create_suite(diction)
# run test cases
if not os.path.exists(config.OUTPUT):
os.makedirs(config.OUTPUT)
else:
pass
report = os.path.join(config.OUTPUT,"report.html")
suite.runner(cases,report)
multi_thread_compare(config.OUTPUT,config.BASELINE)
if __name__ == '__main__':
#multi_thread_compare(config.OUTPUT,config.BASELINE)
run(sitepush1017th.documents)