图像差异识别 & 页面自动遍历 Selenium 插件

A-GPL
Python
泰斯特test · July 09, 2020 · 1350 次阅读 · 6 条评论

Pic-Diff-Recognizer

基于图像差异识别与页面遍历探索的 Selenium UI 自动化测试插件库。

此库诞生的起源是为了让 UI 自动化测试不再需要与页面元素打交道, 而是直接使用真实的视觉差异来判断测试结果是否符合预期。

相关介绍文章

安装

 pip install -r requirements.txt

pip install pic-diff-recognizer

最佳实践

from pic_diff_recognizer.searchHandler import SearchHandler
from violent_webdriver import Chrome
from 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 searchHandler
search_handler = SearchHandler(browser=dr)

# search and saving baseline images in current directory named baseline
search_handler.traverse_href(origin_url='https://gitbook.cn/gitchat/author/5cea0bfbb78cc870612d8bba')

# -------------------- assuming after some iterations of current project -----------------------------

search_handler.url_histories = []

# load baseline images
search_handler.picture_handler.load_base_line()

# search and comparing screen shots and baseline images
search_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 directory
search_handler.picture_handler.generate_diff_between_base_line_and_screen_shot()

# output testReport.txt to current directory
search_handler.picture_handler.export_picture_comparison_result()

源码地址

https://github.com/amazingTest/Pic-Diff-Recognizer

评论列表
泰斯特test 发表于 October 22, 2020

@hong 目前没有考虑这么完善哈哈,算是抛砖引玉一下

hong 发表于 October 21, 2020

好像有些页面可能异常之后不会超时跳过?

泰斯特test 发表于 September 30, 2020

@wuhanwoaini521
有什么问题可以直接提 issue 哈 https://github.com/amazingTest/Pic-Diff-Recognizer

秃头修炼者 发表于 August 25, 2020

你好 有群吗 相关介绍文章里面的 二维码 不好用了

泰斯特test 发表于 August 04, 2020

@chenhengjie123 已修复

陈恒捷 发表于 August 03, 2020

logo 直接变码云 403 图片了。。。麻烦修正下?