一、断言
assert cur_title=='百度一下,你就知道1','title断言失败'
'title断言失败':自定义报错
二、截图
# 调用截屏方法(路径+截图名称)
driver.get_screenshot_as_file('../image/image.png')
from selenium import webdriver from time import sleep import os driver=webdriver.Chrome() # 最大化 driver.maximize_window() driver.get('https://www.baidu.com') cur_title=driver.title cur_url=driver.current_url print(cur_title) print(cur_url) assert cur_title=='百度一下,你就知道','title断言失败' try: assert cur_title=='百度一下,你就知道1','title断言失败' assert cur_url=='https://www.baidu.com/123' except: # 调用截屏方法 # driver.get_screenshot_as_file('../image/image.png') driver.get_screenshot_as_file('image.png') sleep(3) driver.quit()