The most complete, HttpRunner interface automated testing - data-driven combat, advanced advanced testing


foreword

C1

Scenario 1: use case set + independent parameters + parameter list

Original use case file savePatient_01.yml

-   config:
        name: 患者管理-新增患者
        request:
            base_url: 'http://192.168.14.76:8080'
            headers:
                User-Agent: null
        variables: []
-   test:
        name: /myinfo/pinyin4j/converterToFirstSpell
        request:
            method: GET
            params:
                detail: '{"body":{"synCode":"","content":{},"param":{"name":"施耐庵"},"code":{}},"header":{"v":"v_pc_1.0.3.24","doctorMainId":"ff80808162bc9a2f0162f1c2322627ab","clinicId":"8a9a9c745f9b87c3015fdcc1e36b4271","type":"4","imei":"661D-6DF1-B196-3DFE-DE7D-3A01-3AA1-471F","userToken":"20180803105231387f8ueqor"}}'
            url: http://192.168.14.76:8080/myinfo/pinyin4j/converterToFirstSpell
        validate:
        -   eq:
            - status_code
            - 200
        -   eq:
            - headers.Content-Type
            - text/html;charset=UTF-8

Analysis:
need parameterized data, patient name name.

Steps:
In the config module, configure the data name that needs to be parameterized as a global parameter, and use the list assignment.

parameters:
- name: ["杜甫", "曹雪芹", "施耐庵"]

Where name is referenced in the test request, replace ${name} with parameters

params:
                detail: '{"body":{"synCode":"","content":{},"param":{"name":"$name"},"code":{}},"header":{"v":"v_pc_1.0.3.24","doctorMainId":"ff80808162bc9a2f0162f1c2322627ab","clinicId":"8a9a9c745f9b87c3015fdcc1e36b4271","type":"4","imei":"661D-6DF1-B196-3DFE-DE7D-3A01-3AA1-471F","userToken":"20180803105231387f8ueqor"}}'

If there is a place in the assertion that needs to verify the name, replace it

validate:
        -   eq:
            - status_code
            - 200
        -   eq:
            - content.body.code
            - "0000"
        -   eq:
            - content.body.param.name
            - $name

All code examples:

-   config:
        name: 患者管理-新增患者
        request:
            base_url: 'http://192.168.14.76:8080'
            headers:
                User-Agent: null
        variables: []
        parameters:
        - name: ["杜甫", "曹雪芹", "施耐庵"]
-   test:
        name: /myinfo/pinyin4j/converterToFirstSpell
        request:
            method: GET
            params:
                detail: '{"body":{"synCode":"","content":{},"param":{"name":"$name"},"code":{}},"header":{"v":"v_pc_1.0.3.24","doctorMainId":"ff80808162bc9a2f0162f1c2322627ab","clinicId":"8a9a9c745f9b87c3015fdcc1e36b4271","type":"4","imei":"661D-6DF1-B196-3DFE-DE7D-3A01-3AA1-471F","userToken":"20180803105231387f8ueqor"}}'
            url: http://192.168.14.76:8080/myinfo/pinyin4j/converterToFirstSpell
        validate:
        -   eq:
            - status_code
            - 200
        -   eq:
            - content.body.code
            - "0000"
        -   eq:
            - content.body.param.name
            - $name

Scenario 2. Use case set + associated parameters + parameter list

Find the information that needs to be parameterized
Name-abbreviation-date of birth-gender

Configuration parameters in config

parameters:
            - userName-userShortName-birthday-sex:
                - ["李白","LB","1988-09-09",1]
                - ["白居易","BJY","1978-05-09",1]
                - ["杜牧","DM","1998-03-09",1]

Substitution parameter

