1、搭建環境相關地址以及相關模塊下載地址html
一、#各個瀏覽器驅動下載地址:python
https://www.cnblogs.com/nancyzhu/p/8589764.html git
二、#sublime+python+selenium自動化配置教程:github
http://python.tedu.cn/know/289803.html 瀏覽器
三、#html測試報告:測試
https://github.com/defnngj/HTMLTestRunner http://www.testpub.cn/t/213 ui
四、#page objects插件下載地址 pip install page_objects:spa
https://github.com/eeaston/page-objects 插件
五、郵件模板下載地址pip3 install yagmail:3d
https://github.com/kootenpv/yagmail
2、使用實例
一、模塊級別的fixture:
二、類級別的fixture:
三、鼠標事件:
(1)懸停事件
js使用方法:
js = '' var q = document.getElementsByClassName(\''類名\'')[0];q.style.display=\''block\'' ; ''
driver.execute_script(js)
(2)將一個元素拖拽到一個區域:
from selenium.wedriver.common.action_chains import ActionChains
start_1 = driver.find_element_by_xpath("……")
actions = ActionsChains(driver)
actions.drag_and_drop_by_offset(start_1,20,20).perform()
(3)將一個元素與另外一個元素連成一條線:
start_2 = driver.find_elements_by_class_name("類名")[索引值]
end_2 = driver.find_elements_by_class_name("類名")[索引值]
actions.drag_and_drop(start_2,end_2).perform()
四、規範:元素定位與動做分離:
五、測試執行discover匹配文件:
六、測試報告:
suit = unittest.defaultTestLoader.discover('./','testcase*.py')
fp = open('./result.html','wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title=u'測試報告',
description=u'版本:V1.0,報告人:xxx'
)
runner.run(suit)
fp.close()
七、發送郵件:
八、測試套件、測試執行: