Python 如何正确的获取到对应用例的目录信息

Time · 2023年01月06日 · 最后由 Time 回复于 2023年01月06日 · 5072 次阅读

定义用例优先级前的块为用例的目录,如下图所示
第一个用例目录是:testcase-template.xlsx-充电桩测试 - 通信模块测试 - 心跳测试
第二个用例目录是:testcase-template.xlsx-充电桩测试 - 通信模块测试 - 控制直连测试
第三个用例目录是:testcase-template.xlsx-充电桩测试 - 传呼模块测试 - 设备测试
用例目前只有最高到四层,如果更多层怎么保证获取到的目录是正确的

JSON 数据格式如下:

{"root": {
    "data": {"created": 1666753139902, "text": "testcase-template.xlsx", "id": "c9fca96a-f4ca-4c73-8d89-6b63784b85e8"},
    "children": [{"data": {"created": 1666753139963, "text": "充电桩测试", "id": "3db7fe92-8fc7-4c70-b2ca-ecdf70f2f5b3"},
                  "children": [{"data": {"created": 1666753139963, "text": "通信模块测试",
                                         "id": "1d77eac3-4029-4761-9eee-9bad06b2ec79"}, "children": [{"data": {
                      "created": 1666753139964, "text": "心跳测试", "id": "4d3d471e-cfee-4b7d-ad65-f6cd94512d2d",
                      "expandState": "expand"}, "children": [{"data": {
                      "note": "创建人: tester1\n用例描述: 充电桩与上层云平台心跳为5s,测试功能\n备注: \n用例是否自动化自动化: 否\n用例关联接口: \n用例测试类型: 功能测试\n用例关联项目: 充电桩一期\n",
                      "resource": ["心跳"], "created": 1666753139964, "text": "心跳时长测试",
                      "id": "02728e92-0ad8-44c1-9fc4-87d52e2daf35", "priority": 1}, "children": [{"data": {
                      "resource": ["前置条件"], "created": 1666753139964, "text": "充电桩与云平台建立连接",
                      "id": "65813894-fb87-462e-97b5-b9b3be814724"}, "children": [{"data": {"resource": ["执行步骤"],
                                                                                            "created": 1666753139964,
                                                                                            "text": "1.云平台发起心跳,有预期结果1",
                                                                                            "id": "61d4ad36-df7e-4fcf-bf8e-cb5a2fe8fe77",
                                                                                            "expandState": "expand"},
                                                                                   "children": [{"data": {
                                                                                       "id": "f7111115-3282-44b2-baf7-29c088fea495",
                                                                                       "created": 1666753139964,
                                                                                       "resource": ["预期结果"],
                                                                                       "text": "1.充电桩1s内返回响应"},
                                                                                       "children": []}]}, {
                                                                                      "data": {"id": "cpj8wpoy7iw0",
                                                                                               "created": 1672819178746,
                                                                                               "text": "2.充电桩发起心跳,有预期结果2",
                                                                                               "resource": ["执行步骤"]},
                                                                                      "children": [{"data": {
                                                                                          "id": "cpj8wz4u9ls0",
                                                                                          "created": 1672819199298,
                                                                                          "text": "2.云平台2s内返回响应",
                                                                                          "resource": ["预期结果"]},
                                                                                          "children": []}]}]},
                      {"data": {
                          "id": "cpj944ucgm00",
                          "created": 1672819760273,
                          "text": "充电前置条件2",
                          "expandState": "expand",
                          "resource": [
                              "前置条件"]},
                          "children": [{
                              "data": {
                                  "id": "cpj8x6no50g0",
                                  "created": 1672819215674,
                                  "text": "3.充电桩发起心跳,有预期结果2",
                                  "resource": [
                                      "执行步骤"]},
                              "children": [
                                  {
                                      "data": {
                                          "id": "cpj8xff7pcw0",
                                          "created": 1672819234753,
                                          "text": "3.云平台3s内返回响应",
                                          "resource": [
                                              "预期结果"]},
                                      "children": []}]}]}]}]},
                      {"data": {
                          "created": 1666753139964,
                          "text": "控制直连测试",
                          "id": "1ff3276a-1d6e-437b-a285-e643bf8a6fc4"},
                          "children": [{
                              "data": {
                                  "note": "创建人: tester2\n用例描述: \n备注: 关注101指令数据\n用例是否自动化自动化: 是\n用例关联接口: /api/charge\n用例测试类型: 可靠性测试\n用例关联项目: 充电桩三期\n",
                                  "resource": [
                                      "充电",
                                      "通信"],
                                  "created": 1666753139964,
                                  "text": "启动充电功能测试",
                                  "id": "8e7e7164-32d3-4f99-955d-4a74bed28032",
                                  "priority": 2},
                              "children": [
                                  {
                                      "data": {
                                          "resource": [
                                              "前置条件"],
                                          "created": 1666753139964,
                                          "text": "充电桩与云平台建立连接",
                                          "id": "516803bb-ad71-4e9a-b2fc-c1bba61d8cc4"},
                                      "children": [
                                          {
                                              "data": {
                                                  "resource": [
                                                      "执行步骤"],
                                                  "created": 1666753139964,
                                                  "text": "1.充电桩启动充电,有预期结果1",
                                                  "id": "12779ceb-bbb2-4f09-8cd3-5985563cc053"},
                                              "children": [
                                                  {
                                                      "data": {
                                                          "resource": [
                                                              "预期结果"],
                                                          "created": 1666753139964,
                                                          "text": "1.充电成功,开始计费",
                                                          "id": "6a3115f5-ac97-4df0-8903-96042906b270"},
                                                      "children": []}]},
                                          {
                                              "data": {
                                                  "id": "cpj8xunme8o0",
                                                  "created": 1672819267913,
                                                  "text": "2.充电桩启动充电,有预期结果2",
                                                  "resource": [
                                                      "执行步骤"]},
                                              "children": [
                                                  {
                                                      "data": {
                                                          "id": "cpj8y1sabkw0",
                                                          "created": 1672819283433,
                                                          "text": "2.充电失败,不计费",
                                                          "resource": [
                                                              "预期结果"]},
                                                      "children": []}]}]}]}]}]},
                               {"data": {"id": "cpjafnmqt7k0", "created": 1672823484288, "text": "传呼模块测试"},
                                "children": [{"data": {"id": "cpjag2og9sw0", "created": 1672823517043, "text": "设备测试"},
                                              "children": [{"data": {"id": "cpjaggd5sog0", "created": 1672823546835,
                                                                     "text": "顶部分层", "priority": 1}, "children": [{
                                                  "data": {
                                                      "id": "cpjai6ahjls0",
                                                      "created": 1672823681634,
                                                      "text": "步骤",
                                                      "resource": [
                                                          "执行步骤"]},
                                                  "children": [
                                                      {
                                                          "data": {
                                                              "id": "cpjaiduwveg0",
                                                              "created": 1672823698106,
                                                              "text": "结果",
                                                              "resource": [
                                                                  "预期结果"]},
                                                          "children": []}]}]}]}]}]}]},
    "template": "right", "theme": "fresh-blue", "version": "1.4.43", "base": 64}
共收到 1 条回复 时间 点赞
Time #2 · 2023年01月06日 Author

已解决,代码之前写的位置放的有点问题导致遍历错误

Time 关闭了讨论 01月06日 18:13
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册