Commit 37625ec3 by yuecao

添加平板接口

parents
*.classpath
*.project
*.settings/
*.idea/
*.sonar/
*target/
bin/
*bin/
bin/
*.iml
*.bak
*test-output/
sublime-project
sublime-project.sublime-workspace
华沁智联接口自动化框架。
1.case层编写用例层。
2.dataProvider 测试case数据层。
3.service基础服务层。
\ No newline at end of file
imageLib/card.jpg

232 KB

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>FlatInterface</groupId>
<artifactId>FlatInterface</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>FlatInterface</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>mjitech</id>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-cache</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- 导入org.json包 -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!-- testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
<!-- 导入excel包 poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
</dependency>
<dependency>
<groupId>ojdbc</groupId>
<artifactId>ojdbc</artifactId>
<version>14</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!--
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
-->
<!-- json加密工具 -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- 增加StringBuiderWriter依赖 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>3.0</version>
</dependency>
<!-- 要用reportNG出报告,必须引入下面2个依赖 -->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.3</version>
</dependency>
<!-- okhttp -->
<!--
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.6.0</version>
</dependency>
-->
<!-- jdom -->
<!--
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1</version>
<type>pom</type>
</dependency>
-->
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
\ No newline at end of file
### \u8BBE\u7F6E###
log4j.rootLogger = debug,stdout,D,E
### \u8F93\u51FA\u4FE1\u606F\u5230\u63A7\u5236\u62AC ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
### \u8F93\u51FADEBUG \u7EA7\u522B\u4EE5\u4E0A\u7684\u65E5\u5FD7\u5230=D://logs/error.log ###
#log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
#log4j.appender.D.File = D://logs/log.log
#log4j.appender.D.Append = true
#log4j.appender.D.Threshold = DEBUG
#log4j.appender.D.layout = org.apache.log4j.PatternLayout
#log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### \u8F93\u51FAERROR \u7EA7\u522B\u4EE5\u4E0A\u7684\u65E5\u5FD7\u5230=D://logs/error.log ###
#log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
#log4j.appender.E.File =D://logs/error.log
#log4j.appender.E.Append = true
#log4j.appender.E.Threshold = ERROR
#log4j.appender.E.layout = org.apache.log4j.PatternLayout
#log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH\:mm\:ss} [ %t\:%r ] - [ %p ] %m%n
\ No newline at end of file
//package com.mjitech.qa.data;
//
//import org.testng.annotations.DataProvider;
//
///**
// * 数据层:数据与数据之间用“,”号分割,最后一个字段为接口状态字段,例如“OK”或“ERROR”
// *
// * @author android
// * @date 2018-05-17
// */
//public class MjitechData {
// // 无指定数据名称,默认用方法名
// @DataProvider
// public static Object[][] NoNameMethod() {
// return new Object[][] {};
// }
//
// /**
// * 按照名字进行检索数据
// */
// @DataProvider(name = "b_regist")
// public static Object[][] bRegistDataProvider() {
// return new Object[][] { { "PPS011509000000005", "", "ZC02050002" },
// { "6226090106597152", "007", "王五", "530101198512140018", 7385952L, "招商银行", "11", "11", "招商银行北京分行",
// "03080000", "308100005027", "13911708375", "成功" }, };
// }
//}
package com.mjitech.qa.service;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.json.JSONObject;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
/**
* http协议方法封装
*
* @author android
* @date 2018-05-17
**/
public class HttpMethod {
public BufferedReader getresult;
public BufferedReader postresult;
@SuppressWarnings("deprecation")
static HttpClient hc = new DefaultHttpClient();
static HttpResponse hr;
static HttpEntity entity;
StringBuilder strB = new StringBuilder();
JSONObject json = JSONObject.fromObject("{}");
String line;
List<NameValuePair> list = new ArrayList<NameValuePair>();
// get 请求 返回字符串
public String httpget(String url) throws ClientProtocolException, IOException {
HttpGet hg = new HttpGet(url);
hr = hc.execute(hg);
entity = hr.getEntity();
String rev = EntityUtils.toString(entity);
hg.abort();
return rev;
}
// get 请求 返回json字符串
public JSONObject httpgetReturnJson(String url) throws ClientProtocolException, IOException {
HttpGet hg = new HttpGet(url);
hr = hc.execute(hg);
entity = hr.getEntity();
String rev = EntityUtils.toString(entity);
hg.abort();
JSONObject json = null;
try {
json = JSONObject.fromObject(rev);
} catch (Exception e) {
json = new JSONObject();
System.out.println("返回不是json数据:" + rev);
}
return json;
}
// post 请求 返回字符串
public String httppost(String url, List<NameValuePair> nvps) throws ClientProtocolException, IOException {
HttpPost hp = new HttpPost(url);
hp.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
hr = hc.execute(hp);
entity = hr.getEntity();
BufferedReader postresult = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
// 清空 strb
strB.delete(0, strB.length());
line = null;
while ((line = postresult.readLine()) != null) {
strB.append(line);
}
hp.abort();
return strB.toString();
}
// post 请求 直接发送json串
public String httppostJson(String url, String json) throws ClientProtocolException, IOException {
HttpPost hp = new HttpPost(url);
StringEntity entity = new StringEntity(json, "utf-8");// 解决中文乱码问题
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
hp.setEntity(entity);
hr = hc.execute(hp);
// entity = hr.getEntity();
BufferedReader postresult = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
// 清空 strb
strB.delete(0, strB.length());
line = null;
while ((line = postresult.readLine()) != null) {
strB.append(line);
}
hp.abort();
return strB.toString();
}
// post 请求 返回json字符串
public JSONObject httppostReturnJson(String url, List<NameValuePair> nvps)
throws ClientProtocolException, IOException {
HttpPost hp = new HttpPost(url);
hp.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
hr = hc.execute(hp);
entity = hr.getEntity();
BufferedReader postresult = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
// 清空 strb
strB.delete(0, strB.length());
line = null;
while ((line = postresult.readLine()) != null) {
strB.append(line);
}
hp.abort();
JSONObject json = null;
try {
json = JSONObject.fromObject(strB.toString());
} catch (Exception e) {
json = new JSONObject();
System.out.println("返回不是json数据:" + strB.toString());
}
return json;
}
public List<NameValuePair> postParameter(JSONObject json) {
list.clear();
Iterator<String> keys = json.keys();
String key;
while (keys.hasNext()) {
key = keys.next();
list.add(new BasicNameValuePair(key, json.get(key).toString()));
}
return list;
}
// get 参数组装
public String getParameter(JSONObject json) {
Iterator<String> keys = json.keys();
String key;
strB.delete(0, strB.length());
while (keys.hasNext()) {
key = keys.next().toString();
strB.append("&" + key + "=" + json.get(key));
}
strB.replace(0, 1, "?");
return strB.toString();
}
// 将 json key 排序 组成新的json
public JSONObject sortJson(JSONObject json) {
JSONObject json2 = new JSONObject();
Iterator<String> keys = json.keys();
String key;
while (keys.hasNext()) {
}
return json2;
}
public void clearJson(JSONObject json) {
Iterator<String> keys = json.keys();
String key = null;
while (keys.hasNext()) {
key = keys.next().toString();
keys.remove();
}
}
public List<NameValuePair> postJsonParameter(String args[]) {
list.clear();
for (int i = 0; i < args.length; i++) {
list.add(new BasicNameValuePair(args[i].toString(), args[i].toString()));
}
return list;
}
// 参数sign加密
public String getSign(JSONObject json, String secret) throws Exception {
String strs = sort(json);
String strss = secret + strs + secret;
// System.out.println("md5加密前参数组合:"+strss);
String sign = Md5.byte2hex(Md5.md5(strss)); // md5加密并转换为大写
// System.out.println("md5 加密:" + sign);
return sign;
}
// 参数排序
public String sort(JSONObject json) throws Exception {
Iterator keys = json.keys();
String key;
StringBuffer sbf = new StringBuffer();
sbf.append("");
while (keys.hasNext()) {
key = keys.next().toString();
sbf.append(key + ",");
}
sbf.append("");
String str[] = sbf.toString().split(",");
Arrays.sort(str);
// 清空buf 重新装
sbf.delete(0, sbf.length());
for (int i = 0; i < str.length; i++) {
sbf.append("" + str[i] + "" + json.getString(str[i]));
}
return sbf.toString();
}
public JSONObject getjson(String url, List<NameValuePair> nvps) {
return json;
}
// 判断是否为数字
public boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
// 判断是否为手机号 1开头
public boolean isMobiles(String mobiles) {
Pattern p = Pattern.compile("1\\d{10}");
Matcher m = p.matcher(mobiles);
boolean b = m.matches();
return b;
}
}
package com.mjitech.qa.service;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
public class HttpPostUtil {
@SuppressWarnings("unused")
private static final String APPLICATION_JSON = "application/json";
@SuppressWarnings("unused")
private static final String CONTENT_TYPE_TEXT_JSON = "text/json";
// http请求连接参数默认值
private static int connectionTimeOut = 15000;// 连接超时时长
private static int readTimeOut = 25000;// 读取超时时长
@SuppressWarnings("unused")
private static int retryTimes = 3;// 重试次数
public static String connPostRequest(String url, String content) {
String result = "";
try {
URL postUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setConnectTimeout(connectionTimeOut);
connection.setReadTimeout(readTimeOut);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.connect();
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(content);
out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while (true) {
result = reader.readLine();
if (null == result)
break;
return result;
}
} catch (MalformedURLException e) {
} catch (ProtocolException e) {
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
}
return result;
}
}
package com.mjitech.qa.service;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
//import com.mjitech.qa.util.Logger;
/**
* 初始化服务
*
* @author Android
* @date 2018-05-16
*/
public class InitProperties {
public static final String PFILEPATH = File.separatorChar + "resources" + File.separatorChar + "config"
+ File.separatorChar + "config.properties";
private Properties config = new Properties();
public static Map<String, String> mapproperties = new HashMap<String, String>();
public InitProperties() {
// 构造初始配置文件
init();
}
private void init() {
String configPath = System.getProperty("user.dir") + PFILEPATH;
File file = new File(configPath);
// Logger.log("加载配置文件%s", configPath);
InputStreamReader fn = null;
if (file.exists()) {
try {
fn = new InputStreamReader(new FileInputStream(configPath), "UTF-8");
config.load(fn);
if (!config.isEmpty()) {
Set<Object> keys = config.keySet();
for (Object key : keys) {
InitProperties.mapproperties.put(key.toString(), config.getProperty(key.toString()));
if (!System.getProperties().containsKey(key.toString())
&& !config.getProperty(key.toString()).isEmpty()) {
System.setProperty(key.toString(), config.getProperty(key.toString()));
}
}
keys.clear();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fn.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
package com.mjitech.qa.service;
import java.security.MessageDigest;
/**
* 为加密字段预留功能
*
* @author android
* @date 2018-05-23
*/
public class Md5 {
public static String digist(String text) {
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("md5");
// 定义编码方式
byte[] bufs = text.getBytes("UTF-8");
md.update(bufs);
byte[] b = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
result = buf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static byte[] md5(String text) {
byte[] returnByte = null;
try {
MessageDigest md = MessageDigest.getInstance("md5");
// 定义编码方式
returnByte = md.digest(text.getBytes("UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
return returnByte;
}
public static String byte2hex(byte[] b) {
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
if (n < b.length - 1)
hs = hs + ":";
}
return hs.toUpperCase();
}
}
package com.mjitech.qa.service;
/**
*
* 自动化测试报告模版
* @author android
* @date 2018-05-16
*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import com.mjitech.qa.util.DateUtil;
public class YrdHtmlReport {
String date = DateUtil.formatDate(DateUtil.getCurrentDate(), "yyMMdd");
static String fileName = null;
FileWriter fw = null;
// 生成报告名字
public String reportName(String caseClassName) {
return "D:\\yrdReport\\" + date + "\\" + caseClassName + ".html";
}
// 创建报告的前半部分
public void createHead(String caseClassName) {
try {
// 获取报告名字
fileName = reportName(caseClassName);
File file = new File(fileName);
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
fw = new FileWriter(fileName);
fw.write("<!DOCTYPE html>");
fw.write("<html>");
fw.write("<head>");
fw.write("<meta charset=\"UTF-8\">");
fw.write("<title>" + caseClassName + " reprot</title>");
fw.write("<style type=\"text/css\">");
fw.write("*{ padding:0px;margin:0px;}" + "body{color:#333;}ul,li{list-style:none;}"
+ ".warp{ width:90%;margin:0 auto;line-height:24px;padding:20px 0;}"
+ ".list{font-size:14px;padding:10px 0;width:300px;margin:0 auto;}"
+ ".list strong{padding-right:10px;}"
+ "table{width:100%;cellpadding:0;cellspacing:0;border-collapse:collapse;border-spacing:0;font-size:12px;margin:0;padding:0;}"
+ "table th{text-align:center;border:1px #e8e8e8 solid; background:#efefef;padding:5px 20px;}"
+ "table td{text-align:center;padding:5px 20px;border:1px #e8e8e8 solid;}");
fw.write("</style>");
fw.write("</head>");
fw.write("<body>");
fw.write("<div class=\"warp\"> " + "<ul class=\"list\">" + " <li><strong>接口名称:</strong><span>"
+ caseClassName + "</span></li>" + " <li><strong>执行时间:</strong><span>" + date + "</span></li>"
+ " <li><strong>Test:</strong><span>" + date + "</span></li>" + " </ul>");
fw.write("<table>");
fw.write("<tr>");
fw.write("<th>用例编号</th><th>用例说明</th><th>输入参数</th>");
fw.write("<th>接口状态码(预期/实际)</th><th>接口返回码(预期/实际)</th><th>返回码说明(预期/实际)</th><th>用例执行结果</th>");
fw.write("</tr>");
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("创建报告文件报错");
e.printStackTrace();
}
}
// 添加报告内容 传入参数,用例编号、传入参数、
public void addReport(String caseData) {
try {
fw = new FileWriter(fileName, true);
fw.write("<tr>");
for (int i = 0; i < caseData.split("#").length; i++) {
fw.write("<td>" + caseData.split("#")[i] + "</td>");
}
fw.write("</tr>");
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
}
}
// 关闭报告
public void fileClose() {
try {
fw = new FileWriter(fileName, true);
fw.write("</table>");
fw.write("</div></body>");
fw.write("</html>");
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//package com.mjitech.qa.test;
//
//import org.testng.annotations.BeforeSuite;
//
///**
// * 测试父类
// * @author android
// */
//public abstract class BaseTest {
// @BeforeSuite
// public void beforeMethod() {
// }
//
//}
/*
* Java Base64 - A pure Java library for reading and writing Base64
* encoded streams.
*
* Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version
* 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License version 2.1 along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
package com.mjitech.qa.util;
import java.io.IOException;
import java.io.InputStream;
/**
* <p>
* A base64 encoding input stream.
* </p>
*
* <p>
* A <em>Base64InputStream</em> reads from an underlying stream which is
* supposed to be a base64 encoded stream. <em>Base64InputStream</em> decodes
* the data read from the underlying stream and returns the decoded bytes to the
* caller.
* </p>
*
* @author Carlo Pelliccia
*/
public class Base64InputStream extends InputStream {
/**
* The underlying stream.
*/
private InputStream inputStream;
/**
* The buffer.
*/
private int[] buffer;
/**
* A counter for values in the buffer.
*/
private int bufferCounter = 0;
/**
* End-of-stream flag.
*/
private boolean eof = false;
/**
* <p>
* It builds a base64 decoding input stream.
* </p>
*
* @param inputStream
* The underlying stream, from which the encoded data is read.
*/
public Base64InputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public int read() throws IOException {
if (buffer == null || bufferCounter == buffer.length) {
if (eof) {
return -1;
}
acquire();
if (buffer.length == 0) {
buffer = null;
return -1;
}
bufferCounter = 0;
}
return buffer[bufferCounter++];
}
/**
* Reads from the underlying stream, decodes the data and puts the decoded
* bytes into the buffer.
*/
private void acquire() throws IOException {
char[] four = new char[4];
int i = 0;
do {
int b = inputStream.read();
if (b == -1) {
if (i != 0) {
throw new IOException("Bad base64 stream");
} else {
buffer = new int[0];
eof = true;
return;
}
}
char c = (char) b;
if (Shared.chars.indexOf(c) != -1 || c == Shared.pad) {
four[i++] = c;
} else if (c != '\r' && c != '\n') {
throw new IOException("Bad base64 stream");
}
} while (i < 4);
boolean padded = false;
for (i = 0; i < 4; i++) {
if (four[i] != Shared.pad) {
if (padded) {
throw new IOException("Bad base64 stream");
}
} else {
if (!padded) {
padded = true;
}
}
}
int l;
if (four[3] == Shared.pad) {
if (inputStream.read() != -1) {
throw new IOException("Bad base64 stream");
}
eof = true;
if (four[2] == Shared.pad) {
l = 1;
} else {
l = 2;
}
} else {
l = 3;
}
int aux = 0;
for (i = 0; i < 4; i++) {
if (four[i] != Shared.pad) {
aux = aux | (Shared.chars.indexOf(four[i]) << (6 * (3 - i)));
}
}
buffer = new int[l];
for (i = 0; i < l; i++) {
buffer[i] = (aux >>> (8 * (2 - i))) & 0xFF;
}
}
public void close() throws IOException {
inputStream.close();
}
}
\ No newline at end of file
/*
* Java Base64 - A pure Java library for reading and writing Base64
* encoded streams.
*
* Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version
* 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License version 2.1 along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
package com.mjitech.qa.util;
import java.io.IOException;
import java.io.OutputStream;
/**
* <p>
* A base64 decoding output stream.
* </p>
*
* <p>
* It encodes in base64 everything passed to the stream, and it puts the encoded
* data into the underlying stream.
* </p>
*
* @author Carlo android
* @date 2018-05-23
*/
public class Base64OutputStream extends OutputStream {
/**
* The underlying stream.
*/
private OutputStream outputStream = null;
/**
* A value buffer.
*/
private int buffer = 0;
/**
* How many bytes are currently in the value buffer?
*/
private int bytecounter = 0;
/**
* A counter for the current line length.
*/
private int linecounter = 0;
/**
* The requested line length.
*/
private int linelength = 0;
/**
* <p>
* It builds a base64 encoding output stream writing the encoded data in the
* given underlying stream.
* </p>
*
* <p>
* The encoded data is wrapped to a new line (with a CRLF sequence) every 76
* bytes sent to the underlying stream.
* </p>
*
* @param outputStream
* The underlying stream.
*/
public Base64OutputStream(OutputStream outputStream) {
this(outputStream, 76);
}
/**
* <p>
* It builds a base64 encoding output stream writing the encoded data in the
* given underlying stream.
* </p>
*
* <p>
* The encoded data is wrapped to a new line (with a CRLF sequence) every
* <em>wrapAt</em> bytes sent to the underlying stream. If the
* <em>wrapAt</em> supplied value is less than 1 the encoded data will not
* be wrapped.
* </p>
*
* @param outputStream
* The underlying stream.
* @param wrapAt
* The max line length for encoded data. If less than 1 no wrap
* is applied.
*/
public Base64OutputStream(OutputStream outputStream, int wrapAt) {
this.outputStream = outputStream;
this.linelength = wrapAt;
}
public void write(int b) throws IOException {
int value = (b & 0xFF) << (16 - (bytecounter * 8));
buffer = buffer | value;
bytecounter++;
if (bytecounter == 3) {
commit();
}
}
public void close() throws IOException {
commit();
outputStream.close();
}
/**
* <p>
* It commits 4 bytes to the underlying stream.
* </p>
*/
protected void commit() throws IOException {
if (bytecounter > 0) {
if (linelength > 0 && linecounter == linelength) {
outputStream.write("\r\n".getBytes());
linecounter = 0;
}
char b1 = Shared.chars.charAt((buffer << 8) >>> 26);
char b2 = Shared.chars.charAt((buffer << 14) >>> 26);
char b3 = (bytecounter < 2) ? Shared.pad : Shared.chars.charAt((buffer << 20) >>> 26);
char b4 = (bytecounter < 3) ? Shared.pad : Shared.chars.charAt((buffer << 26) >>> 26);
outputStream.write(b1);
outputStream.write(b2);
outputStream.write(b3);
outputStream.write(b4);
linecounter += 4;
bytecounter = 0;
buffer = 0;
}
}
}
\ No newline at end of file
package com.mjitech.qa.util;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
/**
* 数据库连接工具
*
* @author gangwang
* @date 2018
*/
public class DBConnection {
String driver = "com.mysql.jdbc.Driver";
String test_url = "jdbc:mysql://139.129.108.180:3306/maxbox_test";
String test_user = "root";
String test_password = "Mjitech20!6";
String online_url = "jdbc:mysql://test.mjitech.com:3306/maxbox";
String online_user = "root";
String online_password = "Mjitech20!6";
public Connection conn;
/**
* 连接数据库
*/
public DBConnection(String env) {
try {
Class.forName(driver); // 加载驱动
if (env.equalsIgnoreCase("online")) {
conn = (Connection) DriverManager.getConnection(online_url, online_user, online_password);
if (!conn.isClosed()) {
System.out.println("online Succeeded connecting to the Database!");
}
} else {
conn = (Connection) DriverManager.getConnection(test_url, test_user, test_password);
if (!conn.isClosed()) {
System.out.println("TestEnv Succeeded connecting to the Database!");
}
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 关闭数据库
*/
public void close() {
try {
this.conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
DBConnection con = new DBConnection("online");
}
}
package com.mjitech.qa.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
//import com.mjitech.qa.util.Logger;
/**
* 初始化服务
* @author android
* @date 2018-05-16
* */
public class InitProperties {
public static final String PFILEPATH = File.separatorChar+"resources"+File.separatorChar+"config"+File.separatorChar+"config.properties";
private Properties config = new Properties();
public static Map<String, String> mapproperties = new HashMap<String, String>();
public InitProperties() {
//构造初始配置文件
init();
}
private void init() {
String configPath = System.getProperty("user.dir")+PFILEPATH;
File file =new File(configPath);
// Logger.log("加载配置文件%s", configPath);
InputStreamReader fn = null;
if(file.exists()){
try {
fn = new InputStreamReader(new FileInputStream(configPath),"UTF-8");
config.load(fn);
if (!config.isEmpty()) {
Set<Object> keys = config.keySet();
for (Object key : keys) {
InitProperties.mapproperties.put(key.toString(), config.getProperty(key.toString()));
if (!System.getProperties().containsKey(key.toString()) && !config.getProperty(key.toString()).isEmpty()) {
System.setProperty(key.toString(), config.getProperty(key.toString()));
}
}
keys.clear();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fn.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
//package com.mjitech.qa.util;
//
//import java.text.DateFormat;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.Formatter;
//
//import org.testng.Reporter;
//
///**
// * 日志类
// *
// * @author android
// * @date 2018-05-16
// */
//
//public class Logger {
// private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// // Log4j 输出
//
// // 日志开关
// public static boolean isLog = true;
// // 框架默认日志开关
// public static boolean isDefaut = false;
// // 控制台输出开关
// public static boolean isToStandardOut = true;
// // 日志格式开关
//
// public static int verbose = 1;
//
// private static void log(String s, int level, boolean logToStandardOut) {
// if (isLog) {
// Reporter.log(logPrefix(s), level, logToStandardOut);
// }
// }
//
// @SuppressWarnings("resource")
// public static void Defaultlog(String format, Object... args) {
// if (isLog && isDefaut) {
// String log = new Formatter().format(format, args).toString();
// Reporter.log(logPrefix(log), verbose, isToStandardOut);
// }
// }
//
// @SuppressWarnings("resource")
// public static void log(String format, Object... args) {
// String log = new Formatter().format(format, args).toString();
// log(log, verbose, isToStandardOut);
// }
//
// private static String logPrefix(String s) {
// Date logtime = new Date();
// return "[" + DATE_FORMAT.format(logtime) + "]: " + s;
// }
//
// public static void setLog() {
// if (System.getProperty("Logger", "true").equalsIgnoreCase("false")) {
// Logger.isLog = false;
// }
// if (System.getProperty("Logger.StandardOut", "true").equalsIgnoreCase("false")) {
// Logger.isToStandardOut = false;
// }
// if (System.getProperty("Logger.FrameWorkOut", "false").equalsIgnoreCase("true")) {
// Logger.isDefaut = true;
// }
// }
//}
/*
* Java Base64 - A pure Java library for reading and writing Base64
* encoded streams.
*
* Copyright (C) 2007-2009 Carlo Pelliccia (www.sauronsoftware.it)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version
* 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License version 2.1 along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
package com.mjitech.qa.util;
/**
* Package related utilities.
*
* @author android
* @date 2018-05-17
*/
class Shared {
static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static char pad = '=';
}
\ No newline at end of file
### \u8BBE\u7F6E###
#log4j.rootLogger = debug,stdout,D,E
### \u8F93\u51FA\u4FE1\u606F\u5230\u63A7\u5236\u62AC ###
#log4j.appender.stdout = org.apache.log4j.ConsoleAppender
#log4j.appender.stdout.Target = System.out
#log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
### \u8F93\u51FADEBUG \u7EA7\u522B\u4EE5\u4E0A\u7684\u65E5\u5FD7\u5230=E://logs/error.log ###
#log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
#log4j.appender.D.File = D://logs/log.log
#log4j.appender.D.Append = true
#log4j.appender.D.Threshold = INFO
#log4j.appender.D.layout = org.apache.log4j.PatternLayout
#log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### \u8F93\u51FAERROR \u7EA7\u522B\u4EE5\u4E0A\u7684\u65E5\u5FD7\u5230=E://logs/error.log ###
#log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
#log4j.appender.E.File =D://logs/error.log
#log4j.appender.E.Append = true
#log4j.appender.E.Threshold = ERROR
#log4j.appender.E.layout = org.apache.log4j.PatternLayout
#log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="手机端-小程序-账户登录">
<classes>
<class name="com.mjitech.qa.test.TestVaildateLoginName"/>
<class name="com.mjitech.qa.test.Login"/>
</classes>
</test> <!-- Test -->
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
</suite> <!-- Suite -->
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="mobile-micoo prgoram-login">
<classes>
<class name="com.mjitech.qa.test.VaildateLoginName"/>
<class name="com.mjitech.qa.test.Login"/>
</classes>
</test>
<!-- Test Flat -->
<test name="Flat Interface">
<classes>
<class name="com.mjitech.qa.test.GetMachineData"/>
<class name="com.mjitech.qa.test.ListFault"/>
<class name="com.mjitech.qa.test.UpdateDoorClose"/>
<class name="com.mjitech.qa.test.UploadImageList" />
</classes>
</test>
<test name="WeiXin Interface">
<classes>
<class name="com.mjitech.qa.test.GetPagedMainpageData"></class>
</classes>
</test>
<test name="27 Interface">
<classes>
<class name="com.mjitech.qa.test.AddSkuToCart"></class>
</classes>
</test>
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
</suite> <!-- Suite -->
package com.mjitech.qa.data;
import org.testng.annotations.DataProvider;
public class LoginDate {
@DataProvider(name="login")
public static Object[][] loginDate() {
return new Object[][]{
{"admin","yier34wu6"},
// {"fenjian","yier34wu6"},
// {"dabao","yier34wu6"},
// {"peisong","yier34wu6"},
// {"jiqikuguan","yier34wu6"},
// {"gangwang@mjitech.com","1234456"}
};
}
}
package com.mjitech.qa.data;
import org.testng.annotations.DataProvider;
public class SetOpenPasswordDate {
@DataProvider(name="set_open_password")
public static Object[][] loginDate() {
return new Object[][]{
{"13","yier34wu6"}
};
}
}
package com.mjitech.qa.data;
import org.testng.annotations.DataProvider;
public class SetUserPasswordData {
@DataProvider(name="setUserPassWord")
public static Object[][] setUserPassWord() {
return new Object[][] {{"fenjian","yier34wu6","yier34wu6"}};
}
}
package com.mjitech.qa.data;
import org.testng.annotations.DataProvider;
/**
* 验证用户是否存在接口
* @author android
* @date 2018-05-23
* */
public class VaildateLoginNameData {
@DataProvider(name="vaildateLoginName")
public static Object[][] vailateLoginName(){
return new Object[][] {
{"13","admin"}
// {"fenjian"},
// {"dabao"},
// {"peisong"},
// {"jiqikuguan"}
};
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.annotations.Test;
import com.mjitech.qa.service.BaseService;
import net.sf.json.JSONObject;
/**
* 故障检查任务之一-已知故障-删除图片接口
* @author gangwang
* @date 2018-07-30
* */
public class DeleteImageError {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
@Test
public void delete_image_error() {
String url = "http://preprod.mjitech.com/web/delete_image_error.action";
String body = "{\"fileId\":\"3213\",\"errorId\":\"432\",\"type\":\"KN\"}";
try {
JSONObject result = service.httpPostFlat(url, body);
System.out.println("删除图片:"+result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.junit.Assert;
import org.testng.annotations.Test;
import com.mjitech.qa.data.LoginDate;
import com.mjitech.qa.data.SetOpenPasswordDate;
import com.mjitech.qa.service.BaseService;
import com.mjitech.qa.data.VaildateLoginNameData;
import net.sf.json.JSONObject;
/**
* 平板接口逻辑
*
* @author caoyue
* @date 2018-11-12
*/
public class FlagInterface {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
/**
* 平板登陆接口
* @author caoyue
* @date 2019-1-9
* */
//@Test(dataProvider = "login", dataProviderClass = LoginDate.class)
public void login(String loginName,String password) {
String url = "http://test.mjitech.com/web/wx_work_login_api/login.action" ;
try {
json.put("loginName",loginName );
json.put("password", password);
json = service.httppostReturnJson(url, service.postParameter(json));
System.out.println("login result:"+json);
JSONObject meta = json.getJSONObject("meta");
if(meta!=null) {
String code = meta.getString("code");
Assert.assertEquals("200", code);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 小程序-账号登陆-验证账号是否存在
* @author caoyue
* @date 2019-1-9
* */
//@Test(dependsOnMethods = "login",dataProvider = "vaildateLoginName", dataProviderClass = VaildateLoginNameData.class)
public void vaildateLoginName(String storeId,String loginName) {
String url = "http://test.mjitech.com/web/wx_work_login_api/vaildate_login_name.action" ;
try {
json.put("storeId",storeId);
json.put("loginName", loginName);
json = service.httppostReturnJson(url, service.postParameter(json));
System.out.println("vaildate_login_name result:"+json);
// JSONObject meta = json.getJSONObject("meta");
// if(meta!=null) {
// String code = meta.getString("code");
// Assert.assertEquals("200", code);
// }
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 我要开门-首次开门设置密码
* */
//@Test(dependsOnMethods = "vaildateLoginName" ,dataProvider = "set_open_password", dataProviderClass = SetOpenPasswordDate.class)
public void setOpenPassword(String storeId,String password) {
String url = "http://test.mjitech.com/web/wx_work_api/set_open_password.action" ;
try {
json.put("storeId",storeId);
json.put("password", password);
json = service.httppostReturnJson(url, service.postParameter(json));
System.out.println("set_open_password result:"+json);
// JSONObject meta = json.getJSONObject("meta");
// if(meta!=null) {
// String code = meta.getString("code");
// Assert.assertEquals("200", code);
// }
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 统一获取门店信息
*
* @param storeId
* 门店ID
* @author caoyue
*/
//@Test
public void getMachineData() {
String url = "http://test.mjitech.com/web/pad_warehouse/getMachineData.action";
String body = "{\"storeId\":\"13\"}";
try {
JSONObject result = service.httpPostFlat(url, body);
String code = result.getJSONObject("meta").getString("code");
String name = result.getJSONObject("data").getJSONObject("warehouse").getString("name");
Assert.assertEquals("200", code);
Assert.assertEquals("华贸商业街", name);
System.out.println("获取订单信息:" + result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 获取有权限的任务类型接口
*
* @param employeeId
* @param storeId
* 门店ID
* @author caoyue
* @date 2018-11-12
*/
//@Test
public void getAlowedTaskAction() {
String url = "http://test.mjitech.com/web/machine_pad/get_alowed_task.action";
String body = "{\"employeeId\":\"1\",\"storeId\":\"13\"}";
try {
JSONObject result = service.httpPostFlat(url, body);
String code = result.getJSONObject("meta").getString("code");
Assert.assertEquals("200", code);
System.out.println("获取有权限的任务类型接口:" + result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.junit.Assert;
import org.testng.annotations.Test;
import com.mjitech.qa.service.BaseService;
import net.sf.json.JSONObject;
/**
* 统一获取门店信息
* @author gangwang
* @date 2018-07-25
* */
public class GetMachineData {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
@Test
public void getMachineData() {
String url = "http://preprod.mjitech.com/web/pad_warehouse/getMachineData.action" ;
String body = "{\"storeId\":\"12\"}";
try {
JSONObject result = service.httpPostFlat(url, body);
String code = result.getJSONObject("meta").getString("code");
String name = result.getJSONObject("data").getJSONObject("warehouse").getString("name");
Assert.assertEquals("200", result.getJSONObject("meta").getString("code"));
Assert.assertEquals("华贸测试机", name);
System.out.println("获取订单信息:"+result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.http.client.ClientProtocolException;
import org.junit.Assert;
import org.testng.annotations.Test;
import com.mjitech.qa.service.BaseService;
import net.sf.json.JSONObject;
/**
* 首页-统一获取门店信息
* @author gangwang
* @date 2018-07-25
* */
public class GetMachineData27 {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 华贸商业街
* */
@Test
public void getMachineData13() {
String url = "http://www.mjitech.com/web/machine_api/get_mainpage_data.action" ;
json.put("storeId", "13");
try {
String startTime = df.format(new Date());
System.out.println("华贸商业街获取首页接口start time:"+startTime);
JSONObject result = service.httppostCartReturnJson27(url, service.postParameter(json));
String endTime = df.format(new Date());
System.out.println("华贸商业街获取首页接口 end time:"+df.format(new Date()));
// String dd = endTime-startTime;
// System.out.println("华贸商业街获取首页接口响应时间:"+(endTime-startTime));
// System.out.println("华贸商业街-获取首页信息接口:"+result);
String is_succ = result.getString("is_succ");
Assert.assertEquals("true", is_succ);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 后现代城
* */
// @Test
public void getMachineData22() {
String url = "http://www.mjitech.com/web/machine_api/get_mainpage_data.action" ;
json.put("storeId", "22");
try {
JSONObject result = service.httppostCartReturnJson27(url, service.postParameter(json));
System.out.println("获取首页信息接口:"+result);
String is_succ = result.getString("is_succ");
Assert.assertEquals("true", is_succ);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 华贸写字楼店
* */
// @Test
public void getMachineData20() {
String url = "http://www.mjitech.com/web/machine_api/get_mainpage_data.action" ;
json.put("storeId", "20");
try {
JSONObject result = service.httppostCartReturnJson27(url, service.postParameter(json));
System.out.println("华贸写字楼店-获取首页信息接口:"+result);
String is_succ = result.getString("is_succ");
Assert.assertEquals("true", is_succ);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.mjitech.qa.service.BaseService;
import net.sf.json.JSONObject;
/**
* 微信端首页切换接口
* @author gangwang
* @date 2018-09-28
* */
public class GetPagedMainpageData {
BaseService service = new BaseService();
@Test
public void test_login_with_openid() {
String url = "http://www.mjitech.com/web/buyer_api/test_login_with_openid.action" ;
String body = "{\"openid\":\"o41Mgv5qXayH9P9C6IGYhN1Ujz3g\"}";
try {
long startTime = System.currentTimeMillis();
JSONObject result = service.httpPostFlat(url, body);
System.out.println("login result:"+result);
long endTime = System.currentTimeMillis();
long dd = endTime-startTime;
boolean flag = false ;
if(dd <=300) {
flag = true ;
} else {
flag = false ;
}
Assert.assertEquals(flag, true);
//{"is_succ":true,"userinfo":{"image":"/tmp/2018-06-23/1529767666568.png","outDate":0,"isEmployee":1,"unionId":"o2bX9wYWM6OW2SGhVaBqR0H7As6Y","gender":0,"openId":"o41Mgv5qXayH9P9C6IGYhN1Ujz3g","displayName":"张智","roles":[],"isManagerAuth":0,"mobile":"139****1145","isSubscribe":1,"displayNamePinyin":"zhang zhi ","nickname":"张智","userType":999,"id":1,"email":"zhangzhi@mjitech.com","username":"zhangzhi@mjitech.com"}}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test(dependsOnMethods = "test_login_with_openid")
public void get_paged_mainpage_data() {
String url = "http://www.mjitech.com/web/buyer_api/get_paged_mainpage_data.action" ;
String body = "{\"storeId\":\"13\",\"category\":\"4\",\"subCategory\":\"22\",\"from\":\"0\",\"to\":\"10\"}" ;
try {
long startTime = System.currentTimeMillis();
JSONObject result = service.httpPostFlat(url, body);
long endTime = System.currentTimeMillis();
System.out.println("get_paged_mainpage_data result:"+result);
long dd = endTime-startTime;
System.out.println("首页分类接口请求时间差:"+dd);
boolean flag = false ;
if(dd <=300) {
flag = true ;
} else {
flag = false ;
}
Assert.assertEquals(flag, true);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.mjitech.qa.service.BaseService;
import net.sf.json.JSONObject;
/**
* 故障列表接口
* @author gangwang
* @data 2018-07-27
* */
public class ListFault {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
@Test
public void list_fault() {
String url = "http://preprod.mjitech.com/web/machine_pad/list_fault.action" ;
String body = "{\"storeId\":\"12\",\"employeeId\":\"20\"}";
try {
JSONObject result = service.httpPostFlat(url, body);
String code = result.getJSONObject("meta").getString("code");
Assert.assertEquals("200", code);
String data = result.getString("data");
Assert.assertNotNull(data);
System.out.println("故障列表:"+result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.annotations.Test;
import com.mjitech.qa.data.LoginDate;
import com.mjitech.qa.service.BaseService;
import junit.framework.Assert;
import net.sf.json.JSONObject;
/**
* 登录接口
* @author android
* @date 2018-05-23
* */
public class Login {
BaseService service =new BaseService();
JSONObject json = JSONObject.fromObject("{}");
@Test(dataProvider = "loginFenJian", dataProviderClass = LoginDate.class)
public void login(String loginName,String password) {
String url = "http://test.mjitech.com/web/wx_work_login_api/login.action" ;
try {
json.put("loginName",loginName );
json.put("password", password);
json = service.httppostReturnJson(url, service.postParameter(json));
System.out.println("login result:"+json);
JSONObject meta = json.getJSONObject("meta");
if(meta!=null) {
String code = meta.getString("code");
Assert.assertEquals("200", code);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.annotations.Test;
import com.mjitech.qa.service.BaseService;
import net.sf.json.JSONObject;
public class OrderDetail {
String url = "http://www.mjitech.com/web/buyer_api/order_detail_new" ;
BaseService service = new BaseService() ;
JSONObject json = JSONObject.fromObject("{}");
@Test
public void testOrder() {
json.put("orderNumber", "S4094204721");
try {
String result = service.httppost(url, service.postParameter(json));
System.out.println("result:"+result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.annotations.Test;
import com.mjitech.qa.data.SetUserPasswordData;
import com.mjitech.qa.service.BaseService;
import junit.framework.Assert;
import net.sf.json.JSONObject;
/**
* 设置初始密码
* @author android
* @date 2018-05-24
* */
public class SetUserPasswrod {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
@Test(dataProvider="setUserPassWord",dataProviderClass=SetUserPasswordData.class)
public void setUserPassword(String loginName,String password,String confirPassword) {
String url = "http://test.mjitech.com/web/wx_work_login_api/set_user_passwrod.action" ;
System.out.println("test......");
json.put("loginName", loginName);
json.put("password",password);
json.put("confirPassword",confirPassword) ;
try {
json = service.httppostReturnJson(url, service.postParameter(json));
JSONObject meta = json.getJSONObject("meta");
if(meta!=null) {
String code = meta.getString("code");
Assert.assertEquals("200", code);
String message = meta.getString("message");
Assert.assertEquals("密码必须有一个大写字母", message);
}
System.out.println("result="+json);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import org.testng.log4testng.Logger;
public class Test {
private static Logger logger = Logger.getLogger(Test.class);
public static void main(String[] args) {
logger.debug("debug test");
logger.info("info test");
logger.error("error test....");
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.testng.annotations.Test;
import com.mjitech.qa.data.LoginDate;
import com.mjitech.qa.service.BaseService;
import junit.framework.Assert;
import net.sf.json.JSONObject;
/**
* 任务列表(分拣,打包,配送各种)
*
* @author android
* @date 2018-05-30
*/
public class TestTypeList {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
String token = "";
String employeeid = "";
@Test
public void login() {
String url = "http://localhost:8080/maxbox/web/wx_work_login_api/login.action";
try {
json.put("loginName", "fenjiantest");
json.put("password", "123456");
json = service.httppostReturnJson(url, service.postParameter(json));
JSONObject data = json.getJSONObject("data");
JSONObject employee = data.getJSONObject("employee");
employeeid = employee.getString("id");
token = data.getString("token");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test(dependsOnMethods = "login")
public void type_list() {
String url = "http://localhost:8080/maxbox/web/wx_work_api/type_list.action";
String body = "{\"type\":\"ST\"}";
try {
JSONObject result = service.httppostHeaderReturnJson(url, employeeid, token,body);
JSONObject meta = result.getJSONObject("meta");
if (meta != null) {
String code = meta.getString("code");
Assert.assertEquals("200", code);
Assert.assertEquals("成功", meta.getString("message"));
Assert.assertEquals("true", meta.getString("success"));
}
System.out.println("reuslt=" + result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.annotations.Test;
import com.mjitech.qa.service.BaseService;
import junit.framework.Assert;
import net.sf.json.JSONObject;
/**
* 关门接口
* @author gangwang
* @date 2018-07-27
* */
public class UpdateDoorClose {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
//http://localhost:8080/maxbox/web/machine_pad/update_close_door.action
@Test
public void update_close_door() {
String url = "http://preprod.mjitech.com/web/machine_api/update_door_close.action" ;
String body = "{\"storeId\":\"12\",\"employeeId\":\"20\"}";
try {
JSONObject result = service.httpPostFlat(url, body);
Assert.assertEquals("true",result.getString("is_succ"));
System.out.println("更新关闭接口:"+result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.annotations.Test;
import com.mjitech.qa.service.BaseService;
import junit.framework.Assert;
import net.sf.json.JSONObject;
/**
* 批量上传图片返回图片idList
* @author gangwang
* @date 2018-08-06
* */
public class UploadImageList {
BaseService service = new BaseService();
JSONObject json = JSONObject.fromObject("{}");
String data = "" ;
/**扫描二维码获取故障信息接口*/
// @Test
public void two_bar_codes_detail() {
String url = "http://preprod.mjitech.com/web/machine_pad/two_bar_codes_detail/KN/432" ;
System.out.println("url="+url);
try {
String result = service.httppost(url);
//扫描二维码获取故障信息接口:{"meta":{"code":"200","message":"成功","success":true},"data":{"errorCode":null,"message":"1:11 回零故障,伺服电机到位超时","type":"KN","fileModelVoList":[]}}
System.out.println("扫描二维码获取故障信息接口:"+result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// @Test
public void upload_image_list() {
String url = "http://preprod.mjitech.com/web/upload_image_list.action" ;
//{"meta":{"code":"200","message":"成功","success":true},"data":[3877]}
String result = service.uploadImageList(url);
System.out.println("平板-上传图片信息接口:"+result);
JSONObject stringtoJson = JSONObject.fromObject(result);
String code = stringtoJson.getJSONObject("meta").getString("code");
Assert.assertEquals("200", code);
if(code.equals("200")) {
data = stringtoJson.getString("data");
}
}
///machine_pad/fault/{type}/{id}
/**
* 上传图片之后调用这个接口保存图片到
* */
//@Test(dependsOnMethods="upload_image_list")
@Test
public void fault() {
String url = "http://preprod.mjitech.com/web/machine_pad/fault/KN/432" ;
json.put("files", "3967");
// String body = "{\"files\":\""+data+"\"}";
try {
String result = service.httppost(url, service.postParameter(json));
//JSONObject result = service.httpPostFlat(url, body);
System.out.println("保存图片:"+result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.mjitech.qa.test;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.testng.annotations.Test;
import com.mjitech.qa.data.VaildateLoginNameData;
import com.mjitech.qa.service.BaseService;
import com.mjitech.qa.service.HttpMethod;
import junit.framework.Assert;
import net.sf.json.JSONObject;
/**
* 验证账户是否存在接口
*
* @author android
* @date 2018-05-23
*/
public class VaildateLoginName {
JSONObject json = JSONObject.fromObject("{}");
HttpMethod httpMethod = new HttpMethod();
BaseService service = new BaseService();
@Test(dataProvider = "vaildateLoginName", dataProviderClass = VaildateLoginNameData.class)
public void VaildateLoginNameByDabao(String loginName) {
String url = "http://test.mjitech.com/web/wx_work_login_api/vaildate_login_name.action";
try {
json.put("loginName", loginName);
json = service.httppostReturnJson(url, service.postParameter(json));
System.out.println("验证不同角色账户是否存在接口:" + json);
JSONObject meta = json.getJSONObject("meta");
if (meta != null) {
String code = meta.getString("code");
Assert.assertEquals("200", code);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment