Skip to content

thingsBoard设备管理接口文档

环境说明


题目说明

  • 测试方法:请使用所学的测试用例设计方法例如等价类、边界值等方法完成 web 自动化和接口自动化测试
  • 场景说明见下方业务流程
  • 断言方式:根据不同业务,断言返回结果是否正确

自动化场景

  • 功能模块:设备
  • 测试点:对设备的增、删、改、查

业务流程-添加设备

@startuml
scale 1000
学生 -> thingsboard: 登录
thingsboard -> 设备: 点击
设备 -> 添加新设备: 点击加号
添加新设备 -> 名称: 必填
添加新设备 -> 标签: 选填
添加新设备 -> 设备配置: 默认
添加新设备 -> 新建设备配置: 默认
添加新设备 -> 是否网关: 默认
添加新设备 -> 说明: 选填
添加新设备 -> 添加: 点击添加
添加新设备 -> 断言: 根据创建的设备搜索进行断言
@enduml

业务流程-查询设备

@startuml
scale 1000
学生 -> thingsboard: 登录
thingsboard -> 设备: 点击
设备 -> 查找设备: 点击搜索按钮
查找设备 -> 查询: 输入要查询的设备名称
查询 -> 展示查询结果
展示查询结果 -> 断言: 根据填写的字段进行断言
@enduml

业务流程-修改设备

@startuml
scale 1000
学生 -> thingsboard: 登录
thingsboard -> 设备: 点击
设备 -> 目标设备: 搜索设备名称
目标设备-> 设备详情页: 点击
设备详情页-> 编辑模式: 点击切换编辑模式
编辑模式 -> 名称: 更新
编辑模式 -> 设备配置: 默认
编辑模式 -> 标签: 更新
编辑模式 -> 分配的固件: 默认
编辑模式 -> 分配的软件: 默认
编辑模式 -> 是否网关: 默认
编辑模式 -> 说明: 更新
编辑模式 -> 应用更改: 点击
应用更改 -> 设备详情页: 自动返回
设备详情页 -> 返回列表页: 关闭详情页
返回列表页 -> 断言: 搜索设备
@enduml

业务流程-删除设备

@startuml
scale 1000
学生 -> thingsboard: 登录
thingsboard -> 设备: 点击
设备 -> 目标设备: 搜索设备名称
目标设备 -> 删除: 点击删除
删除 -> 返回列表页: 是否删除
返回列表页 -> 断言: 搜索设备
@enduml

场景

  • 登录
  • 新增设备
  • 查询设备
  • 修改设备
  • 删除设备

登录-获取token

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/auth/login

  • 请求方式:post

  • 请求参数:{"username": username,"password": password}

  • 接口返回:

{
  'token': 'eyJhbGciOiJIUzUxMiJ9',  # 使用此token进行登录
  'refreshToken': 'r6U6RfH3Hc_Tj8QGEx7xVr4Nmckg',
  'scope': None
}

业务流程-创建设备

@startuml
scale 1000
学生 -> 登录: /api/auth/login
登录 -> 学生: 获取token
学生 -> 创建设备: /api/device
创建设备 -> 断言: 根据响应结果进行断言
@enduml

创建设备-请求示例

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/device

  • 请求方式为:post

  • 请求头:{"X-Authorization": Bearer token}

  • 示例:登录接口返回token为:xxxxxx,则请求头为:{"X-Authorization": Bearer xxxxxx}


{
  "name": "hogwarts",  // 名称
  "label": "hogwarts_tag",  // 标签
  "deviceProfileId": {
    "entityType": "DEVICE_PROFILE",   // 默认值
    "id": "eec576e0-eca9-11ed-b839-b910c19eb442"  // 默认值
  },
  "additionalInfo": {
    "gateway": "false",  // 默认值
    "overwriteActivityTime": "false",  // 默认值
    "description": "霍格沃兹测试开发学社"  // 说明
  },
}            

创建设备-响应结果

{
  'id': {
    'entityType': 'DEVICE',
    'id': '177cfd40-f62a-11ed-afdc-53eb80421d86'
  },
  'createdTime': 1684484670888,
  'additionalInfo': {
    'gateway': 'false',
    'overwriteActivityTime': 'false',
    'description': '测试选项'
  },
  'tenantId': {
    'entityType': 'TENANT',
    'id': '0ebd8110-e578-11ed-854b-71497f176d4c'
  },
  'customerId': {
    'entityType': 'CUSTOMER',
    'id': '13814000-1dd2-11b2-8080-808080808080'
  },
  'name': 'hogwarts_test',
  'type': '孤孤咕咕咕',
  'label': 'hogwarts_tag',
  'deviceProfileId': {
    'entityType': 'DEVICE_PROFILE',
    'id': 'eec576e0-eca9-11ed-b839-b910c19eb442'
  },
  'deviceData': {
    'configuration': {
      'type': 'DEFAULT'
    },
    'transportConfiguration': {
      'type': 'DEFAULT'
    }
  },
  'firmwareId': None,
  'softwareId': None,
  'externalId': None
}

注意 'id': '177cfd40-f62a-11ed-afdc-53eb80421d86' 为创建设备返回的id,具体id根据自己调用创建接口返回的id为准