request:
            method: GET
            params:
                detail: '{"body":{"synCode":"","content":{},"param":{"id":"9cc01ecefb784f03bfcc5a87c3ad6a71","userName":"$userName","userShortName":"$userShortName","birthday":"$birthday","sex":$sex,"phone":"18911572511","isDelete":0,"illHistory":"","allergicHistory":"","address":"","homeAddress":"","base_version":"","totalArrears":"0","clinicId":"","doctorId":"","idCardNo":"","agency":"","folk":"","validitytime":"","fingerPrint":"0","deviceType":"0","diagnose":"","patientSource":""},"code":{}},"header":{"v":"v_pc_1.0.3.24","doctorMainId":"ff80808162bc9a2f0162f1c2322627ab","clinicId":"8a9a9c745f9b87c3015fdcc1e36b4271","type":"4","imei":"661D-6DF1-B196-3DFE-DE7D-3A01-3AA1-471F","userToken":"20180803105231387f8ueqor"}}'
            url: http://192.168.14.76:8080/patient/clinicPatient/savePatientFromPad

Optimizing Assertions

validate:
        -   eq:
            - status_code
            - 200
        -   eq:
            - content.body.code
            - "0000"
        -   eq:
            - content.body.param.userName
            - $userName

full code

-   config:
        name: 患者管理-新增患者
        parameters:
            - userName-userShortName-birthday-sex:
                - ["李白","LB","1988-09-09",1]
                - ["白居易","BJY","1978-05-09",1]
                - ["杜牧","DM","1998-03-09",1]
        request:
            base_url: 'http://192.168.14.76:8080'
            headers:
                User-Agent: null
        variables: []


-   test:
        name: /patient/clinicPatient/savePatientFromPad
        request:
            method: GET
            params:
                detail: '{"body":{"synCode":"","content":{},"param":{"id":"9cc01ecefb784f03bfcc5a87c3ad6a71","userName":"$userName","userShortName":"$userShortName","birthday":"$birthday","sex":$sex,"phone":"18911572511","isDelete":0,"illHistory":"","allergicHistory":"","address":"","homeAddress":"","base_version":"","totalArrears":"0","clinicId":"","doctorId":"","idCardNo":"","agency":"","folk":"","validitytime":"","fingerPrint":"0","deviceType":"0","diagnose":"","patientSource":""},"code":{}},"header":{"v":"v_pc_1.0.3.24","doctorMainId":"ff80808162bc9a2f0162f1c2322627ab","clinicId":"8a9a9c745f9b87c3015fdcc1e36b4271","type":"4","imei":"661D-6DF1-B196-3DFE-DE7D-3A01-3AA1-471F","userToken":"20180803105231387f8ueqor"}}'
            url: http://192.168.14.76:8080/patient/clinicPatient/savePatientFromPad
        validate:
        -   eq:
            - status_code
            - 200
        -   eq:
            - content.body.code
            - "0000"
        -   eq:
            - content.body.param.userName
            - $userName

Scenario 3: Use Case Set + Associated Parameters + CSV File

Special Note:
For CSV data files, the following agreed rules need to be followed:

The file needs to be placed in the same directory as the test case file;
the first line in the CSV file must be the parameter name, and the second line must be the parameter value, and each (group) value occupies one line; if there are multiple parameters in the same CSV file, the
separator between the parameter name and the value must be a comma.
How to contain Chinese in the file, it needs to be saved in UTF-8 format

Steps:
Create a new CSV file, name it patientInfo.csv, and encode it in UTF-8

userName,userShortName,birthday,sex
莫言,MY,2011-01-09,1
吴佩慈,WPC,1996-09-08,2

In the config module, configuration parameters

parameters:
            - userName-userShortName-birthday-sex: ${
    
    P(patientInfo.csv)}

In the test module, replace the parameter

request:
            method: GET
            params:
                detail: '{"body":{"synCode":"","content":{},"param":{"id":"9cc01ecefb784f03bfcc5a87c3ad6a71","userName":"$userName","userShortName":"$userShortName","birthday":"$birthday","sex":$sex,"phone":"18911572511","isDelete":0,"illHistory":"","allergicHistory":"","address":"","homeAddress":"","base_version":"","totalArrears":"0","clinicId":"","doctorId":"","idCardNo":"","agency":"","folk":"","validitytime":"","fingerPrint":"0","deviceType":"0","diagnose":"","patientSource":""},"code":{}},"header":{"v":"v_pc_1.0.3.24","doctorMainId":"ff80808162bc9a2f0162f1c2322627ab","clinicId":"8a9a9c745f9b87c3015fdcc1e36b4271","type":"4","imei":"661D-6DF1-B196-3DFE-DE7D-3A01-3AA1-471F","userToken":"20180803105231387f8ueqor"}}'
            url: http://192.168.14.76:8080/patient/clinicPatient/savePatientFromPad

