Bugfree外挂开发

发表于:2014-9-05 11:22

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:心如明镜    来源:51Testing软件测试网采编

  通过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;
}
41/41234>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号