Appilitools eyes是一款检测不同次运行页面是否相同的软件。同样运行一个测试程序,可能呈现出来的结果不同。不同的结果可能是bug,也可能是每次展现给用户的结果不同,比如百度搜索,淘宝页面,这里以百度搜索作为案例。
1,要使用Appilitools eyes,首先需要到Appilitools官网https://applitools.com/上注册账号(可以使用github的账号),注册完毕,它会给你一个密钥。
2,在本机上运行
pip3 install eyes-selenium
3,建立测试程序
#!/usr/bin/env python
# coding:utf-8
import unittest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from applitools.selenium import Eyes,Target
from selenium.webdriver.common.by import By
class checkEyes(unittest.TestCase):
def test_baidu(self):
driverPath= "C:\\Lib\\chromedriver.exe"
service= Service(executable_path=driverPath)
options= webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Lib\\ChromeProfile")
self.driver= webdriver.Chrome(service=service, options=options)
eyes= Eyes()
eyes.api_key="你的applitools密钥"
self.driver= webdriver.Chrome()
self.driver.implicitly_wait(5)
eyes.open(self.driver,"Baidu首页","检查百度首页及搜索结果")
self.driver.get('https://www.baidu.com')
#第一个视觉验证检查点
eyes.check("百度首页视觉验证",Target.window())
self.driver.find_element(By.ID,"kw").send_keys("hello world")
self.driver.find_element(By.ID,"su").click()
#第二个视觉验证检查点
eyes.check("百度搜索结果视觉验证",Target.window())
eyes.close()
self.driver.quit()
if __name__ == "__main__":
unittest.main()
运行,运行通过,他会告诉你
--- Test passed.
See details at https://eyes.applitools.com/app/batches/00000251648871736096/00000251648871735982?accountId=ag4cztZPEEOOoL6WkqNNqA__
.
----------------------------------------------------------------------
Ran 1 test in 20.359s
OK
到https://eyes.applitools.com/app/batches/00000251648871736096/00000251648871735982?accountId=ag4cztZPEEOOoL6WkqNNqA__查看
由于第一次运行,结果是正确的。再次运行,出现结果
Re-raising an error received from SDK server: DiffsFoundError("Test '检查百度首页及搜索结果' of 'Baidu 首页' detected differences! See details at: https://eyes.applitools.com/app/batches/00000251648871497323/00000251648871497183?accountId=ag4cztZPEEOOoL6WkqNNqA__")
E
======================================================================
ERROR: test_baidu (__main__.checkEyes.test_baidu)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\xiang\Desktop\eyes.py", line 31, in test_baidu
eyes.close()
File "C:\Users\xiang\AppData\Local\Programs\Python\Python312\Lib\site-packages\applitools\common\eyes.py", line 382, in close
return
super(WebEyes, self).close(raise_ex)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xiang\AppData\Local\Programs\Python\Python312\Lib\site-packages\applitools\common\eyes.py", line 184, in close
return
self._close(raise_ex, True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xiang\AppData\Local\Programs\Python\Python312\Lib\site-packages\applitools\common\eyes.py", line 233, in _close
results= self.get_results(raise_ex) if wait_result else []
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xiang\AppData\Local\Programs\Python\Python312\Lib\site-packages\applitools\common\eyes.py", line 167, in get_results
results= self._commands.eyes_get_results(self._eyes_ref, raise_ex)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xiang\AppData\Local\Programs\Python\Python312\Lib\site-packages\applitools\common\command_executor.py", line 275, in eyes_get_results
return self._checked_command(context, "Eyes.getResults", payload)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xiang\AppData\Local\Programs\Python\Python312\Lib\site-packages\applitools\common\command_executor.py", line 288, in _checked_command_check_error(response_payload)
File "C:\Users\xiang\AppData\Local\Programs\Python\Python312\Lib\site-packages\applitools\common\command_executor.py", line 298, in _check_error
raise
usdk_error
applitools.common.errors.DiffsFoundError: Test '检查百度首页及搜索结果' of 'Baidu 首页' detected differences! See details at: https://eyes.applitools.com/app/batches/00000251648871497323/00000251648871497183?accountId=ag4cztZPEEOOoL6WkqNNqA__
----------------------------------------------------------------------
Ran 1 test in 22.625s
FAILED (errors=1)
仍旧到https://eyes.applitools.com/app/batches/00000251648871736096/00000251648871735982?accountId=ag4cztZPEEOOoL6WkqNNqA__查看
第一个检查点是相同的,第二个则不同,所以报错。选择Ignore region,然后通过鼠标点掉图上的粉红色。
点击右上角的保存键
再次运行,测试通过。
= RESTART: C:\Users\xiang\Desktop\eyes.py
--- Test passed.
See details at https://eyes.applitools.com/app/batches/00000251648869473990/00000251648869473901?accountId=ag4cztZPEEOOoL6WkqNNqA__
.
----------------------------------------------------------------------
Ran 1 test in 25.603s