程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

*args和**kwargs(0)

debug(0)

标签  

set(0)

三元运算符(0)

日期归档  

ATF-(Vantpy1.03)自动化测试框架

发布于2019-12-07 22:54     阅读(2304)     评论(0)     点赞(25)     收藏(0)


ATF(Auto_Test_Framework)Vantpy1.03


关于框架:

重要声明:Vantpy1.0原作者Vant 944921374@qq.com Vantpy框架基于Selenium+Yaml+Unittest搭建的WebUI自动化测试框架
持续更新By jasonleeyag@163.com

特点:

  • 使用POM(页面对象模式)设计,使代码更加有逻辑性,测试脚本更加规范,后期更加容易维护以及复用性更高
  • 支持多种定位方式,包括(xpath/css/ID/text/link_text/name)
  • 框架集成了Selenium的常用定位方法,使元素定位更加方便
  • 单进程模式使用HTMLTestRunner作为自动生成测试报告,报告更加美观,更加详细,内容更丰富
  • 多进程模式使用BeautifulReport作为自动生成测试报告。
  • Logging日志输出,可以看到每一步做的操作
  • Yaml作为数据管理,实现代码,数据分离,使框架的使用起来更加简单

部署环境:

更新日志:

1.01 封装了选择窗口、选择iframe、点击alert方法。

1.02 将单进程report样式从引用百度修改为离线样式。

1.03 增加多进程及并发运行模式。

使用到的package:

pip install selenium

pip install BeautifulReport

pip install pyyaml

pip install tomorrow3

pip install requests

第三方插件

Autoit V3 HTMLTestRunner3

支持的浏览器及驱动:

基于Selenium支持的所有浏览器

  1. browser == "Chrome"
  2. browser == "firefox"
  3. browser == "IE"
  4. browser == "phantomjs"
  5. browser == "opera"
  6. browser == "edge"

geckodriver(Firefox):https://github.com/mozilla/geckodriver/releases

Chromedriver(Chrome):https://sites.google.com/a/chromium.org/chromedriver/home

IEDriverServer(IE):http://selenium-release.storage.googleapis.com/index.html

operadriver(Opera):https://github.com/operasoftware/operachromiumdriver/releases

MicrosoftWebDriver(Edge):https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver

定位元素方式:

  1. class BaiduPage(BasePage):
  2. """
  3. 在这里写定位器,通过元素属性定位元素对象
  4. """
  5. search_loc =(By.XPATH,'//*[@id="kw"]')#定位百度文本框
  6. def input_baidu_text(self,text):
  7. self.send_key(self.search_loc,text)

读取yaml数据

  1. brwserType:
  2. browserName : Chrome
  3. testUrl:
  4. URL : https://www.baidu.com
  1. file_path = os.path.dirname(os.getcwd())
  2. name_path = file_path + '\conf\config.yaml'
  3. with open(name_path, 'r') as f:
  4. temp = yaml.load(f.read())

日志输出

  1. 2018-06-02 14:58:13,521 - INFO - You had select Chrome browser.
  2. 2018-06-02 14:58:13,524 - INFO - The test url is: https://www.baidu.com
  3. 2018-06-02 14:58:19,629 - INFO - Starting Chrome browser.
  4. 2018-06-02 14:58:20,456 - INFO - Open url: https://www.baidu.com
  5. 2018-06-02 14:58:21,607 - INFO - Maximize the current window.
  6. 2018-06-02 14:58:21,609 - INFO - Set implicitly wait 5 seconds.
  7. 2018-06-02 14:58:21,609 - INFO - Clear input-box: //*[@id="kw"]...
  8. 2018-06-02 14:58:22,723 - INFO - Input element by xpath: //*[@id="kw"]...
  9. 2018-06-02 14:58:22,723 - INFO - Input: selenium

生成测试报告

  1. def report():
  2. if len(sys.argv) > 1:
  3. report_name = os.path.dirname(os.getcwd()) + '\\report\\' + sys.argv[1] + '_result.html'
  4. else:
  5. now = time.strftime("%Y-%m-%d_%H_%M_%S_")
  6. # 需要查看每段时间的测试报告,可以这样写:
  7. # report_name = os.getcwd() + '\\report\\'+now+'result.html'
  8. report_name = os.path.dirname(os.getcwd()) + '\\report\\result.html'
  9. return report_name
  10. fp = open(report(), 'wb')
  11. Runner = HTMLTestRunner(
  12. stream=fp,
  13. title='测试报告',
  14. description='测试用例执行情况'
  15. )

测试报告(单进程模式)

其他注意事项

   运行报错找不到某某文件路径,请自行修改BrowserDriver.py以及logger.py


所属网站分类: 技术文章 > 博客

作者:慧雅

链接:https://www.pythonheidong.com/blog/article/170259/fbbaa32bb0cba7642f24/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

25 0
收藏该文
已收藏

评论内容:(最多支持255个字符)