Commit 727c5c50 by shuai

题库首次提交20181017

parent cb21f7e1
/.classpath
/.project
.idea
.settings
bin/
log/
testoutput/
test-output/
环境要求:
1. 安装Java jdk 和 ant到本地环境
运行准备和步骤:
1. 确保工程目录下的resources目录下的tmp.xls 文件不存在。
2. 打开data.xls文件,在Input sheet中的填写测试数据(一行数据就是一次接口调用). 可以把data_all.xls里Testcase Sheet里需要执行的测试用例复制到data.xls的Input里(带表头)。清除data.xls里output sheet里的数据。
保存并关闭data.xls.(必须关闭)
3. 选择测试环境配置: 修改env.properties里的环境值。 可以参照env.prod.properties和env.beta.properties
4. 在工程目录下执行,ant。
配置:
1. 测试数据表说明:data.xls
1)数字输入excel会变成字符型。如果参数为数字型,请输入单引号+数字。例如’10000。
2)OpenId,productId,orderId:
OpenId,productId,orderId需要从之前测试步骤执行结果获取的,填写"code". 代码会使用从之前的测试结果中取得的openid,prouductId,orderId。
3)VerifyCode
a. verifycode需要从之前测试步骤执行结果获取本条用例使用的手机号的verifycode的,填写"code_own"
b. verifycode需要从之前测试步骤执行结果获取非本条用例使用的手机号的verifycode的,填写"code_others"
c. verifycode需要从之前测试步骤执行结果获取本条用例使用的手机号的已过期的verifycode的,填写"code_old"
4)statusCode,errcode,errmsg需要填写期望返回值
5) 对于需要全新客户信息的case,需要把cleanDB字段置为Y。
2. env.properties 文件:
isProduct=Y 表示 生产环境运行,不会连接数据做数据插入和检查。注意,生产环境执行时,如果要测插入商品接口,请在data表的字段busiId和busiName填写实际值,不要使用“code”。
查看结果:
1)测试用例全部执行后,打开data.xls文件, 在output里查看结果。
说明: 在非beta环境运行时,测试case运行结束后,会清除数据库中的测试数据。如需不清除数据,需要comment掉:BestbuyGMAPITest.java里afterClass() function下的
this.cleanCustomerInfo();
this.cleanProductsFromDB();
this.cleanOrdersFromDB();
<project name="auto_test" default="testoutput" basedir=".">
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask" >
<classpath>
<pathelement location="lib/testng-6.8.6.jar" />
</classpath>
</taskdef>
<property name="testoutputdir" location="test-output" />
<property name="srcdir" location="src" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<property name="basedir" value="D:/workspace/auto_test/" />
<path id="classpath.test">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${testoutputdir}" />
<pathelement location="${srcdir}" />
</path>
<target name="clean">
<delete dir="${basedir}/bin" />
</target>
<target name="compile" depends="clean">
<mkdir dir="${basedir}/bin" />
<javac srcdir="${srcdir}" encoding="UTF-8" destdir="${basedir}/bin" verbose="${full-compile}" classpathref="classpath.test" includeantruntime="off" debug="on" debuglevel="lines,vars,source" />
</target>
<path id="classes">
<fileset dir="${libdir}" includes="*jar"/>
<fileset dir="${libdir}" includes="*zip"/>
<pathelement location="${basedir}/bin/"/>
</path>
<!--如果testng里面没有配置reportng监听器,则使用这个方式,如果testng里面配置了 reportng监听器,那么就使用这个配置
<target name="runtest" depends="compile">
<testng outputdir="${testoutputdir}" classpathref="classes"
useDefaultListeners="false"
delegateCommandSystemProperties="true" haltOnFailure="true"
listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter,org.testng.reporters.FailedReporter">
<sysproperty key="file.encoding" value="UTF-8" />
<xmlfileset dir="${basedir}" includes="testng.xml" />
</testng>
</target>-->
<!--如果testng里面配置了 reportng监听器,那么就使用这个配置-->
<target name="runtest" depends="compile">
<!---->
<testng outputdir="${testoutputdir}" classpathref="classes"
useDefaultListeners="false" >
<sysproperty key="file.encoding" value="UTF-8" />
<xmlfileset dir="${basedir}" includes="testng.xml" />
</testng>
</target>
<target name="testoutput" depends="runtest">
<java classname="com.offcn.TestUnti.Mail" classpath="${basedir}/bin">
<sysproperty key="file.encoding" value="UTF-8" />
<classpath>
<pathelement location="lib/javax.mail.jar" />
</classpath>
</java>
<!--
ui自动化测试报告部分
<xslt in="${testoutputdir}/testng-results.xml" style="${testoutputdir}/testng-results.xsl" out="${testoutputdir}/index.html ">
<param name="testNgXslt.outputDir" expression="${basedir}/testoutput/" />
<classpath refid="classpath.test" />
</xslt>
-->
</target>
</project>
++ "b/tiku_API_test/out/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Failed suite-ys">
<test name="Default test-ys">
<classes>
<class name="com.puhui.test.RenMai_APITest">
<methods>
<include name="f" invocation-numbers=""/>
</methods>
</class>
</classes>
</test>
</suite>
package aoutTestCode;
import java.io.File;
import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.offcn.TestUnti.Log;
import sun.util.logging.resources.logging;
import freemarker.template.Configuration;
import freemarker.template.Template;
public class MakeCode {
public static void main(String[] args){
MakeCode mc=new MakeCode();
try {
// mc.aoutMakeCode("xml_makecode/MakeCode.xml");
mc.aoutMakeCode("xml_makecode/rgxs-MakeCode.xml");
} catch (Exception e) {
Log.logError("aoutMakeCode_error");
e.printStackTrace();
}
Log.logInfo("aoutMakeCode_ok");
}
public void aoutMakeCode(String path) throws Exception {
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File("templates"));
Map<String,Object> root = new HashMap<String,Object>();
xmlToftl xml=new xmlToftl(path);
root.put("package_name", xml.getName("package_name"));
root.put("implements_name",xml.getName("implements_name"));
root.put("class_name", xml.getName("class_name"));
root.put("father_class_name", xml.getName("father_class_name"));
root.put("parameters", xml.getNameAndKey("parameters","parameter"));
root.put("initialize_Disable", xml.getBoolean("initialize_Disable"));
root.put("initializes", xml.getNameAndKey("initializes","initialize"));
root.put("handleInput_Disable", xml.getBoolean("handleInput_Disable"));
root.put("handleInput_replaces", xml.getNameAndTypeAndKey("handleInput_replaces","handleInput_replace"));
root.put("handleInputs_Verifications", xml.getNameAndTypeAndKey("handleInputs_Verifications","handleInputs_Verification"));
root.put("SendRequest_Disable", xml.getBoolean("SendRequest_Disable"));
root.put("SendRequest", xml.getName("SendRequest"));
root.put("handleOutput_Disable", xml.getBoolean("handleOutput_Disable"));
root.put("handleOutput_saves", xml.gethandleOutput_save("handleOutput_saves","handleOutput_save","handleOutput"));
root.put("handleOutput_Table", xml.getName("handleOutput_Table"));
root.put("handleOutput_TableKey", xml.getKey("handleOutput_Table"));
Template t1 = cfg.getTemplate("code.ftl");
File directory = new File(".");
String package_name=xml.getName("package_name").replace(".", "\\");
String FilePath = directory.getCanonicalPath() +File.separator+"src"+File.separator+package_name+File.separator;
File Files = new File(FilePath);
File FilesName = new File(FilePath,xml.getName("class_name")+".java");
Log.logInfo("makeFolder:"+(Files.mkdirs()));
Log.logInfo("makeFile:"+(FilesName.createNewFile()));
//显示生成的数据
Writer out = new FileWriter(FilesName);
t1.process(root, out);
out.flush();
out.close();
}
}
package aoutTestCode;
import java.io.File;
import java.util.List;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ParseXml {
@SuppressWarnings("unused")
private String filePath;
private Document document;
private Element root;
public ParseXml(String filePath) {
super();
this.filePath = filePath;
this.load(filePath);
}
public void load(String filePath) {
File file=new File(filePath);
if(file.exists()){
SAXReader saxReader=new SAXReader();
try {
document=saxReader.read(file);
root = document.getRootElement();
} catch (DocumentException e) {
System.out.println("文件加载异常"+filePath);
}
}else{
System.out.println("文件没找到");
}
}
public Element getElementObject(String elementPath){
return (Element)document.selectSingleNode(elementPath);
}
public String getElementText(String elementPath){
Element element=this.getElementObject(elementPath);
if(element!=null){
return element.getTextTrim();
}else{
return null;
}
}
public List<Map<String,String>> getElementsName_text(String parameters){
Element P=root.element(parameters);
List<Element> Elements = P.elements("parameter");
for (Element element : Elements) {
System.out.print(element.attributeValue("name")+" ");
System.out.println(element.getTextTrim());
}
return null;
}
public static void main(String[] args) {
ParseXml parseXml=new ParseXml("config/config.xml");
String element=parseXml.getElementText("/config/browser");
System.out.println(element);
}
}
package aoutTestCode;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class xmlToftl {
@SuppressWarnings("unused")
private String filePath;
private Document document;
private Element root;
public xmlToftl(String filePath) {
this.filePath = filePath;
this.load(filePath);
}
public void load(String filePath) {
File file=new File(filePath);
if(file.exists()){
SAXReader saxReader=new SAXReader();
try {
document=saxReader.read(file);
root=document.getRootElement();
} catch (DocumentException e) {
System.out.println("文件加载异常"+filePath);
}
}else{
System.out.println("文件没找到");
}
}
public static void main(String[] args) {
xmlToftl x=new xmlToftl("templates/MakeCode.xml");
x.go();
}
public void go(){
//获取包名
String package_name=getName("package_name");
//获取类名
String class_name=getKey("class_name");
//获取接口名
String implements_name=getKey("implements_name");
//获取boolean
boolean b=getBoolean("initialize_Disable");
System.out.println(b);
//获取参数
List<Map<String,String>> listParameters=getNameAndKey("parameters","parameter");
//获取参数
List<Map<String,String>> initializes=getNameAndKey("initializes","initialize");
System.out.println(initializes.toString());
//获取参数
List<List<String>> getN=getNameAndTypeAndKey("handleInput_replaces","handleInput_replace");
System.out.println(getN);
//获取参数
List<List<String>> getN1=getNameAndTypeAndKey("handleInputs_Verifications","handleInputs_Verification");
System.out.println(getN1);
//获取参数
Map<String,List<String>> getn2=gethandleOutput_save("handleOutput_saves","handleOutput_save","handleOutput");
System.out.println(getn2);
}
public String getName(String str){
if(str.equals("package_name")){
return root.attributeValue("name");
}
Element element=root.element(str);
return element.attributeValue("name");
}
public String getKey(String str){
Element ementsValue=root.element(str);
String Value=ementsValue.getTextTrim();
return Value;
}
public boolean getBoolean(String str){
String type=getKey(str);
if("true".equals(type)){
return true;
}
return false;
}
public List<Map<String,String>> getNameAndKey(String parameters,String parameter){
Element Elements=root.element(parameters);
@SuppressWarnings("unchecked")
List<Element> liste = Elements.elements(parameter);
List<Map<String,String>> list = new ArrayList<Map<String,String>>();
for (Element element : liste) {
Map<String,String> root = new HashMap<String,String>();
if(element.attributeValue("value")==null){
root.put(element.attributeValue("name"), element.getTextTrim());
}else{
root.put(element.attributeValue("value"), element.getTextTrim());
}
list.add(root);
}
return list;
}
public List<List<String>> getNameAndTypeAndKey(String parameters,String parameter){
Element Elements=root.element(parameters);
@SuppressWarnings("unchecked")
List<Element> liste = Elements.elements(parameter);
List<List<String>> list = new ArrayList<List<String>>();
for (Element element : liste) {
List<String> root = new ArrayList<String>();
if(element.attributeValue("name")!=null){
root.add(element.attributeValue("name"));
}
if(element.attributeValue("type")!=null){
root.add(element.attributeValue("type"));
}
if(element.attributeValue("value")!=null){
root.add(element.attributeValue("value"));
}
if(!element.getTextTrim().equals("")){
root.add(element.getTextTrim());
}
list.add(root);
}
return list;
}
public Map<String,List<String>> gethandleOutput_save(String parameters,String parameter,String handleOutput){
Element Elements=root.element(parameters);
@SuppressWarnings("unchecked")
List<Element> liste = Elements.elements(parameter);
Map<String,List<String>> map = new HashMap<String,List<String>>();
String mapString="";
for (Element element : liste) {
List<String> root = new ArrayList<String>();
if(element.attributeValue("name")!=null){
mapString=element.attributeValue("name");
}
List<Element> listh = element.elements(handleOutput);
for (Element element2 : listh) {
root.add(element2.getTextTrim());
}
map.put(mapString,root);
}
return map;
}
}
package com.offcn.TestData;
import org.testng.annotations.DataProvider;
import com.offcn.TestUnti.ReadExcels;
import com.offcn.TestUnti.ReadProperties;
public class offcn_api_testData {
@DataProvider(name="renmai")
public static Object[][] dp(){
String xls=ReadProperties.GetTestPropertyByKey("xls");
String sheet=ReadProperties.GetTestPropertyByKey("sheet");
ReadExcels readExcels = new ReadExcels(xls,sheet);
try {
return readExcels.readExcels_return();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
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