Pic-Diff-Recognizer - 基于图像差别识别与页面自动遍历的开源 UI 测试库

最近某人把以前的 UI 测试新思路与代码整理了一番,
css


因而有了 Pic-Diff-Recognizer 的诞生。python



什么是 Pic-Diff-Recognizer ?nginx


Pic-Diff-Recognizer  是基于图像差别识别与页面遍历探索的Selenium UI 自动化测试插件库。git


此库诞生的目的是为了让 UI 自动化测试再也不须要与页面元素打交道, web

而是直接使用真实的视觉差别来判断测试结果是否符合预期。
chrome





如何安装?微信


首先安装开源项目目录下的依赖包:
app


pip install -r requirements.txt


而后再安装今天的主角:less


pip install pic-diff-recognizer



如何使用?
测试


下面给你们放出最佳实践:


from pic_diff_recognizer.searchHandler import SearchHandlerfrom violent_webdriver import Chromefrom selenium.webdriver.chrome.options import Options

# add some useful options :)chrome_options = Options()chrome_options.add_argument("--headless")chrome_options.add_argument("disable-infobars")chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
# init driver , executable_path should be your own path!dr = Chrome.violent_chromedriver(chrome_options=chrome_options, executable_path='/usr/local/bin/chromedriver')
# init searchHandlersearch_handler = SearchHandler(browser=dr)
# search and saving baseline images in current directory named baselinesearch_handler.traverse_href(origin_url='https://gitbook.cn/gitchat/author/5cea0bfbb78cc870612d8bba')
# -------------------- assuming after some iterations of current project -----------------------------
search_handler.url_histories = []
# load baseline imagessearch_handler.picture_handler.load_base_line()
# search and comparing screen shots and baseline imagessearch_handler.traverse_href(origin_url='https://gitbook.cn/gitchat/author/5cea0bfbb78cc870612d8bba', compare_baseline_and_screen_shots=True)
# generate_diff_between_base_line_and_screen_shot and output diffResults to current directorysearch_handler.picture_handler.generate_diff_between_base_line_and_screen_shot()
# output testReport.txt to current directorysearch_handler.picture_handler.export_picture_comparison_result()



能够看到在项目迭代分割线以前,


程序先探索并保存了待测页面的图像。



而在项目迭代分割线以后,


程序再次探索待测页面并对比了图像差别,


最终输出测试报告。



相信这很好的对应了现实项目迭代中的回测节奏。



固然,目前来讲此库还有许多能够改进的地方。


对源码地址有兴趣的小伙伴能够在公众号内回复:


Pic-Diff-Recognizer



最后喊个口号吧:开源,yes!

本文分享自微信公众号 - AI测试前线(TaisiteMagicWorld)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。

相关文章
相关标签/搜索