前提:bug记录为JIRA
自动化脚本跑完后,如果发现问题,再用手工把问题录入jira,这样是不是觉得自动化做得还不够彻底?下面讲的是如何联通jira。
首先测试用例中需要带有开发名称和测试人员名称(对应jira内的名称)。
测试结果数据和人员名称聚合。
如果有重试机制,重试完成最后再统一录入jira。
jira有开放的api,分两种:
com.atlassian.jira jira-api ${atlassian.product.version} provided
2 . rest api — 通过网络调用,地址:https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-group-issues
调用jira前需要获取token
使用 java包时需要先调用auth 获取token
使用api时,首先要获取authentication,它支持 OAuth2.0 这里可以用简单的basic auth 通过鉴权,这种方式可以直接调用所需的接口,不需要再次获取token,如果jira配置不支持这种鉴权方式,就需要在jira中配置token 官网地址:。https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/#Tokens-de-API
basic auth 使用:
curl -D- -X GET -H “Authorization: Basic ZnJlZDpmcmVk” -H “Content-Type: application/json” “https://your-domain.atlassian.net/rest/api/2/issue/QA-31”
第三行 basic 后的字符串是,用户名:密码的base64字符。
有的网络使用统一的登录授权方式,对于这种,使用java包的话需要重写 authentication的头信息,把获取的token代入进去。而调用rest api的方式同样要在请求头加入统一系统的token。
说下新建bug
jira新建bug,也就是 issue的 接口地址:POST /rest/api/2/issue
请求格式:
{ “update”: { “worklog”: [ { “add”: { “timeSpent”: “60m”, “started”: “2019-07-05T11:05:00.000+0000” } } ] }, “fields”: { “summary”: “Main order flow broken”, “parent”: { “key”: “PROJ-123” }, “issuetype”: { “id”: “10000” }, “components”: [ { “id”: “10000” } ], “customfield_20000”: “06/Jul/19 3:25 PM”, “customfield_40000”: “Occurs on all orders”, “customfield_70000”: [ “jira-administrators”, “jira-software-users” ], “project”: { “id”: “10000” }, “description”: “Order entry fails when selecting supplier.”, “reporter”: { “id”: “5b10a2844c20165700ede21g” }, “fixVersions”: [ { “id”: “10001” } ], “customfield_10000”: “09/Jun/19”, “priority”: { “id”: “20000” }, “labels”: [ “bugfix”, “blitz_test” ], “timetracking”: { “remainingEstimate”: “5”, “originalEstimate”: “10” }, “customfield_30000”: [ “10000”, “10002” ], “customfield_80000”: { “value”: “red” }, “security”: { “id”: “10000” }, “environment”: “UAT”, “versions”: [ { “id”: “10000” } ], “duedate”: “2019-03-11”, “customfield_60000”: “jira-software-users”, “customfield_50000”: “Could impact day-to-day work.”, “assignee”: { “id”: “5b109f2e9729b51b54dc274d” } }}// 涉及到的id 可以在脚本中做个名称和id的字典方便匹配//reporter 是报告人,一般对应测试人员的id//assignee 是之给谁,一般是开发人员//customfield_xxxx 字段是jira设置的自定义字段//建立后回应如下:{ “id”: “10000”, “key”: “ED-24”, “self”: “https://your-domain.atlassian.net/rest/api/2/issue/10000”, “transition”: { “status”: 200, “errorCollection”: { “errorMessages”: [], “errors”: {} } }}
把相应的 id 收集后,自动发送邮件,邮件中用 上方selft的地址把id逐个拼起来就是bug的浏览地址,方便人员点击查看。
bug的修改,删除请求用法见地址:https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-group-issues
jira大部分查询用的Jql 语法,使用方法:
例如
var bodyData = `{ “queries”: [ “summary ~ test AND (labels in (urgent, blocker) OR lastCommentedBy = currentUser()) AND status CHANGED AFTER startOfMonth(-1M) ORDER BY updated DESC”, “invalid query”, “summary = test”, “summary in test”, “project = INVALID”, “universe = 42” ]}`;const response = await api.asApp().requestJira(route`/rest/api/2/jql/parse`, { method: ‘POST’, headers: { ‘Accept’: ‘application/json’, ‘Content-Type’: ‘application/json’ }, body: bodyData});console.log(`Response: ${response.status} ${response.statusText}`);console.log(await response.json());//“AND (labels in (urgent, blocker) OR lastCommentedBy = currentUser()) AND status CHANGED AFTER startOfMonth(-1M) ORDER BY updated DESC ” //上一行这部分条件可以在jira网页地址中调试成功再写入代码。
除了上面这些,还能做些什么?
- 使用查询可以获取项目的issue数量,人员数量,类别,从而可以自定义报表,分析软件哪部分缺陷多,缺陷类型是哪些
- 多项目中共有字段可以通过脚本一键同步建立
- 定时更新issue或项目状态,发布进度提醒