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

一、搭建环境相关地址以及相关模块下载地址

1、#各个浏览器驱动下载地址:

https://www.cnblogs.com/nancyzhu/p/8589764.html 

2、#sublime+python+selenium自动化配置教程:

http://python.tedu.cn/know/289803.html 

3、#html测试报告:

https://github.com/defnngj/HTMLTestRunner         http://www.testpub.cn/t/213 

4、#page objects插件下载地址 pip install page_objects:

https://github.com/eeaston/page-objects 

5、邮件模板下载地址pip3  install yagmail:

https://github.com/kootenpv/yagmail

二、使用实例

1、模块级别的fixture:

2、类级别的fixture:

3、鼠标事件:

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

4、规范:元素定位与动作分离:

5、测试执行discover匹配文件:

6、测试报告:

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

7、发送邮件:

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

 

posted @ 2019-05-14 00:18  漫步sch  阅读(791)  评论(0)    收藏  举报