我有一个与Zephyr相关的查询,我如何通过rest API使用测试用例ID来更新测试用例的执行状态以通过/失败/WIP
我已经参考了下面链接中的文章https://support.getzephyr.com/hc/en-us/articles/205042055-Sample-REST-API-Update-execution-status-of-a-testcase-JAVA-
在本例中,他们展示了如何使用调度ID更新执行状态,但实现是在SOAP中的,我们需要使用REST API实现同样的功能。是否有任何直接的REST API来获取计划ID
另外,是否有直接的REST API来使用测试用例ID更新测试用例的执行状态?如果是,您能否提供上述两种情况的示例?
提前感谢。
Jira REST API中没有使用测试用例ID更新执行状态的直接方法。但是,您可以使用以下自定义方法:
import java.util.HashMap;
import java.util.Map;
import org.apache.http.client.methods.HttpPost;
import org.apache.commons.io.IOUtils;
import org.codehaus.jettison.json.JSONObject;
import java.net.Proxy;
import java.net.HttpURLConnection;
import java.net.URL;
public class JiraAuthHeader {
public static void main(String args[])
{
try {
JiraAuthHeader jiraAuthHeaderObj= new JiraAuthHeader();
System.out.println(" Create Execution method*********");
int executionId= jiraAuthHeaderObj.createExecution(<project id>,<issue id>,<cycle id>);
System.out.println(" Update Execution method*********");
jiraAuthHeaderObj.updateExecution(executionId,"pass");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String updateExecution(int executionId, String status) throws Exception {
System.out.println("Executing execution with executionId " + executionId + " and status = " + status);
String url = "https://jira.company.com/jira/rest/zapi/latest/execution/" + executionId + "/execute";
//String url = "https://jira.company.com/jira/rest/zapi/latest/execution";
String statusInReq = "";
if (status.equalsIgnoreCase("pass")) {
statusInReq = "1";
} else if (status.equalsIgnoreCase("fail")) {
statusInReq = "2";
}
// Create request body
JSONObject obj = new JSONObject();
obj.put("status", statusInReq);
obj.put("comment", "through java");
String requestBody = obj.toString();
System.out.println("Request body: " + requestBody);
HttpURLConnection conn
= httpPut(url, null, null, obj.toString());
System.out.println("HTTP response code: " + conn.getResponseCode());
String response = getResponse(conn);
System.out.println("HTTP response content: " + response);
System.out.println("from HTTP response content fetch the execution id: " + response.substring(6, 12));
return response;
}
public HttpURLConnection httpGet(String url, Map<String, String> requestHeaders, String queryString) throws Exception {
System.out.println("Get request");
if (queryString != null) {
url += "?" + queryString;
}
if (requestHeaders == null) {
requestHeaders = new HashMap<String, String>();
}
requestHeaders.put("Content-Type", "application/json");
return openConnection(url, "GET", requestHeaders, null);
}
public HttpURLConnection httpPut(String url, Map<String, String> requestHeaders, String queryString, String requestContent) throws Exception {
System.out.println("Put request");
if (queryString != null) {
url += "?" + queryString;
}
System.out.println(url);
if (requestHeaders == null) {
requestHeaders = new HashMap<String, String>();
}
requestHeaders.put("Content-Type", "application/json");
return openConnection(url, "PUT", requestHeaders, requestContent);
}
public HttpURLConnection httpPost(String url, Map<String, String> requestHeaders, String queryString, String requestContent) throws Exception {
System.out.println("Post request");
if (queryString != null) {
url += "?" + queryString;
}
System.out.println(url);
if (requestHeaders == null) {
requestHeaders = new HashMap<String, String>();
}
requestHeaders.put("Content-Type", "application/json");
return openConnection(url, "POST", requestHeaders, requestContent);
}
private HttpURLConnection openConnection(String url, String requestMethod, Map<String, String> requestHeaders, String requestContent)
throws Exception {
boolean usingProxy = false;
HttpURLConnection conn = null;
if (usingProxy) {
/*String[] proxyInfo = jiraIntegrationConfig.getProxyServer().split(":");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyInfo[0], Integer.valueOf(proxyInfo[1])));
conn = (HttpURLConnection) new URL(url).openConnection(proxy);*/
} else {
conn = (HttpURLConnection) new URL(url).openConnection(Proxy.NO_PROXY);
String auth = "ssing621" + ":" + "amex^123";
auth = "Basic " + new String(new sun.misc.BASE64Encoder().encode(auth.getBytes()));
conn.setRequestProperty("Authorization", auth);
conn.setRequestMethod(requestMethod);
if (requestHeaders != null && requestHeaders.size() > 0) {
for (String key : requestHeaders.keySet()) {
conn.setRequestProperty(key, requestHeaders.get(key));
}
}
if (requestContent != null) {
conn.setDoOutput(true);
conn.getOutputStream().write(requestContent.getBytes("UTF-8"));
}
}
return conn;
}
private String getResponse(HttpURLConnection conn) throws Exception {
String response;
if (conn.getResponseCode() == 200 || conn.getResponseCode() == 201) {
response = IOUtils.toString(conn.getInputStream());
return response;
} else {
response = IOUtils.toString(conn.getErrorStream());
throw new Exception(response);
}
}
public int getIssueIdByKey(String issueKey) throws Exception {
System.out.println("Getting issue ID for test: [" + issueKey + "]");
String url = ("https://jira.company.com/jira/rest/api/2/issue/" + issueKey);
HttpURLConnection conn = httpGet(url, null, null);
String response = getResponse(conn);
JSONObject resObj = new JSONObject(response);
if (resObj.has("id")) {
int issueId = resObj.getInt("id");
System.out.println("Found issue ID: " + issueId);
return issueId;
}
System.out.println("Could not find IssueId for test: [" + issueKey + "]");
return 0;
}
public int createExecution(int projectId, int issueId, int cycleId) throws Exception {
System.out.print("Creating execution for project Id " + projectId + " and issueId " + issueId);
String url = ("https://jira.company.com/jira/rest/zapi/latest/execution");
// Create request body
JSONObject reqObj = new JSONObject();
reqObj.put("issueId", issueId);
reqObj.put("projectId", projectId);
reqObj.put("cycleId", cycleId);
String requestBody = reqObj.toString();
System.out.println("Request body: " + requestBody);
HttpURLConnection conn = httpPost(url, null, null, requestBody);
System.out.println("HTTP response code: " + conn.getResponseCode());
String response = getResponse(conn);
System.out.println("HTTP response content: " + response);
// Parse the Execution Id, and return it
JSONObject resObj = new JSONObject(response);
int executionId = Integer.valueOf(resObj.keys().next().toString());
System.out.println("Creation done, execution ID: " + executionId);
return executionId;
}
}
我已经将Selenium代码与jenkins集成在一起,通过以下步骤执行测试用例: https://wiki.jenkins.io/display/JENKINS/ZephyrJira测试管理插件 现在,我必须根据项目结构讲述我的测试用例。示例:PackageName。类名。MethodName不是正确的方法。 请告诉我是否有任何其他方法可以使用Test ID识别测试用例
我能够使用CURL命令在JIRA中创建一个票证,并且手头有一个json数据。 curl-D--u:-X POST--data@ 我现在正试图更新生成的票证的状态,但出现以下错误<代码>{“errorMessages”:[],“errors”:{“status”:“无法设置字段‘status’。它不在适当的屏幕上,或未知。”} 卷曲命令: 旋度-D--u
问题内容: 我是python和jango rest的新手。但是我很困惑。在Django Rest框架中更新多对多关系的最佳方法是什么。我阅读了文档 http://www.django-rest-framework.org/api-guide/relations/#manytomanyfields- with-a-through-model 默认情况下,设置了以指定的贯通模型为目标的ManyToMa
🍭 大家好这里是清隆学长 ,一枚热爱算法的程序员 ✨ 本系列打算持续跟新华为OD-D卷的三语言AC题解 👏 感谢大家的订阅➕ 和 喜欢💗 📎在线评测链接 => LYA的测试用例执行计划(100分) <= 🌍 评测功能需要 =>订阅专栏<= 后联系清隆解锁~ 🍓OJ题目截图 🎀 LYA的测试用例执行计划 问题描述 LYA是一名软件测试工程师,她需要为当前迭代周期内的 个特性 设计测试用
问题内容: 我有一个表“测试”,具有自动递增和任意数量的列。 我想在此表中复制一行,当然所有的列都相同。 有没有一种方法可以不命名所有列? 我以为会对我有所帮助,直到我意识到它永远不会产生,它只会更新现有行。 问题答案: 假设您的表格包含以下字段: 然后,要将具有新键值的值从一行复制到另一行,以下查询可能会有所帮助 这将产生一个新的价值领域和值复制,并选定行的。 您可以扩展此示例以在表中申请更多字