ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

学习httprunner记录03

2020-06-24 19:03:45  阅读:315  来源: 互联网

标签:03 httprunner 记录 equal Accept assert html zentao


使用httprunner3.x版本

python版本是3.6

测试环境是zen dao

以下为脚本:

# NOTE: Generated By HttpRunner v3.1.0
# FROM: assign_me.har
import re
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase


class TestCaseAssignMe(HttpRunner):
    config = (
        Config("testcase description")
        .verify(False)
        .variables(**{})
        .base_url("http://192.168.75.175")
    )

    teststeps = [

        Step(
            RunRequest("login with username and password")
                .post("/zentao/user-login.html")
                .with_headers(
                **{
                    "Accept": "application/json, text/javascript, */*; q=0.01",
                    "X-Requested-With": "XMLHttpRequest",
                    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
                    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                    "Referer": "http://192.168.75.175/zentao/user-login.html",
                    "Accept-Encoding": "gzip, deflate",
                    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,lb;q=0.7"

                }
            )
                .with_data(
                {
                    "account": "admin",
                    "password": "qazwsx123",
                    "referer": "/zentao/",
                    "keepLogin": "1",
                }
            ).validate()
                .assert_equal("status_code", 200)
                .assert_equal('headers."Content-Type"', "text/html; Language=UTF-8;charset=UTF-8")
                .assert_equal('body.result', 'success')
        )
        ,

        Step(
            RunRequest("check bugs that are assigned to me")
            .get("/zentao/bug-browse-1-0-assigntome.html")
            .with_headers(
                **{
                    "Host": "192.168.75.175",
                    "Upgrade-Insecure-Requests": "1",
                    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
                    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                    "Referer": "http://192.168.75.175/zentao/bug-browse-1-0-unclosed.html",
                    "Accept-Encoding": "gzip, deflate",
                    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,lb;q=0.7",
                    "Pragma": "no-cache",
                    "Cache-Control": "no-cache",
                }
            ).validate()
            .assert_equal("status_code", 200)
            .assert_equal(
                'headers."Content-Type"', "text/html; Language=UTF-8;charset=UTF-8"
            )
            .assert_contains('body', "data-id='6'".encode('utf-8'))
        ),
    ]


if __name__ == "__main__":
    TestCaseAssignMe().test_start()

1  采用charles录制,导出

 

2 使用har2case 将har文件转换为python脚本,如上;

 

3 修正脚本,主要是去除不需要的部分,修改断言部分,参数化url部分

与手写pytest的区别:

最主要的一点是:

httprunner的作者设定为接口调用返回的都是json格式的数据,所以httprunner的断言函数都是依据此假设封装的

这一点对我不适用

 

手写pytest脚本的话完全不受此限制,可以方便的结合re模块从html中提取信息做断言

但是httprunner录制脚本然后转换的做法,生成脚本的速度确实是非常快

 

 

 

 

 

 

 

 

 

 

 

 

  

标签:03,httprunner,记录,equal,Accept,assert,html,zentao
来源: https://www.cnblogs.com/luke8919/p/13189272.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有