complete code example

-   config:
        name: 患者管理-新增患者
        parameters:
            - userName-userShortName-birthday-sex: ${
    
    P(patientInfo.csv)}

        request:
            base_url: 'http://192.168.14.76:8080'
            headers:
                User-Agent: null
        variables: []


-   test:
        name: /patient/clinicPatient/savePatientFromPad
        request:
            method: GET
            params:
                detail: '{"body":{"synCode":"","content":{},"param":{"id":"9cc01ecefb784f03bfcc5a87c3ad6a71","userName":"$userName","userShortName":"$userShortName","birthday":"$birthday","sex":$sex,"phone":"18911572511","isDelete":0,"illHistory":"","allergicHistory":"","address":"","homeAddress":"","base_version":"","totalArrears":"0","clinicId":"","doctorId":"","idCardNo":"","agency":"","folk":"","validitytime":"","fingerPrint":"0","deviceType":"0","diagnose":"","patientSource":""},"code":{}},"header":{"v":"v_pc_1.0.3.24","doctorMainId":"ff80808162bc9a2f0162f1c2322627ab","clinicId":"8a9a9c745f9b87c3015fdcc1e36b4271","type":"4","imei":"661D-6DF1-B196-3DFE-DE7D-3A01-3AA1-471F","userToken":"20180803105231387f8ueqor"}}'
            url: http://192.168.14.76:8080/patient/clinicPatient/savePatientFromPad
        validate:
        -   eq:
            - status_code
            - 200
        -   eq:
            - content.body.code
            - "0000"
        -   eq:
            - content.body.param.userName
            - $userName

Scenario 4: Use Case + Associated Parameters + CSV File

In scenario 3, the parameter configuration in config can be moved to the test module

C2

Scenario 5. Use case set + associated parameters + custom function generation list

Special attention: It should be noted that in the custom function, the generated parameter list must be a data structure of list of dict. This design is mainly to be consistent with the processing mechanism of CSV files.

Define the function get_patient_info in debugtalk.py to generate a specified number of parameter lists.

def get_patient_info(num):
    patients = []
    for index in range(1, num+1):
        patients.append(
            {
    
    "userName": gen_random_name(), "sex": gen_random_sex(),"birthday":gen_random_date()},
        )

    return patients

Among them: gen_random_name(), gen_random_sex(), gen_random_date() are the methods defined above

Then in the parameters of YAML/JSON, you can call a custom function to generate a specified number of parameter lists.

parameters:
	- userName-sex-birthday-sex: ${
    
    get_patient_info(3)}
The following is the most complete software test engineer learning knowledge architecture system diagram in 2023 that I compiled

1. From entry to mastery of Python programming

Please add a picture description

2. Interface automation project actual combat

Please add a picture description

3. Actual Combat of Web Automation Project

Please add a picture description

4. Actual Combat of App Automation Project

Please add a picture description

5. Resume of first-tier manufacturers

Please add a picture description

6. Test and develop DevOps system

Please add a picture description

7. Commonly used automated testing tools

Please add a picture description

Eight, JMeter performance test

Please add a picture description

9. Summary (little surprise at the end)

Only a firm dream in our hearts can keep us from getting tired on the way forward. In the journey of life, don't forget your original intention and don't give up your dreams. Only by persevering and constantly catching up can you walk out of a brilliant and wonderful life.

Don't give up, don't give up, only keep fighting hard can make your dreams come true. No matter how far and how difficult the journey is, you must persist in pursuing it, because unremitting dedication is the key to the ultimate achievement, and let the light of struggle illuminate the way forward.

No matter how difficult the front is, no matter how bad the environment is, as long as we ignite the flame of hope in our hearts and are willing to persevere in struggle, we will be able to overcome difficulties and create our own brilliance. Believe in your own strength, go forward bravely, and the future will become better because of your efforts.

Guess you like

Origin blog.csdn.net/x2waiwai/article/details/131724950