软件测试/测试开发丨UI自动化测试用例结构分析

点此获取更多相关资料

本文为霍格沃兹测试开发学社学员学习笔记分享

原文链接:https://ceshiren.com/t/topic/26899

一、用例结构

1.1、标准的用例结构

  • 用例标题 搜狗搜索功能
  • 前提条件 进入搜狗首页
  • 用例步骤 1、输入关键词;2、点击搜索
  • 预期结果 1、搜索成功;2、搜索结果中包含关键字
  • 实际结果

1.2、自动化测试用例结构

自动化测试用例 作用
用例标题 测试包、文件、类、方法名称 用例的唯一标识
前提条件 setup、setup_class(Pytest);BeforeEach、BeforeAll(JUnit) 测试用例前的准备动作,比如读取数据或者driver的初始化
用例步骤 测试方法内的代码逻辑 测试用例具体的步骤行为
预期结果 assert 实际结果 = 预期结果 断言,印证用例是否执行成功
实际结果 assert 实际结果 = 预期结果 断言,印证用例是否执行成功
后置动作 teardown、teardown_class(Pytest);@AfterEach、@AfterAll(JUnit) 脏数据清理、关闭进程

二、录制脚本分析

  • 脚本步骤:

    1. 访问搜狗网站
    2. 搜索框输入"霍格沃兹测试开发"
    3. 点击搜索按钮
python 复制代码
class Test():
  def setup_method(self, method):
    self.driver = webdriver.Chrome()
    self.vars = {}
  
  def teardown_method(self, method):
    self.driver.quit()
  
  def test_sougou(self):
    # 打开网页,设置窗口
    self.driver.get("https://www.sogou.com/")
    self.driver.set_window_size(1235, 693)
    # 输入搜索信息
    self.driver.find_element(By.ID, "query").click()
    self.driver.find_element(By.ID, "query").send_keys("霍格沃兹测试开发")
    # 点击搜索
    self.driver.find_element(By.ID, "stb").click()

三、录制脚本优化

  • 添加隐式等待
  • 添加断言
python 复制代码
class Test():
    def setup_method(self, method):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(3)
        # self.vars = {}

    def teardown_method(self, method):
        self.driver.quit()

    def test_sougou(self):
        # 打开网页,设置窗口
        self.driver.get("https://www.sogou.com/")
        self.driver.set_window_size(1235, 693)
        # 输入搜索信息
        # self.driver.find_element(By.ID, "query").click()
        self.driver.find_element(By.ID, "query").send_keys("霍格沃兹测试开发")
        # 点击搜索
        self.driver.find_element(By.ID, "stb").click()
        # element = self.driver.find_element(By.ID, "stb")
        # actions = ActionChains(self.driver)
        # actions.move_to_element(element).perform()
        time.sleep(5)
        # 添加断言
        fond_element = self.driver.find_element(By.ID, "sogou_vr_30000000_0")
        assert "霍格沃兹测试开发" in fond_element.text
相关推荐
一个java开发23 分钟前
distributed.client.Client 用户可调用函数分析
大数据·python
eqwaak034 分钟前
Matplotlib 动态显示详解:技术深度与创新思考
网络·python·网络协议·tcp/ip·语言模型·matplotlib
007php0071 小时前
某大厂MySQL面试之SQL注入触点发现与SQLMap测试
数据库·python·sql·mysql·面试·职场和发展·golang
CodeCraft Studio1 小时前
Excel处理控件Aspose.Cells教程:使用 Python 将 Pandas DataFrame 转换为 Excel
python·json·excel·pandas·csv·aspose·dataframe
flashlight_hi1 小时前
LeetCode 分类刷题:2563. 统计公平数对的数目
python·算法·leetcode
java1234_小锋1 小时前
Scikit-learn Python机器学习 - 特征预处理 - 归一化 (Normalization):MinMaxScaler
python·机器学习·scikit-learn
星空的资源小屋1 小时前
网易UU远程,免费电脑远程控制软件
人工智能·python·pdf·电脑
IMER SIMPLE1 小时前
人工智能-python-深度学习-神经网络-MobileNet V1&V2
人工智能·python·深度学习
eleqi2 小时前
Python+DRVT 从外部调用 Revit:批量创建楼板
python·系统集成·revit·外部调用·drvt·自动化生产流水线
咖啡Beans2 小时前
Python工具DrissionPage推荐
后端·python