设想:

1、使用excel编写用例第一个sheet页为用例概要格式如下:

后面的sheet页为具体的用例步骤:

实现所有定位信息都与测试代码分离

2、读取该excel文件取出关键字等信息,作为关键字的参数,通过反射机制传递给关键字方法去执行。

  关键字模块如下:ObjectMap.py

# coding:utf-8
from selenium.webdriver.support.ui import WebDriverWait #获取单个页面元素对象
def get_element(driver, locationType, locatorExpression):
try:
element = WebDriverWait(driver, 30).until(lambda x:x.find_element(by=locationType,value = locatorExpression))
return element
except Exception, e:
raise e def get_elements(driver , locationType, locatorExpression):
try:
elements = WebDriverWait(driver, 30).until(lambda x:x.find_elements(by=locationType,value=locatorExpression))
return elements
except Exception, e:
raise e # 由于关键字函数的参数个数不一样,所以通过传递动态参数*args实现传参,关键字方法
# 最多需要(driver , locationType, locatorExpression, operationValue)四个参数
def open_browser(driver, *args):
driver.get(args[2]) def input_string(driver, *args):
WebDriverWait(driver, 30).until(lambda x: x.find_element(by=args[0], value=args[1])).send_keys(args[2]) def click(driver, *args):
WebDriverWait(driver, 30).until(lambda x: x.find_element(by=args[0], value=args[1])).click()

测试执行代码如下:

# coding:utf-8
from util import ObjectMap, ExcelUtil
import xlrd, xlwt
import time
from xlutils.copy import copy def baidu_search():
#初始化操作,创建driver
from selenium import webdriver
start_time = time.time()
# print start_time
driver = webdriver.Chrome()
#读取excel中的关键字的值,定位方式的值,定位表达式,和操作值等参数值。然后将参数值传到对应关键字方法中
excelFile = xlrd.open_workbook(r"D:\KeyWordsFrameWork\testScripts\search.xlsx", formatting_info=True)
sheet = excelFile.sheet_by_index(1)
maxRows = sheet.nrows
# print maxRows for row in range(1, maxRows-1):
keyword = sheet.row_values(row)[2]
locationType = sheet.row_values(row)[3]
locatorExpression = sheet.row_values(row)[4]
operationValue = sheet.row_values(row)[5]
# dir(ObjectMap)获取该模块的所有方法和变量
# print dir(ObjectMap)
for i in dir(ObjectMap):
if keyword == i:
# print i
# 要用到反射机制,通过函数名字符串调用对应方法:http://www.liujiangblog.com/course/python/48
if hasattr(ObjectMap, keyword):
# print '有这个方法'
func = getattr(ObjectMap, keyword)
func(driver, locationType, locatorExpression, operationValue)
end_time = time.time()
take_time = end_time-start_time
print take_time
excleFileCopy = copy(excelFile)
case_sheet = excleFileCopy.get_sheet(0)
case_sheet.write(1,5,take_time)
excleFileCopy.save(r"D:\KeyWordsFrameWork\testScripts\search.xlsx") if __name__ == '__main__':
baidu_search()

  

最新文章

  1. CozyRSS开发记录20-CanResizeWithGrip
  2. mysql sum 和 count 函数 合并使用
  3. Inline Workers--Web workers without a separate Javascript file
  4. 删除ecshop登录后台看到的系统信息
  5. 清除XCode缓存和生成文件
  6. kafka集群安装与配置
  7. hibernate导入大量数据时,为了避免内存中产生大量对象,在编码时注意什么,如何去除?
  8. NGUI系列教程三
  9. !! python 之半年总结
  10. 从头到尾彻底理解KMP(2014年8月22日版)
  11. w3school教程整理
  12. 非阻塞式线程安全列表-ConcurrentLinkedDeque
  13. java设计模式---备忘录模式
  14. PrismCDN 网络的架构解析,以及低延迟、低成本的奥秘
  15. sort_gff.py
  16. UI基础一:简单的BOL查询
  17. Windows平台Mysql使表名区分大小写
  18. Letterbox,Pillarbox和Pan&Scan
  19. dubbo 源码编译记录
  20. JavaScript 之 uploadify 或 SWFUpload上传问题

热门文章

  1. keil里面填数据
  2. Arduino UNO 键盘记录器中时钟接到2口或3口,其它接口不行。马上就要放弃了。要修改例子中时钟的引脚。
  3. SpringMVC前后台数据传递中Json格式的相互转换(前台显示格式、Json-lib日期处理)及Spring中的WebDataBinder浅析
  4. Linux实战教学笔记15:磁盘原理
  5. Python爬虫实战一之爬取糗事百科段子
  6. ubuntu如何安装samba
  7. [Training Video - 4] [Groovy] Function in detail
  8. Scala入门学习随笔
  9. python学习之内部执行流程,内部执行流程,编码(一)
  10. (1)WePHP 开启WePHP