执行入口



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)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值