2023Python自动化测试5种模型(建议收藏)_python 关键字驱动

(1)Python所有方向的学习路线(新版)

这是我花了几天的时间去把Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。

最近我才对这些路线做了一下新的更新,知识体系更全面了。

在这里插入图片描述

(2)Python学习视频

包含了Python入门、爬虫、数据分析和web开发的学习视频,总共100多个,虽然没有那么全面,但是对于入门来说是没问题的,学完这些之后,你可以按照我上面的学习路线去网上找其他的知识资源进行进阶。

在这里插入图片描述

(3)100多个练手项目

我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了,只是里面的项目比较多,水平也是参差不齐,大家可以挑自己能做的项目去练练。

在这里插入图片描述

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

    self.kw.send_keys(data)
    time.sleep(1)
    self.su.click()

(4)runner 存放运行脚本。


例如 main.py



#!/usr/bin/env python

-- coding: utf-8 --

import os
import time
import unittest
from AutomatedTestModel.ModularDriverModel.utils.HwTestReport import HTMLTestReport

class Main:
def get_all_case(self):
current_path = os.path.abspath(os.path.dirname(file))
case_path = current_path + ‘/…/case/’
discover = unittest.defaultTestLoader.discover(case_path, pattern=“test*.py”)
print(discover)
return discover

def set_report(self, all_case, report_path=None):
    if report_path is None:
        current_path = os.path.abspath(os.path.dirname(__file__))
        report_path = current_path + '/../../report/'
    else:
        report_path = report_path

    # 获取当前时间
    now = time.strftime('%Y{y}%m{m}%d{d}%H{h}%M{M}%S{s}').format(y="年", m="月", d="日", h="时", M="分", s="秒")
    # 标题
    title = u"搜索测试"
    # 设置报告存放路径和命名
    report_abspath = os.path.join(report_path, title + now + ".html")
    # 测试报告写入
    with open(report_abspath, 'wb') as report:
        runner = HTMLTestReport(stream=report,
                                verbosity=2,
                                images=True,
                                title=title,
                                tester='Meng')
        runner.run(all_case)

def run_case(self, report_path=None):
    all_case = self.get_all_case()
    self.set_report(all_case, report_path)

if name == ‘main’:
Main().run_case()


### 6、utils 存放公共方法。


例如导出报告样式、读取配置文件等。


