码迷,mamicode.com
首页 > Web开发 > 详细

学习httprunner记录01

时间:2020-06-23 19:33:51      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:orm   exchange   浏览器   sign   hang   传递   type   测试   pass   

python 3.6版本

使用 pipenv构建的虚拟化环境

 

安装指导遵从官方文档https://docs.httprunner.org/quickstart/

测试环境:在vmware中安装centos7,然后在centos7安装禅道软件

步骤:

1 打开charles,作为proxy

2 使用浏览器访问禅道,包括登录和退出

3 将charles中的对应步骤导出为har格式,存储在本地login.har

4 使用har2case将login.har转换为python脚本,转换结果如下:(做了一点点注释和手动修改)

 

# NOTE: Generated By HttpRunner v3.1.0
# FROM: test_zendao.har

from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase


class TestCaseTestZendao(HttpRunner):
    config = Config("testcase description").verify(False)

    teststeps = [
        Step(
            RunRequest("test login with username and password")
            .post("http://192.168.75.175/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"
            )
        ),
        Step(
            RunRequest("test logout")
            .get("http://192.168.75.175/zentao/user-logout.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/my/",
                    "Accept-Encoding": "gzip, deflate",
                    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,lb;q=0.7"

                }
            )
            .validate()
            .assert_equal("status_code", 200)
            .assert_equal(
                ‘headers."Content-Type"‘, "text/html; Language=UTF-8;charset=UTF-8"
            )
        ),
        # Step(
        #     RunRequest("test reload the login page")
        #     .get("http://192.168.75.175/zentao/user-login.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/my/",
        #             "Accept-Encoding": "gzip, deflate",
        #             "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,lb;q=0.7"
        #         }
        #     )
        #     .validate()
        #     .assert_equal("status_code", 200)
        #     .assert_equal(
        #         ‘headers."Content-Type"‘, "text/html; Language=UTF-8;charset=UTF-8"
        #     )
        # ),
        # Step(
        #     RunRequest("/zentao/misc-checkUpdate-.html")
        #     .get("http://192.168.75.175/zentao/misc-checkUpdate-.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/user-login.html",
        #             "Accept-Encoding": "gzip, deflate",
        #             "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,lb;q=0.7"
        #         }
        #     )
        #     .validate()
        #     .assert_equal("status_code", 200)
        #     .assert_equal(
        #         ‘headers."Content-Type"‘, "text/html; Language=UTF-8;charset=UTF-8"
        #     )
        # ),
    ]


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

5 运行hrun login_test.py

问题:

  感觉脚本的可读性还好,但是底层貌似使用了requests的session,所以cookies可以自动传递;

  参数化功能据说还在开发中

  根据官方文档,hrun是兼容于pytest的,即pytest login_test.py可行;如果能够完全兼容于pytest,则可借助于pytest强大的生态圈

 

学习httprunner记录01

标签:orm   exchange   浏览器   sign   hang   传递   type   测试   pass   

原文地址:https://www.cnblogs.com/luke8919/p/13183658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!