业务流程-查询设备

@startuml
scale 1000
学生 -> 登录: /api/auth/login
登录 -> 学生: 获取token
学生 -> 查询设备: /api/tenant/devices?deviceName=<设备名称>
查询设备 -> 断言: 根据响应结果进行断言
@enduml

查询设备-请求示例

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/tenant/devices
  • 请求方式为:get
  • 请求参数:deviceName为创建设备的名字
  • 示例:设备名称为hogwarts,则请求的url为:https://thingsboard.stu.hogwarts.ceshiren.com/api/tenant/devices?deviceName=hogwarts

  • 请求头:{"X-Authorization": Bearer token}

  • 示例:登录接口返回token为:xxxxxx,则请求头为:{"X-Authorization": Bearer xxxxxx}


查询设备-响应结果

{
  'id': {
    'entityType': 'DEVICE',
    'id': '177cfd40-f62a-11ed-afdc-53eb80421d86'
  },
  'createdTime': 1684484670888,
  'additionalInfo': {
    'gateway': 'false',
    'overwriteActivityTime': 'false',
    'description': '第四届火焰杯决赛测试选项'
  },
  'tenantId': {
    'entityType': 'TENANT',
    'id': '0ebd8110-e578-11ed-854b-71497f176d4c'
  },
  'customerId': {
    'entityType': 'CUSTOMER',
    'id': '13814000-1dd2-11b2-8080-808080808080'
  },
  'name': 'hogwarts_test',
  'type': '孤孤咕咕咕',
  'label': 'hogwarts_tag',
  'deviceProfileId': {
    'entityType': 'DEVICE_PROFILE',
    'id': 'eec576e0-eca9-11ed-b839-b910c19eb442'
  },
  'deviceData': {
    'configuration': {
      'type': 'DEFAULT'
    },
    'transportConfiguration': {
      'type': 'DEFAULT'
    }
  },
  'firmwareId': None,
  'softwareId': None,
  'externalId': None
}

业务流程-修改设备

@startuml
scale 1000
学生 -> 登录: /api/auth/login
登录 -> 学生: 获取token
学生 -> 修改设备: /api/device
修改设备 -> 断言: 根据响应结果进行断言(断言修改的内容)
@enduml

修改设备-请求示例

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/device

  • 请求方式为:post

  • 请求头:{"X-Authorization": Bearer token}

  • 示例:登录接口返回token为:xxxxxx,则请求头为:{"X-Authorization": Bearer xxxxxx}

  • 请求参数:

{
  'id': {
    'entityType': 'DEVICE',
    'id': '177cfd40-f62a-11ed-afdc-53eb80421d86'  // 要修改的设备id,即创建接口返回的设备id
  },
  "name": "hogwarts2",  // 要修改的设备名称
  "label": "hogwarts_tag2", // 要修改的设备标签
  "deviceProfileId": {
    "entityType": "DEVICE_PROFILE", // 默认
    "id": "eec576e0-eca9-11ed-b839-b910c19eb442" // 默认
  },
  "additionalInfo": {
    "gateway": "false", // 默认
    "overwriteActivityTime": "false", // 默认
    "description": "hogwarts" // 要修改的描述
  },

}

修改设备-响应结果

{
  'id': {
    'entityType': 'DEVICE',
    'id': '5b4b83f0-f622-11ed-afdd-53eb80421d86'
  },
  'createdTime': 0,
  'additionalInfo': {
    'gateway': 'false',
    'overwriteActivityTime': 'false',
    'description': '第四届火焰杯决赛2'
  },
  'tenantId': {
    'entityType': 'TENANT',
    'id': '0ebd8110-e578-11ed-854b-71497f176d4c'
  },
  'customerId': {
    'entityType': 'CUSTOMER',
    'id': '13814000-1dd2-11b2-8080-808080808080'
  },
  'name': 'hogwarts2',
  'type': '孤孤咕咕咕',
  'label': 'hogwarts_tag2',
  'deviceProfileId': {
    'entityType': 'DEVICE_PROFILE',
    'id': 'eec576e0-eca9-11ed-b839-b910c19eb442'
  },
  'deviceData': {
    'configuration': {
      'type': 'DEFAULT'
    },
    'transportConfiguration': {
      'type': 'DEFAULT'
    }
  },
  'firmwareId': None,
  'softwareId': None,
  'externalId': None
}

业务流程-删除设备

@startuml
scale 1000
学生 -> 登录: /api/auth/login
登录 -> 学生: 获取token
学生 -> 删除设备: api/device/<device_id>
删除设备 -> 断言: 根据响应结果进行断言
@enduml

删除设备-请求示例

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/device/<device_id>

  • 示例:设备id为xxxx,则请求的url为:https://thingsboard.stu.hogwarts.ceshiren.com/api/device/xxxx

  • 请求方式为:delete

  • 请求头:{"X-Authorization": Bearer token}

  • 示例:登录接口返回token为:xxxxxx,则请求头为:{"X-Authorization": Bearer xxxxxx}


删除设备-响应结果

  • 接口响应状态码为:200代表删除成功