![](https://img-blog.csdnimg.cn/img_convert/3bc2e4c3552f0b2a0c39f7f182e27044.png)


### 7、run.py 运行脚本。



#!/usr/bin/env python

-- coding: utf-8 --

软件测试

from AutomatedTestModel.ModularDriverModel.test.runner.main import Main

if name == ‘main’:
Main().run_case()


**运行后的测试报告。**


![](https://img-blog.csdnimg.cn/img_convert/f7ece1118cc5351c5e75612d760da551.png)


### 4、数据驱动模型


该模型会根据数据的变化而引起测试结果的改变,这显然是一个非常高级的概念和想法。简单地说,该模型是一种数据的参数化呈现,即通过输入不同的参数来驱动程序执行,输出不同的测试结果。


框架目录:


![](https://img-blog.csdnimg.cn/img_convert/bc17305aed1a79162aec8da09cfa1b46.png)


1、case 存放测试用例步骤。


![](https://img-blog.csdnimg.cn/img_convert/db1e8a3900780903e4ff8eca9a79aac4.png)



![](https://img-blog.csdnimg.cn/img_convert/c9fe875b4ec8e5bd6d14014f39ea77e9.png)


2、common 存放公共的方法等。


如读取 Excel 方法、生成报告等样式。


![](https://img-blog.csdnimg.cn/img_convert/6953de70d09774e64adcdb1cf6b5262c.png)


3、data 存放测试数据与预期结果。


![](https://img-blog.csdnimg.cn/img_convert/6b0737df4b886d25318504aae32cd708.png)


![](https://img-blog.csdnimg.cn/img_convert/567ac194366475f56a720ec927831c3c.png)


4、report 存放执行完成后的测试报告。


打开报告效果。


![](https://img-blog.csdnimg.cn/img_convert/942cd20e2ae6e1c01fb21f10b9c8f84f.png)


5、RunMain.py 运行脚本。



#!/usr/bin/env python

-- coding: utf-8 --

import os, time, unittest
from AutomatedTestModel.DataDrivenModeling.common.HwTestReport import HTMLTestReport

class RunMain:
def get_all_case(self):
case_path = os.getcwd()
discover = unittest.defaultTestLoader.discover(case_path,
pattern=“Test*.py”)
print(discover)
return discover

def set_report(self, all_case, report_path=None):
    if report_path is None:
        current_path = os.path.abspath(os.path.dirname(__file__))
        report_path = current_path + '/report/'
    else:
        report_path = report_path

    # 获取当前时间
    now = time.strftime('%Y{y}%m{m}%d{d}%H{h}%M{M}%S{s}').format(y="年", m="月", d="日", h="时", M="分", s="秒")
    # 标题
    title = u"搜索测试"
    # 设置报告存放路径和命名
    report_abspath = os.path.join(report_path, title + now + ".html")
    # 测试报告写入
    with open(report_abspath, 'wb') as report:
        runner = HTMLTestReport(stream=report,
                                verbosity=2,
                                images=True,
                                title=title,
                                tester='Meng')
        runner.run(all_case)

def run_case(self, report_path=None):
    all_case = self.get_all_case()
    self.set_report(all_case, report_path)

if name == “main”:
RunMain().run_case()


### 5、关键字驱动模型


这是一种通过关键字的改变而引起测试结果改变的功能自动化测试模型。QTP(UFT)、Robot Framework 等都是以关键字驱动为主的自动化测试工具,这类工具典型的特征就是具备一套易用的可视化界面,测试人员需要做的就是将测试脚本按照“填表格”的方式填入,并考虑三个问题就可以了:我要做什么?对谁做?怎么做?


框架目录:


![](https://img-blog.csdnimg.cn/img_convert/ebc92f1463c39680799fc343c6900b52.png)


1、action 主要存放动作事件、元素操作。


![](https://img-blog.csdnimg.cn/img_convert/9dfde5a24110d24ed35d4254f34f324c.png)


(1)Action.py



#!/usr/bin/env python

-- coding: utf-8 --

from AutomatedTestModel.KeywordDrivenModel.common.ExcelUtil import ExcelUtil
from AutomatedTestModel.KeywordDrivenModel.action.ElementOperation import ElementOperation

class Action:
def init(self):
self.element = ElementOperation()

def set_value(self, element, action, parameter=None):
    if element == "browser":
        return self.element.browser_operate(action, parameter)
    elif element == "time":
        return self.element.time_operate(action, parameter)
    elif element is None or element == "":
        return
    else: # 如果不是其他的关键字,则默认为定位的元素
        return self.element.element_operate(element, action, parameter)

def case_operate(self, excel, sheet):
    all_case = ExcelUtil(excel_path=excel, sheet_name=sheet).get_case()
    for case in all_case:
        self.set_value(case[0], case[1], case[2])

if name == ‘main’:
excel = ‘…/case/casedata.xlsx’
Action().case_operate(excel=excel, sheet=‘搜索’)


(2)ElementOperation.py


![](https://img-blog.csdnimg.cn/img_convert/40a98f5d8226c4c4d73f202c6beb141f.png)


2、case 存放测试用例步骤。


![](https://img-blog.csdnimg.cn/img_convert/4a8e9f14a15c93be99cbc438cb6812d8.png)


![](https://img-blog.csdnimg.cn/img_convert/3171f6793dc0dad86d5beef4454b317b.png)


3、common 存放公共的方法等。


如读取 Excel 方法等。


![](https://img-blog.csdnimg.cn/img_convert/5809c77b78b1dc339c91dc34c95c5f3d.png)


4、RunMain.py 运行脚本。



#!/usr/bin/env python

-- coding: utf-8 --

from AutomatedTestModel.KeywordDrivenModel.action.Action import Action

if name == ‘main’:
excel = ‘case/casedata.xlsx’
a = Action().case_operate(excel=excel, sheet=‘搜索’)


6、行为驱动模型


行为驱动开发(Behave Driven Development,简称BDD),即从用户的需求出发强调系统行为。通过将BDD借鉴到自动化测试中,便产生了行为驱动测试模型,这种模型通过使用自然描述语言确定自动化测试脚本,其优点是可使用自然语言编写测试用例。


框架目录:


![](https://img-blog.csdnimg.cn/img_convert/602b749caffd9b356864f83523b517a2.png)


1、features 存放用例。


![](https://img-blog.csdnimg.cn/img_convert/e3a2e8f2b32c9e2225a73152cfc59ea5.png)


(1)steps 存放步骤



#!/usr/bin/env python

-- coding: utf-8 --

import time
from behave import *

@When(‘打开访问的网页 “{url}”’)
def step_open(context, url):
context.driver.get(url)
time.sleep(5)

@Then(‘进入百度网站成功’)
def step_assert_open(context):
title = context.driver.title
assert title == “百度一下,你就知道”

@When(‘输入 “{searchdata}”’)
def step_search(context, searchdata):
searchdata_element = context.driver.find_element_by_id(‘kw’)
searchdata_element.send_keys(searchdata)
time.sleep(1)
submit_btn = context.driver.find_element_by_id(‘su’)
submit_btn.click()

@Then(‘获取标题’)
def step_assert_search(context):
success_message = context.driver.title
assert success_message == “自动化测试_百度搜索”


(2)environment.py 存放变量


(3)search.feature 存放行为


![](https://img-blog.csdnimg.cn/img_convert/3169ef5f38f4e9c40985a158a012753c.png)


2、report、result 存放报告


![](https://img-blog.csdnimg.cn/img_convert/c4f66ac36991d768f769c7349bde7c18.png)


**最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:**


![](https://img-blog.csdnimg.cn/2765824078ba44249b8248688a5b8456.png)


这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!


![](https://img-blog.csdnimg.cn/4b3c99291d4342c3a399fc7d56d2d974.png)






### 最后

不知道你们用的什么环境,我一般都是用的Python3.6环境和pycharm解释器,没有软件,或者没有资料,没人解答问题,都可以免费领取(包括今天的代码),过几天我还会做个视频教程出来,有需要也可以领取~  

给大家准备的学习资料包括但不限于:  

Python 环境、pycharm编辑器/永久激活/翻译插件  

python 零基础视频教程  

Python 界面开发实战教程  

Python 爬虫实战教程  

Python 数据分析实战教程  

python 游戏开发实战教程  

Python 电子书100本  

Python 学习路线规划

![](https://img-blog.csdnimg.cn/d29631674929476f9c3b30f7ff58dff0.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ZlaTM0Nzc5NTc5MA==,size_16,color_FFFFFF,t_70)




**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化学习资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618317507)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 16
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值