日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python selenium 框架说明_基于python+selenium的框架思路(二)

發(fā)布時(shí)間:2024/9/19 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python selenium 框架说明_基于python+selenium的框架思路(二) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

#coding:utf-8

from util importObjectMap, ExcelUtilimportxlrd, xlwtimporttimefrom xlutils.copy importcopydefrun_test():from selenium importwebdriver

start_time=time.time()#讀取excel中的關(guān)鍵字的值,定位方式的值,定位表達(dá)式,和操作值等參數(shù)值。然后將參數(shù)值傳到對(duì)應(yīng)關(guān)鍵字方法中

excelFile = xlrd.open_workbook(r"D:KeyWordsFrameWorkestScriptssearch.xlsx", formatting_info=True)

sheet0= excelFile.sheet_by_index(0) #獲取第一個(gè)sheet頁(yè)

#循環(huán)第一個(gè)sheet頁(yè),其中每一行代表一條用例

for row0 in range(1, sheet0.nrows):#一定要在這個(gè)for循環(huán)里面再寫一次excelFile,要不然執(zhí)行多條用例時(shí)只會(huì)在最后一條用例寫入結(jié)果

excelFile = xlrd.open_workbook(r"D:KeyWordsFrameWorkestScriptssearch.xlsx", formatting_info=True)

driver=webdriver.chrome()

case_name= sheet0.row_values(row0)[3] #獲取用例對(duì)應(yīng)的sheet頁(yè)

sheet = excelFile.sheet_by_name(case_name) #從第一個(gè)sheet中獲取對(duì)應(yīng)的用例名稱找到對(duì)應(yīng)的用例sheet

maxRows = sheet.nrows #獲取用例的最大行數(shù),也就是步驟數(shù)

successfulSteps = 0 #定義執(zhí)行成功的步驟數(shù)

retDict = {} #存放用例結(jié)果的字典

if sheet0.row_values(row0)[4] == 'y': #只執(zhí)行標(biāo)記為y的用例

#print case_name

for row in range(1, maxRows): #循環(huán)用例步驟

keyword = sheet.row_values(row)[2] #讀取關(guān)鍵字列

#print keyword

locationType = sheet.row_values(row)[3] #獲取定位方式

if locationType not in ['id','xpath','name']:passlocatorExpression= sheet.row_values(row)[4] #獲取定位表達(dá)式的值

operationValue = sheet.row_values(row)[5] #獲取操作值

#dir(ObjectMap)獲取該模塊的所有方法和變量

#print dir(ObjectMap)

#遍歷ObjectMap中的方法和屬性,如果有名稱一致的則通過(guò)反射調(diào)用對(duì)應(yīng)方法執(zhí)行關(guān)鍵字

for i indir(ObjectMap):if keyword ==i:#print i

#要用到反射機(jī)制,通過(guò)函數(shù)名字符串調(diào)用對(duì)應(yīng)方法:http://www.liujiangblog.com/course/python/48

ifhasattr(ObjectMap, keyword):#print '有這個(gè)方法'

func =getattr(ObjectMap, keyword)try:

func(driver, locationType, locatorExpression, operationValue)print '%s:execute OK' %keyword#執(zhí)行每個(gè)關(guān)鍵字成功后,成功步數(shù)+1

successfulSteps += 1

exceptException:print '%s:excute ERROR' %keywordfinally:#如果成功的步驟數(shù)等于用例的步驟數(shù),則整條用例執(zhí)行成功,寫入執(zhí)行結(jié)果

if successfulSteps == sheet.nrows - 1:

retDict['result'] = 'PASS'

print retDict['result']

end_time=time.time()

take_time= end_time -start_timeprinttake_time#向已經(jīng)存在的excel中寫入時(shí),需要先copy,copy后sheet頁(yè)獲取sheet方法為get_sheet,與

#原來(lái)的獲取方法不一樣

excleFileCopy =copy(excelFile)

case_sheet=excleFileCopy.get_sheet(0)

case_sheet.write(row0,5, take_time)

case_sheet.write(row0,6, retDict['result'])#寫入后需要save

excleFileCopy.save(r"D:KeyWordsFrameWorkestScriptssearch.xlsx")print 'pass write is ok'

else:

retDict['result'] = 'FAIL'

print retDict['result']

end_time=time.time()

take_time= end_time -start_timeprinttake_time

excleFileCopy=copy(excelFile)

case_sheet=excleFileCopy.get_sheet(0)

case_sheet.write(row0,5, take_time)

case_sheet.write(row0,6, retDict['result'])

excleFileCopy.save(r"D:KeyWordsFrameWorkestScriptssearch.xlsx")print 'fail write is ok'

else:raiseException

driver.quit()if __name__ == '__main__':

run_test()

總結(jié)

以上是生活随笔為你收集整理的python selenium 框架说明_基于python+selenium的框架思路(二)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。