zoukankan      html  css  js  c++  java
  • 电商系统自动测试脚本

    一、背景介绍

      在电商系统中,功能点众多、流程负责,在每次迭代都需要大量的测试工作,这时候自动化测试就尤为重要了。Javashop团队经过多年的经验积累,将内部采用的自动化的方案在这里贡献给大家,希望能够帮助到有需要的同学。

    二、环境及软件信息

    1. python 3

    2. selenium 3.13.0

    3. chromedriver

    4. HTMLTestRunner

    selenium只需要再python环境下使用pip install 名称即可进行对应的安装。 安装完成后可使用pip list查看自己的安装列表信息。

    chromedriver:版本需和自己的chrome浏览器对应, 作用:对chrome浏览器进行驱动。

    三、项目结构

    项目主要包括以下几个部分

     四、测试示例

     1 import unittest
     2 import logging
     3 from common.Common import Common, DriverUtil, TipGetter
     4 
     5 class MemberRecyclebinTestCase(unittest.TestCase):
     6 
     7 def setUp(self):
     8 self.driver = DriverUtil.getDriver()
     9 
    10 def testMemberRecyclebin(self):
    11 
    12 try:
    13             common = Common(self.driver)
    14             user = Common.loadDefaultData("admin")
    15             common.adminLogin(user["username"], user["pwd"], "1111")
    16             common.sleep()
    17 # 点击会员回收站
    18             common.driver.find_element_by_xpath(
    19 u"(.//*[normalize-space(text()) and normalize-space(.)='投诉主题'])[1]/following::span[1]").click()
    20             common.sleep()
    21             common.driver.find_element_by_xpath(
    22 u"(.//*[normalize-space(text()) and normalize-space(.)='会员管理'])[1]/following::div[2]").click()
    23             common.sleep()
    24             recycle_bin = common.driver.find_element_by_xpath(
    25 u"(.//*[normalize-space(text()) and normalize-space(.)='会员列表'])[1]/following::span[1]").text
    26 self.assertIn('会员回收站', recycle_bin)
    27             common.sleep()
    28 except Exception as e:
    29             Common.screen()
    30             Common.exceptionHanelder(self, e)
    31 
    32 def tearDown(self):
    33         DriverUtil.quitDriver()
    34 if __name__ == '__main__':
    35     unittest.main()

    测试用例中的相关说明:

    1. 每个测试函数运行前运行

    2. teardown():每个测试函数运行完后执行

    3. self.driver = DriverUtil.getDriver ():加载浏览器驱动

    4. Common.screen(): 截取异常图片

     五、使用HTMLTestRunner执行测试用例,并生成测试报告。

     1 sys.path.append(os.path.dirname(__file__))
     2 
     3 import unittest, time
     4 from common.HTMLTestRunner import HTMLTestRunner
     5 from common.newReport import new_report
     6 
     7 # 用例目录
     8 CASE_DIR = "case"
     9 
    10 # 报告目录
    11 REPORT_DIR = "report"
    12 
    13 
    14 def add_case():
    15 # 加载所有的测试用例
    16     discover = unittest.defaultTestLoader.discover(CASE_DIR, pattern='*.py')
    17 return discover
    18 
    19 
    20 def run_case(all_case):
    21 # 执行所有的测试用例
    22     now = time.strftime("%Y-%m-%d-%H_%M_%S")
    23     filename = 'report/' + now + 'result.html'
    24     fp = open(filename, 'wb')
    25     runner = HTMLTestRunner(stream=fp, title='Javashop-管理端自动化测试报告',
    26                             description='环境:mac 浏览器:chrome')
    27     runner.run(all_case)
    28     fp.close()
    29     new_report("report")  # 调用模块生成最新的报告
    30 
    31 
    32 if __name__ == "__main__":
    33     cases = add_case()
    34     run_case(cases)

    易族智汇(javashop)原创文章 

  • 相关阅读:
    执行truncate引发ORA-02266的问题分析
    一文搞懂MySQL-8.0 redo优化
    写给迷茫中的大一大二的学弟学妹,学渣逆袭中的个人经历与心得
    99+好友共同关注,公众号推荐
    Cesium
    Cesium
    Cesium
    Cesium
    虚拟化学习笔记-KVM虚拟化跨机迁移原理
    虚拟化学习笔记-KVM虚拟化跨机迁移原理
  • 原文地址:https://www.cnblogs.com/javashop-docs/p/14365775.html
Copyright © 2011-2022 走看看