python+selenium自动化环境配置及使用实例

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()

七、发送邮件:

八、测试套件、测试执行:

相关文章
相关标签/搜索