前提:bug記錄為JIRA
自動化腳本跑完后,如果發現問題,再用手工把問題錄入jira,這樣是不是覺得自動化做得還不夠徹底?下面講的是如何聯通jira。
首先測試用例中需要帶有開發名稱和測試人員名稱(對應jira內的名稱)。
測試結果數據和人員名稱聚合。
如果有重試機制,重試完成最后再統一錄入jira。
jira有開放的api,分兩種:
- JAVA rest api --- 以java依賴包的方式調用 點擊查看:https://developer.atlassian.com/server/jira/platform/java-apis/,api doc: https://docs.atlassian.com/software/jira/docs/api/8.22.3/。pom添加如下
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${atlassian.product.version}</version>
<scope>provided</scope>
</dependency>
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或項目狀態,發布進度提醒