diff --git a/docs/examples/test_klook/README.md b/docs/examples/test_klook/README.md new file mode 100644 index 00000000..80c07e3a --- /dev/null +++ b/docs/examples/test_klook/README.md @@ -0,0 +1,22 @@ +## 案例介绍 +我们团队在调研接口测试框架的时候选了httprunner,[让我](https://github.com/readyou)来负责给大家做一次分享,于是有了这里的示例。 + +## 注意事项 +1. 本例子中有些地方用到了`localhost:8085`作为base_url,这些接口是不能访问的,仅仅作为示例学习怎样组织测试用例。 +2. `https://maps.googleapis.com`是可以用的,自己申请一个key,替换掉文件中的`your_google_map_key`即可。 + +## 相关文件说明 +模块 | 文件 | 用途 | 备注 +---|----|------|------ +google map 接口测试 | api/find_place_api.yml | google map根据名称搜索地址的api | 比较全面地使用了api可以使用的关键字:name, base_url, request, variables, validate, extract +google map 接口测试 | testcases/find_place_testcase.yml | google map根据名称搜索地址的testcase | 使用了testcase标准的写法:testcase由teststep组成,teststep中引用api(just_request_testcase.yml中演示了直接使用request而不是引用api的方式)。teststep中还使用了variables。 +google map 接口测试 | testcases/place_detail_testcase.yml | google map获取地址详情的testcase | config中使用variables +google map 接口测试 | testsuites/place_detail_testsuite.yml | google map接口测试的testsuite包含上面两个testcase | 使用了多种方式来做数据驱动测试 + | | +klook地理位置搜索接口测试 | api/search_area_by_name_api.yml | 根据名字查询区域(支持多语言)——api | +klook地理位置搜索接口测试 | api/search_area_by_name_testcase.yml | 根据名字查询区域(支持多语言)——testcase | +klook地理位置搜索接口测试 | api/get_area_groups_api.yml | 查询地理位置下面的组——api | +klook地理位置搜索接口测试 | api/get_area_groups_testcase.yml | 查询地理位置下面的组——testcase | +klook地理位置搜索接口测试 | api/area_manage_testsuite.yml | 区域管理——testsuite | + | | +baidu首页demo | testcases/just_request_testcase.yml | 提取百度首页title的demo | 演示了直接使用request而不是引用api的方式,使用了teardown_hooks的使用 \ No newline at end of file diff --git a/docs/examples/test_klook/__init__.py b/docs/examples/test_klook/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/docs/examples/test_klook/api/find_place_api.yml b/docs/examples/test_klook/api/find_place_api.yml new file mode 100644 index 00000000..394def72 --- /dev/null +++ b/docs/examples/test_klook/api/find_place_api.yml @@ -0,0 +1,19 @@ +name: find place from text +base_url: https://maps.googleapis.com +request: + method: GET + url: /maps/api/place/findplacefromtext/json + params: + key: $key + inputtype: textquery + input: $input + fields: 'formatted_address,geometry,name,permanently_closed,place_id,plus_code,types' + language: zh_CN +variables: + input: 宝安 + key: your_google_map_key +validate: + - eq: [status_code, 200] + - eq: [content.status, OK] +extract: + - place_id: content.candidates.0.place_id diff --git a/docs/examples/test_klook/api/get_area_groups_api.yml b/docs/examples/test_klook/api/get_area_groups_api.yml new file mode 100644 index 00000000..44b66ef5 --- /dev/null +++ b/docs/examples/test_klook/api/get_area_groups_api.yml @@ -0,0 +1,11 @@ +name: get_groups +base_url: http://localhost:8085 +request: + url: /v1/transferairportadminsrv/area/getGroups + method: POST + headers: + Content-Type: application/x-www-form-urlencoded + Accept-language: zh_CN + cookie: $admin_cookie + data: + parentAreaId: 7037 # 广东省 diff --git a/docs/examples/test_klook/api/place_detail_api.yml b/docs/examples/test_klook/api/place_detail_api.yml new file mode 100644 index 00000000..158a867b --- /dev/null +++ b/docs/examples/test_klook/api/place_detail_api.yml @@ -0,0 +1,17 @@ +name: get place detail +request: + method: GET + url: https://maps.googleapis.com/maps/api/place/details/json + params: + key: $key + placeid: $place_id + fields: 'address_component,formatted_address,geometry' + language: zh-CN +variables: + key: your_google_map_key + place_id: ChIJzyoujG6SAzQRRD3Jr26PFfM +validate: + - eq: [status_code, 200] + - eq: [content.status, OK] +extract: + - place_name: content.result.formatted_address diff --git a/docs/examples/test_klook/api/search_area_by_name_api.yml b/docs/examples/test_klook/api/search_area_by_name_api.yml new file mode 100644 index 00000000..fe04bb06 --- /dev/null +++ b/docs/examples/test_klook/api/search_area_by_name_api.yml @@ -0,0 +1,11 @@ +name: search_area_by_name +base_url: http://localhost:8085 +request: + url: /v1/transferairportadminsrv/area/search_area_by_name + method: GET + headers: + Content-Type: application/x-www-form-urlencoded + Accept-language: zh_CN + cookie: $admin_cookie + params: + areaName: $in diff --git a/docs/examples/test_klook/data/place_detail.csv b/docs/examples/test_klook/data/place_detail.csv new file mode 100644 index 00000000..863c196c --- /dev/null +++ b/docs/examples/test_klook/data/place_detail.csv @@ -0,0 +1,3 @@ +input,formatted_address,address_components_len +娄底,中国湖南省娄底市,3 +新化,中国湖南省娄底市新化县,4 \ No newline at end of file diff --git a/docs/examples/test_klook/debugtalk.py b/docs/examples/test_klook/debugtalk.py new file mode 100644 index 00000000..7c2e552a --- /dev/null +++ b/docs/examples/test_klook/debugtalk.py @@ -0,0 +1,11 @@ +from utils.validators.validators_of_area import * +from utils.validators.validators_of_common import * +from utils.setup_hooks import * +from utils.teardown_hooks import * + +__all__ = [ + klook_len_eq, + check_search_area_result, + exists_default_group, + teardown_hook_set_encoding +] diff --git a/docs/examples/test_klook/testcases/find_place_testcase.yml b/docs/examples/test_klook/testcases/find_place_testcase.yml new file mode 100644 index 00000000..339cc90b --- /dev/null +++ b/docs/examples/test_klook/testcases/find_place_testcase.yml @@ -0,0 +1,19 @@ +name: find place from text testcase +config: + base_url: https://maps.googleapis.com + # config 这里的variables优先级更高 + # 如果本testcase被其他testcase引用,variables无法覆盖这里配置的值 + # variables: + # input: 福田 + # formatted_address: 中国广东省深圳市福田区 +teststeps: + - name: find place + api: api/find_place_api.yml + # 如果config上面配置了,这里的同名变量会被覆盖 + variables: + input: 深圳 + formatted_address: 中国广东省深圳市 + validate: + - eq: [content.candidates.0.formatted_address, $formatted_address] + extract: + - formatted_address: formatted_address"\s?:\s?"(.*)" \ No newline at end of file diff --git a/docs/examples/test_klook/testcases/get_area_groups_testcase.yml b/docs/examples/test_klook/testcases/get_area_groups_testcase.yml new file mode 100644 index 00000000..43e414ca --- /dev/null +++ b/docs/examples/test_klook/testcases/get_area_groups_testcase.yml @@ -0,0 +1,13 @@ +config: + base_url: http://127.0.0.1:8085 + variables: + admin_cookie: 'cookies' + +teststeps: + - name: get group by parent area id + api: api/get_area_groups_api.yml + validate: + - eq: [status_code, 200] + - eq: [headers.Content-Type, application/json] + - eq: [content.success, true] + - exists_default_group: [content.result, ''] diff --git a/docs/examples/test_klook/testcases/just_request_testcase.yml b/docs/examples/test_klook/testcases/just_request_testcase.yml new file mode 100644 index 00000000..98a5ec85 --- /dev/null +++ b/docs/examples/test_klook/testcases/just_request_testcase.yml @@ -0,0 +1,9 @@ +teststeps: + - name: extract title + request: + method: GET + url: http://www.baidu.com + extract: + - title: