Bugfree外挂开发
作者:网络转载 发布时间:[ 2014/9/5 14:46:20 ] 推荐标签:软件测试 测试管理工具
通过java模拟浏览器行为,对bugfree系统进行操作。譬如:通过bug id,查询bug的信息;查询产品族;查询满足特定条件的bug列表;批量更新bug的状态;上报bug到bugfree系统等。
package com.yunos.qa;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
public class BugfreeOperator {
private static final String API_KEY = "";
private static final String bugfreeUrl = "http://bugfree-external.aliyun-inc.com/bugfree/api3.php";
private String sessionId;
private SessionInfo sessionInfo;
public BugfreeOperator() {
}
private SessionInfo getSessionInfo() {
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl, "mode=getsid");
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return null;
}
SessionInfo sessionInfo = JsonParser.parseSessionInfo(jsonResult);
System.out.println("sessionId: " + sessionInfo.getSessionId());
System.out.println("rand: " + sessionInfo.getRand());
return sessionInfo;
}
/**
*
* 认证码。
#加密算法:
$auth = md5(md5($username.md5($password)).API_KEY.$rand)
其中$username为用户名,$password为该用户的明文密码,$rand为getsid方法获得的rand值。
* @param userName
* @param password
* @return
*/
public boolean login(String userName, String password) {
sessionInfo = getSessionInfo();
if (sessionInfo == null) {
return false;
}
String md5 = MD5.getMD5(password.getBytes());
System.out.println("md5: " + md5);
md5 = userName + md5;
md5 = MD5.getMD5(md5.getBytes());
md5 = md5 + API_KEY + sessionInfo.getRand();
String auth = MD5.getMD5(md5.getBytes());
Map<String, String> params = new HashMap<String, String>();
params.put("mode", "login");
params.put(sessionInfo.getSessionName(), sessionInfo.getSessionId());
params.put("username", userName);
params.put("auth", auth);
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl, params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return false;
}
System.out.println("jsonResult: " + jsonResult);
return JsonParser.parseLoginResult(jsonResult);
}
public void findProducts() {
if (sessionInfo == null) {
return;
}
Map<String, String> params = new HashMap<String, String>();
params.put("mode", "findproducts");
params.put(sessionInfo.getSessionName(), sessionInfo.getSessionId());
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl, params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return;
}
System.out.println("[findProducts] jsonResult: " + jsonResult);
return;
}
public void getBug(int id) {
if (sessionInfo == null) {
return;
}
Map<String, String> params = new HashMap<String, String>();
params.put("mode", "getbug");
params.put(sessionInfo.getSessionName(), sessionInfo.getSessionId());
params.put("id", Integer.toString(id));
String jsonResult = null;
InputStream is = null;
try {
is = doPost(bugfreeUrl, params);
jsonResult = getResult(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (jsonResult == null) {
return;
}
System.out.println("[getBug] jsonResult: " + jsonResult);
return;
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11