测试用例写入类添加对字段插入、删除、替换以及清空的方法;去除原有的特殊字段方法;在添加、插入字段内容的方法中添加对含有数据有效性字段处理的方法

This commit is contained in:
彭宇琦 2020-03-22 22:37:25 +08:00
parent 5ab9e9761e
commit 84bab79c44
13 changed files with 823 additions and 822 deletions

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version='1.0' encoding='UTF-8'?>
<templet>
<!-- id控制sheet的代号name表示文件中sheet的名称freeze表示需要冻结的前几列 -->
<sheet name="测试用例" freeze='2'>
<column id="标题" name="Name" wide="30.88" align="center"/>
<column id="目的" name="Objective" wide="18.25" align="center"/>
<column id="前置条件" name="Precondition" wide="18.25" align="center"/>
<column id="模块" name="Folder" wide="22.00" align="left"/>
<column id="状态" name="Status" wide="10.00" align="left"/>
<column id="优先级" name="Priority" wide="10.00" align="left"/>
<column id="项目" name="Component" wide="10.00" align="left"/>
<column id="设计者" name="Owner" wide="10.00" align="left"/>
<column id="步骤" name="Step" wide="45.75" align="left" row_text='1'/>
<column id="预期" name="Expected Result" wide="45.75" align="left" row_text='1'/>
<sheet name='测试用例' freeze='2'>
<column id='标题' name='Name' wide='30.88' align='left'/>
<column id='目的' name='Objective' wide='18.25' align='left'/>
<column id='前置条件' name='Precondition' wide='18.25' align='left' index='true'/>
<column id='模块' name='Folder' wide='22.00' align='center'/>
<column id='状态' name='Status' wide='10.00' align='center'/>
<column id='优先级' name='Priority' wide='10.00' align='center'/>
<column id='项目' name='Component' wide='10.00' align='center'/>
<column id='设计者' name='Owner' wide='10.00' align='center'/>
<column id='步骤' name='Step' wide='45.75' align='left' row_text='1' index='true'/>
<column id='预期' name='Expected Result' wide='45.75' align='left' row_text='1' index='true'/>
<datas id='状态'>
<data name='Approved' />
@ -28,10 +28,10 @@
<!-- 测试程序时使用 -->
<!--
<sheet name="测试用例2" freeze='3'>
<column id="标题" name="Name" wide="30.88" align="center"/>
<column id="目的" name="Objective" wide="18.25" align="center"/>
<column id="前置条件" name="Precondition" wide="18.25" align="center"/>
<sheet name='测试用例2' freeze='3'>
<column id='标题' name='Name' wide='30.88' align='center'/>
<column id='目的' name='Objective' wide='18.25' align='center'/>
<column id='前置条件' name='Precondition' wide='18.25' align='center'/>
<datas id='目的'>
<data name='1' />

Binary file not shown.

View File

@ -184,10 +184,13 @@ public class Time {
*/
public String getFormatTime(String pattern) {
if (pattern.matches(REGEX_DATE)) {
dateFormat = pattern;
return new SimpleDateFormat(getDateFormat(pattern)).format(date);
} else {
try {
return new SimpleDateFormat(pattern).format(date);
String dateText = new SimpleDateFormat(pattern).format(date);
dateFormat = pattern;
return dateText;
} catch (IllegalArgumentException e) {
return new SimpleDateFormat(dateFormat).format(date);
}

View File

@ -22,31 +22,6 @@ import org.dom4j.io.SAXReader;
*
*/
public abstract class Case {
/**
* 步骤
*/
private String[] step;
/**
* 预期
*/
private String[] except;
/**
* 标题
*/
private String title;
/**
* 关键词
*/
private String keyWord;
/**
* 前置条件
*/
private String[] precondition;
/**
* 用于存储需要替换的词语的开始标记
*/
@ -61,11 +36,6 @@ public abstract class Case {
*/
final String START_SIGN_REGIX = "\\*\\{";
/**
* 优先级
*/
private int rank;
/**
* 用于指向测试用例xml文件的Document对象
*/
@ -100,102 +70,6 @@ public abstract class Case {
saveField();
}
/**
* 返回步骤文本
* @return 步骤文本
*/
public String[] getStep() {
return step;
}
/**
* 根据调用方法的不同设置相应的步骤文本
* @param step 步骤文本
*/
// void setStep(String[] step) {
// this.step = step;
// }
/**
* 返回预期文本
* @return 预期文本
*/
public String[] getExcept() {
return except;
}
/**
* 根据调用方法的不同设置相应的预期文本
* @param except 预期文本
*/
// void setExcept(String[] except) {
// this.except = except;
// }
/**
* 返回标题文本
* @return 标题文本
*/
public String getTitle() {
return title;
}
/**
* 根据调用方法的不同设置相应的标题文本
* @param title 标题文本
*/
// void setTitle(String title) {
// this.title = title;
// }
/**
* 返回关键词文本
* @return 关键词文本
*/
public String getKeyWord() {
return keyWord;
}
/**
* 根据调用方法的不同设置相应的关键词文本
* @param keyWord 关键词文本
*/
// void setKeyWord(String keyWord) {
// this.keyWord = keyWord;
// }
/**
* 返回关键词文本
* @return 关键词文本
*/
public String[] getPrecondition() {
return precondition;
}
/**
* 根据调用方法的不同设置相应的前置条件文本
* @param keyWord 前置条件文本
*/
// void setPrecondition(String[] precondition) {
// this.precondition = precondition;
// }
/**
* 返回优先级文本
* @return 优先级文本
*/
public int getRank() {
return rank;
}
/**
* 根据调用方法的不同设置相应的优先级文本
* @param keyWord 优先级文本
*/
// void setRank(int rank) {
// this.rank = rank;
// }
/**
* 用于设置需要替换的词语
* @param word 测试用例xml库中需要替换的词语
@ -210,36 +84,6 @@ public abstract class Case {
wordMap.put(word, text);
}
/**
* 用于设置测试用例相应的所有信息
* @param title 标题
* @param step 步骤
* @param except 预期
* @param precondition 前置条件
* @param keyWord 关键词
* @param rank 优先级
*/
void setAllContent(String title, String[] step, String[] except, String[] precondition, String keyWord, int rank) {
this.step = step;
this.except = except;
this.title = title;
this.keyWord = keyWord;
this.precondition = precondition;
this.rank = rank;
}
/**
* 用于初始化所有的内容
*/
public void clearAllContent() {
step = null;
except = null;
title = "";
keyWord = "";
precondition = null;
rank = 1;
}
/**
* 用于替换文本中需要替换的单词返回替换后的文本
* @param text 需要替换的文本
@ -373,15 +217,6 @@ public abstract class Case {
fieldTextMap.get(label.getName()).add(text);
}
/**
* 用于添加带序号的一行文本
* @param label 标签名称枚举
* @param text 相应内容
*/
void addFieldText(LabelType label, int index, String text) {
fieldTextMap.get(label.getName()).add(index + "." + text);
}
/**
* 用于清空字段的内容以避免存储上一次输入的用例
*/

View File

@ -3,7 +3,6 @@ package pres.auxiliary.work.n.tcase;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/**
* <p><b>文件名</b>InformationCase.java</p>
@ -96,22 +95,22 @@ public class InformationCase extends Case {
//存储标题信息
addFieldText(LabelType.TITLE, getLabelText(caseName, LabelType.TITLE, "1"));
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
getAllLabelText(caseName, LabelType.STEP).forEach(text -> {
addFieldText(LabelType.STEP, index.getAndIncrement(), text);
addFieldText(LabelType.STEP, text);
});
//存储预期信息
index.set(1);
getAllLabelText(caseName, LabelType.EXCEPT).forEach(text -> {
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), text);
addFieldText(LabelType.EXCEPT, text);
});
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
@ -132,27 +131,27 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addUnWholeInformationCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//存储标题信息
addFieldText(LabelType.TITLE, getLabelText(caseName, LabelType.TITLE, "1"));
//存储步骤与预期信息
//不填写任何信息
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//只填写所有的必填项信息
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//只填写所有的非必填项信息
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -176,8 +175,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addTextboxCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -192,9 +191,9 @@ public class InformationCase extends Case {
//----------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -226,8 +225,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addTextboxCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -252,47 +251,47 @@ public class InformationCase extends Case {
wordMap.put(WordType.INPUT_MIN_LENGTH.getName(), String.valueOf(minLen));
//小于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
} else if (minLen == 0 && maxLen != 0) {
//存储最大输入限制
wordMap.put(WordType.INPUT_MAX_LENGTH.getName(), String.valueOf(maxLen));
//大于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
} else {
//若都不为0则将相应的内容进行存储且判断最大长度与最小长度是否传反若传反则调换顺序
wordMap.put(WordType.INPUT_MIN_LENGTH.getName(), String.valueOf(minLen < maxLen ? minLen : maxLen));
wordMap.put(WordType.INPUT_MAX_LENGTH.getName(), String.valueOf(minLen < maxLen ? maxLen : minLen));
//小于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//大于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//若最大最小限制相等则不添加该条用例
if (minLen != maxLen) {
//等于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
}
}
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -324,8 +323,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addTextboxCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -357,37 +356,37 @@ public class InformationCase extends Case {
throw new CaseContentException("大小限制不能同时为极值");
} else if (min == MIN_NUMBER && max != MAX_NUMBER) {
//大于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "11"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "11"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//小于最小负数限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "5"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "5"));
} else if (min != MIN_NUMBER && max == MAX_NUMBER) {
//小于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//大于最大正数限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "5"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "5"));
} else {
//小于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//大于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "11"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "11"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
}
//若传入的小数位数大于0则添加小数位相关的用例
@ -395,22 +394,22 @@ public class InformationCase extends Case {
//存储小数位数
wordMap.put(WordType.INPUT_DECIMALS.getName(), String.valueOf(decimals));
//等于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "14"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "6"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "14"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "6"));
//大于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "15"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "15"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//等于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "16"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "16"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
}
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -434,8 +433,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addPhoneCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -453,35 +452,35 @@ public class InformationCase extends Case {
//添加手机相关的测试用例
if (phoneRules.contains(PhoneType.MOBLE)) {
//大于11位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//小于11位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
}
//添加座机相关的测试用例
if (phoneRules.contains(PhoneType.FIXED)) {
//大于7位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//小于7位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//区位号
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
}
//长度符合但不和规则的用例
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -504,8 +503,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addIDCardCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -519,34 +518,34 @@ public class InformationCase extends Case {
textboxCommonCase(isMust, isRepeat, isClear, InputRuleType.NUM);
//输入15位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//输入18位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//输入末尾带Xx
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//输入大于18位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//输入小于18位大于15位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//输入小于15位
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//输入不符合规则
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -569,8 +568,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addSelectboxCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -581,28 +580,28 @@ public class InformationCase extends Case {
//----------------------------------------------------------------------
//存储步骤与预期信息
//选择选项后清空
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, hasEmpty ? "4" : "3"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, hasEmpty ? "4" : "3"));
//添加空选项用例
if (hasEmpty) {
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "1" : "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "1" : "2"));
}
//添加选择第一个选项
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//添加选择最后一个选项
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -622,8 +621,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addRadioButtonCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -634,31 +633,31 @@ public class InformationCase extends Case {
//----------------------------------------------------------------------
//存储步骤与预期信息
//选择选项后清空
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "4"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "4"));
//依次选择选项
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "3"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "3"));
//不改变默认选项
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//选第一个
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//选最后一个
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -679,8 +678,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addCheckboxCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -691,34 +690,34 @@ public class InformationCase extends Case {
//----------------------------------------------------------------------
//存储步骤与预期信息
//依次选择选项
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "3"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "3"));
//再次依次选择选项
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "4"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "4"));
//不进行选择
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
//选择第一个
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//选择最后一个
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//选择多个
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -741,8 +740,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addDateCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -757,9 +756,9 @@ public class InformationCase extends Case {
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -782,8 +781,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addDateCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -798,18 +797,18 @@ public class InformationCase extends Case {
wordMap.put(WordType.END_DATE.getName(), endDateName);
//大于结束时间
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于结束时间
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -832,8 +831,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addDateCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -848,18 +847,18 @@ public class InformationCase extends Case {
wordMap.put(WordType.START_DATE.getName(), startDateName);
//小于开始时间
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于开始时间
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -892,8 +891,8 @@ public class InformationCase extends Case {
clearFieldText();
// 存储case标签的name属性内容
String caseName = "addUploadFileCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//添加控件名称
wordMap.put(WordType.CONTROL_NAME.getName(), name);
@ -910,14 +909,14 @@ public class InformationCase extends Case {
//预览文件
if (isPreview) {
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "11"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "11"));
//根据枚举类型选择相应的预期
switch (uploadFileType) {
case FILE:
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "6"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "6"));
break;
case IMAGE:
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "5"));
break;
default:
throw new IllegalArgumentException("不支持的类型:" + uploadFileType.getName());
@ -925,18 +924,18 @@ public class InformationCase extends Case {
}
//不上传文件
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
//删除文件用例
if (isDelete) {
//删除文件点保存
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
//删除文件再上传
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, uploadFileType.equals(UploadFileType.IMAGE) ? "4" : "3"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, uploadFileType.equals(UploadFileType.IMAGE) ? "4" : "3"));
}
//上传文件个数限制
@ -950,39 +949,39 @@ public class InformationCase extends Case {
wordMap.put(WordType.UPLOAD_MIN_LENGTH.getName(), String.valueOf(minLen));
//小于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
} else if (minLen == 0 && maxLen != 0) {
//存储最大输入限制
wordMap.put(WordType.UPLOAD_MAX_LENGTH.getName(), String.valueOf(maxLen));
//大于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
} else if (minLen != 0 && maxLen != 0) {
//若都不为0则将相应的内容进行存储且判断最大长度与最小长度是否传反若传反则调换顺序
wordMap.put(WordType.UPLOAD_MIN_LENGTH.getName(), String.valueOf(minLen < maxLen ? minLen : maxLen));
wordMap.put(WordType.UPLOAD_MAX_LENGTH.getName(), String.valueOf(minLen < maxLen ? maxLen : minLen));
//小于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "7"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//等于最小限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "8"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//大于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "9"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
//若最大最小限制相等则不添加等于最大限制
if (minLen != maxLen) {
//等于最大限制
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "10"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
}
} else {
//若均等于0则不进行处理
@ -993,12 +992,12 @@ public class InformationCase extends Case {
//存储大小限制
wordMap.put(WordType.FILE_SIZE.getName(), String.valueOf(fileSize));
//超过大小限制的用例
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "7"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "7"));
} else {
//超过大小限制的用例
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "8"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "8"));
}
//上传非限制格式文件
@ -1008,15 +1007,14 @@ public class InformationCase extends Case {
fileRulesText += (fileRule.getName() + "");
}
wordMap.put(WordType.FILE_RULE.getName(), fileRulesText.substring(0, fileRulesText.length() - 1));
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "9"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "6"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "9"));
}
//----------------------------------------------------------------------
//存储前置条件信息
index.set(1);
getAllLabelText(caseName, LabelType.PRECONDITION).forEach(text -> {
addFieldText(LabelType.PRECONDITION, index.getAndIncrement(), text);
addFieldText(LabelType.PRECONDITION, text);
});
//存储关键词信息
addFieldText(LabelType.KEY, getLabelText(caseName, LabelType.KEY, "1"));
@ -1036,21 +1034,21 @@ public class InformationCase extends Case {
private void textboxCommonCase(boolean isMust, boolean isRepeat, boolean isClear, InputRuleType... inputRuleTypes) {
// 存储case标签的name属性内容
String caseName = "textboxBasicCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//转换输入限制为集合类型
List<InputRuleType> inputRules = Arrays.asList(inputRuleTypes);
//不填写或只输入空格
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "1"));
//根据是否必填来判断填入成功或失败预期
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
//填写特殊字符或HTML代码
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "2"));
//根据是否存在输入
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, inputRules.size() == 0 || inputRules.contains(InputRuleType.SPE) ? "1" : "2"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, inputRules.size() == 0 || inputRules.contains(InputRuleType.SPE) ? "1" : "2"));
//输入非限制的字符
if (inputRules.size() != 0) {
@ -1059,16 +1057,16 @@ public class InformationCase extends Case {
inputRuleText += (inputRule.getName() + "");
}
wordMap.put(WordType.INPUT_RULE.getName(), inputRuleText.substring(0, inputRuleText.length() - 1));
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
}
//清空输入的内容
if (isClear) {
//不填写或只输入空格
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "13"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "13"));
//根据是否必填来判断填入成功或失败预期
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "4" : "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "4" : "3"));
}
}
@ -1081,32 +1079,30 @@ public class InformationCase extends Case {
private void dateboxCommonCase(boolean isMust, boolean isInput, boolean isClear) {
// 存储case标签的name属性内容
String caseName = "addDateCase";
//存储步骤信息
AtomicInteger index = new AtomicInteger(1);
//不填写
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "1"));
//根据是否必填来判断填入成功或失败预期
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
//选择当前时间
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "2"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
//选择时间后清除时间
if (isClear) {
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "3"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, isMust ? "2" : "1"));
}
//手动输入时间
if (isInput) {
//输入正确格式
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "1"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "4"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "1"));
//输入不正确的格式
addFieldText(LabelType.STEP, index.get(), getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, index.getAndIncrement(), getLabelText(caseName, LabelType.EXCEPT, "2"));
addFieldText(LabelType.STEP, getLabelText(caseName, LabelType.STEP, "5"));
addFieldText(LabelType.EXCEPT, getLabelText(caseName, LabelType.EXCEPT, "2"));
}
}

View File

@ -126,10 +126,11 @@ public class TestCaseTemplet {
/**
* 根据xml配置文件中的内容生成相应的测试用例模板文件
*
* @return 生成的模板类文件对象
* @throws IOException 文件路径有误时抛出的异常
* @throws DocumentException xml配置文件有误时抛出的异常
*/
public void create() throws IOException {
public File create() throws IOException {
// 判断文件是否已经存在若存在且设置为不可覆盖时则抛出异常若允不存在则创建路径
if (templetFile.exists()) {
if (!cover) {
@ -158,6 +159,8 @@ public class TestCaseTemplet {
// 关闭流
fop.close();
xw.close();
return templetFile;
}
/**

View File

@ -43,7 +43,7 @@ import org.dom4j.io.SAXReader;
* <b>编码时间</b>2020年2月17日下午9:36:00
* </p>
* <p>
* <b>修改时间</b>2020年3月3日下午8:07:23
* <b>修改时间</b>2020年3月22日 下午10:29:37
* </p>
*
* @author 彭宇琦
@ -81,11 +81,6 @@ public class TestCaseWrite {
* 用于存储与测试用例生成类关联的字段参数1为用例文件中的字段参数2为测试用例生成方法中的字段
*/
private HashMap<String, String> relevanceMap = new HashMap<>(16);
/**
* 用于存储数据有效性的内容
*/
private String[] rank;
/**
* 用于存储当前对应的sheet名称
@ -113,7 +108,7 @@ public class TestCaseWrite {
* 多个sheet标签时则读取第一个sheet标签如需切换sheet标签则可调用{@link #switchSheet(String)} 方法
*
* @param configFile 测试文件模板xml配置文件类对象
* @param caseFile 测试用例文件类对象
* @param caseFile 测试用例文件类对象
* @throws IncorrectFileException 文件格式或路径不正确时抛出的异常
*/
public TestCaseWrite(File configFile, File caseFile) {
@ -121,7 +116,7 @@ public class TestCaseWrite {
try {
configXml = new SAXReader().read(configFile);
} catch (DocumentException e) {
throw new IncorrectFileException("用例xml文件有误" );
throw new IncorrectFileException("用例xml文件有误");
}
// 获取xml文件中的第一个sheet标签则将该标签的name属性内容传入getColumnId中
@ -161,64 +156,6 @@ public class TestCaseWrite {
this.sheetName = sheetName;
}
/**
* 用于指定特殊字段在xml文件中对应的字段id可预设的字段详见{@link FieldType}
* 若设置的是优先级字段则自动读取数据有效性标签中对优先级的数据内容添加至优先级映射中其顺序
* 按照标签的顺序可参建方法{@link #setRank(String...)}
*
* @param fieldType 预设字段枚举对象
* @param fieldId xml文件中字段对应的id
* @throws LabelNotFoundException 当在sheet标签中查不到相应的单元格id不存在时抛出的异常
*/
@SuppressWarnings("unchecked")
public void setPresupposeField(FieldType fieldType, String field) {
// 当字段id在fieldMap中查不到时则抛出异常
if (!fieldMap.containsKey(field)) {
throw new LabelNotFoundException("当前sheet不存在的标签id" + field);
}
fieldType.setValue(field);
// 当设置的字段为优先级字段时则直接查找字段id对应的数据有效性若存在则直接对其进行设置
if (fieldType == FieldType.RANK) {
Element datas = null;
if ((datas = (Element) (configXml
.selectSingleNode("//sheet[@name='" + sheetName + "']/datas[@id='" + field + "']"))) != null) {
// 获取datas标签下所有的data标签
List<Element> dataList = datas.elements();
// 设置优先级
setRank(dataList.stream().map(e -> e.attributeValue("name")).collect(Collectors.toList()));
}
}
}
/**
* 用于设置优先级的等级映射值若未使用预设的优先级添加方法可无需进行设置优先级映射根据传入的参数 的前后顺序进行排序例如<br>
* 传入的参数为<br>
* 则相应的映射关系为121<br>
* 若未对其映射进行设置则按照默认的优先级数字写入到文件中
*
* @param ranks 优先级映射文本
*/
public void setRank(String... ranks) {
rank = ranks;
}
/**
* 用于设置优先级的等级映射值若未使用预设的优先级添加方法可无需进行设置优先级映射根据传入的参数 的前后顺序进行排序例如<br>
* 传入的参数为<br>
* 则相应的映射关系为121<br>
* 若未对其映射进行设置则按照默认的优先级数字写入到文件中
*
* @param ranks 优先级映射文本
*/
public void setRank(List<String> ranks) {
rank = new String[ranks.size()];
for (int i = 0; i < ranks.size(); i++) {
rank[i] = ranks.get(i);
}
}
/**
* 设置字段名称的常值通过该设置则之后该字段将直接填入设置的值无需再次写入字段的值
@ -230,7 +167,7 @@ public class TestCaseWrite {
*/
public void setFieldValue(String field, String content) {
// 为保证在写用例的时候也能生效故将值设置进入fieldMap
addContent(field, false, content);
addContent(field, content);
// 先将值设置入fieldMap中可以保证field字段是存在于fieldMap中以减少此处再做判断
// 将字段内容写入caseValueMap
@ -247,180 +184,186 @@ public class TestCaseWrite {
word = WORD_SIGN + word + WORD_SIGN;
replaceWordMap.put(word, replactWord);
}
/**
* 用于将测试用例文件模板中的字段名与测试用例生成类继承自{@link Case}的测试用例生成类
* 的字段进行关联通过该方法设置关联字段后可将生成的测试用例写入到测试用例文件中
* @param field 测试用例文件字段
*
* @param field 测试用例文件字段
* @param caseLabel 测试用例生成方法的字段
* @throws LabelNotFoundException 当在sheet标签中查不到相应的单元格id不存在时抛出的异常
*/
public void relevanceCase(String field, String caseLabel) {
//判断字段是否存在若不存在则抛出异常
if (!fieldMap.containsKey(field)) {
throw new LabelNotFoundException("当前sheet不存在的标签id" + field);
}
//添加字段
relevanceMap.put(field, caseLabel);
}
/**
* 向用例中添加步骤可传入多个参数每一个参数表示一个步骤通过该方法传入后将自动对数据进行编号和换行
* 若需要调用该方法则需要对步骤对应的标签id调用{@link #setPresupposeField(FieldType, String)}方法
* 映射到{@link FieldType}枚举中 若需要使用替换的词语则需要使用#XX#进行标记如传参<br>
* testing<br>
* 需要替换其中的ing则传参<br>
* test#ing#
*
* @param steps 步骤参数
* @return 类本身以方便链式编码
*/
public TestCaseWrite addStep(String... steps) {
// 为每一段添加标号
for (int i = 0; i < steps.length; i++) {
steps[i] = ((i + 1) + "." + steps[i]);
}
return addContent(FieldType.STEP.getValue(), false, steps);
}
/**
* 向用例中添加预期可传入多个参数每一个参数表示一个预期通过该方法传入后将自动对数据进行编号和换行
* 若需要调用该方法则需要对预期对应的标签id调用{@link #setPresupposeField(FieldType, String)}方法
* 映射到{@link FieldType}枚举中 若需要使用替换的词语则需要使用#XX#进行标记如传参<br>
* testing<br>
* 需要替换其中的ing则传参<br>
* test#ing#
*
* @param excepts 预期参数
* @return 类本身以方便链式编码
*/
public TestCaseWrite addExcept(String... excepts) {
// 为每一段添加标号
for (int i = 0; i < excepts.length; i++) {
excepts[i] = ((i + 1) + "." + excepts[i]);
}
return addContent(FieldType.EXPECT.getValue(), false, excepts);
}
/**
* 向用例中添加前置条件可传入多个参数每一个参数表示一个前置条件通过该方法传入后将自动对数据进行编号和换行
* 若需要调用该方法则需要对预期对应的标签id调用{@link #setPresupposeField(FieldType, String)}方法
* 映射到{@link FieldType}枚举中 若需要使用替换的词语则需要使用#XX#进行标记如传参<br>
* testing<br>
* 需要替换其中的ing则传参<br>
* test#ing#
*
* @param preconditions 前置条件参数
* @return 类本身以方便链式编码
*/
public TestCaseWrite addPrecondition(String... preconditions) {
return addContent(FieldType.PRECONDITION.getValue(), true, preconditions);
}
/**
* 向用例中添加标题若需要调用该方法则需要对预期对应的
* 标签id调用{@link #setPresupposeField(FieldType, String)}方法映射到{@link FieldType}枚举中
* 若需要使用替换的词语则需要使用#XX#进行标记如传参<br>
* testing<br>
* 需要替换其中的ing则传参<br>
* test#ing#
*
* @param title 标题参数
* @return 类本身以方便链式编码
*/
public TestCaseWrite addTitle(String title) {
return addContent(FieldType.TITLE.getValue(), false, title);
}
/**
* 向用例中添加优先级若有通过{@link #setRank(String...)}等方法设置了优先级文本映射时
* 将传入的数字转义成设置的文本若未设置则直接传入数字若需要调用该方法则需要对预期对应
* 的标签id调用{@link #setPresupposeField(FieldType, String)}方法映射到{@link FieldType}枚举中
*
* @param titles 优先级参数
* @return 类本身以方便链式编码
*/
public TestCaseWrite addRank(int rank) {
// 若有设置优先级文本映射则将优先级对应到文本中若未设置则直接传入数字
if (this.rank != null) {
String text = "";
// 转义优先级
if (rank < 1) {
// 若优先级小于1则直接设置优先级第一个项目
text = this.rank[0];
} else if (rank >= 1 && rank <= this.rank.length) {
// 若优先级大于1且小于数组的长度时则直接设置相应优先级文字由于传入的数字从1开始故实际值为传入的数字-1
text = this.rank[rank - 1];
} else {
// 若优先级大于数组长度则直接设置最后一个项目
text = this.rank[this.rank.length - 1];
}
return addContent(FieldType.RANK.getValue(), false, text);
} else {
return addContent(FieldType.RANK.getValue(), false, String.valueOf(rank));
}
}
/**
* 通过传入的字段id将对应的字段内容写入到用例中字段id对应xml配置文件中的单元格标签的id属性
* 若需要使用替换的词语则需要使用#XX#进行标记如传参<br>
* testing<br>
* 需要替换其中的ing则传参<br>
* test#ing#
*
* @param field 字段id
* @param content 相应字段的内容
* @return 类本身以方便链式编码
* @throws LabelNotFoundException 当在sheet标签中查不到相应的单元格id不存在时抛出的异常
*/
public TestCaseWrite addContent(String field, boolean hasindex, String... contents) {
// 判断字段是否存在若不存在则抛出异常
if (!fieldMap.containsKey(field)) {
throw new LabelNotFoundException("当前sheet不存在的标签id" + field);
}
// 查找特殊词语并对词语进行替换
for (String word : replaceWordMap.keySet()) {
// 查找所有的内容并将特殊词语进行替换
for (int i = 0; i < contents.length; i++) {
contents[i] = hasindex ? (String.valueOf(i + 1) + ".") : "" + contents[i].replaceAll(word, replaceWordMap.get(word));
}
// 添加字段
relevanceMap.put(field, caseLabel);
}
/**
* 通过传入的字段id将对应的字段内容写入到用例最后的段落中字段id对应xml配置文件中的单元格标签的id属性
* 若需要使用替换的词语则需要使用#XX#进行标记如传参<br>
* testing<br>
* 需要替换其中的ing则传参<br>
* test#ing#<br>
* 添加数据时其亦可对存在数据有效性的数据进行转换在传值时只需要传入相应的字段值即可例如<br>
* 当字段存在两个数据有效性测试1测试2可传入addContent(..., "1")注意下标从1开始
* 此时文件中该字段的值将为测试1若传入的值无法转换成数字则直接填入传入的内容具体说明可以参见{@link Field#getDataValidation(String)}
*
* @param field 字段id
* @param contents 相应字段的内容
* @return 类本身以方便链式编码
* @throws LabelNotFoundException 当在sheet标签中查不到相应的单元格id不存在时抛出的异常
*/
public TestCaseWrite addContent(String field, String... contents) {
return insertContent(field, fieldMap.get(field).content.size(), contents);
}
/**
* 用于对已存储的内容进行移除若传入的下标超出当前的内容的段落数时则不做处理
* @param field 字段id
* @param indexs 需要删除的段落下标
* @return 类本身以方便链式编码
* @throws LabelNotFoundException 当在sheet标签中查不到相应的单元格id不存在时抛出的异常
*/
public TestCaseWrite removeContent(String field, int...indexs) {
// 判断字段是否存在若不存在则抛出异常
if (!fieldMap.containsKey(field)) {
throw new LabelNotFoundException("当前sheet不存在的标签id" + field);
}
// 将字段内容写入fieldMap
fieldMap.get(field).content = contents;
//移除相关的内容若输入的序号不存在则不进行
Arrays.stream(indexs).forEach(index -> {
try {
fieldMap.get(field).content.remove(index);
} catch (Exception e) {
}
});
return this;
}
/**
* 通过传入的字段id将对应的字段内容写入到用例文本的相应段落中字段id对应xml配置文件中的单元格标签的id属性
* 若需要使用替换的词语则需要使用#XX#进行标记如传参<br>
* testing<br>
* 需要替换其中的ing则传参<br>
* test#ing#<br>
* 添加数据时其亦可对存在数据有效性的数据进行转换在传值时只需要传入相应的字段值即可例如<br>
* 当字段存在两个数据有效性测试1测试2可传入insertContent(..., "1")注意下标从1开始
* 此时文件中该字段的值将为测试1若传入的值无法转换成数字则直接填入传入的内容具体说明可以参见{@link Field#getDataValidation(String)}
*
* @param field 字段id
* @param index 需要插入的段落
* @param contents 相应字段的内容
* @return 类本身以方便链式编码
* @throws LabelNotFoundException 当在sheet标签中查不到相应的单元格id不存在时抛出的异常
*/
public TestCaseWrite insertContent(String field, int index, String... contents) {
// 判断字段是否存在若不存在则抛出异常
if (!fieldMap.containsKey(field)) {
throw new LabelNotFoundException("当前sheet不存在的标签id" + field);
}
//若未传值或传入null则直接结束
if (contents == null || contents.length == 0) {
return this;
}
//若传入的下标大于相应的最大段落数时则直接结束
if (index > fieldMap.get(field).content.size()) {
return this;
}
if (fieldMap.get(field).datas.size() != 0) {
//查找数据有效性若当前字段存在数据有效性则将数据有效性转义若添加的字段无法转义则存储原内容
contents = dataValidityChange(contents, fieldMap.get(field));
}
// 查找特殊词语并对词语进行替换
contents = replaceWord(contents);
// 将字段内容写入fieldMap若插入的下标不正确则不做任何处理
try {
fieldMap.get(field).content.addAll(index, Arrays.asList(contents));
} catch (Exception e) {
}
return this;
}
/**
* 通过传入的字段id将对应的字段相应段落的内容替换成传入的文本或文本组字段id对应xml配置文件中的单元格标签的id属性
* 若需要使用替换的词语则需要使用#XX#进行标记如传参<br>
* testing<br>
* 需要替换其中的ing则传参<br>
* test#ing#
* @param field 字段id
* @param index 需要插入的段落
* @param contents 相应字段的内容
* @return 类本身以方便链式编码
* @throws LabelNotFoundException 当在sheet标签中查不到相应的单元格id不存在时抛出的异常
*/
public TestCaseWrite replaceContent(String field, int index, String... contents) {
// 判断字段是否存在若不存在则抛出异常
if (!fieldMap.containsKey(field)) {
throw new LabelNotFoundException("当前sheet不存在的标签id" + field);
}
//若未传值或传入null则直接结束
if (contents == null || contents.length == 0) {
return this;
}
//若传入的下标大于相应的最大段落数时则直接结束
if (index >= fieldMap.get(field).content.size()) {
return this;
}
//移除相应的段落
removeContent(field, index);
//在原位置上插入相应的内容
insertContent(field, index, contents);
return this;
}
/**
* 用于清空字段中存储的内容
* @param field 字段id
* @return 类本身以方便链式编码
* @throws LabelNotFoundException 当在sheet标签中查不到相应的单元格id不存在时抛出的异常
*/
public TestCaseWrite clearContent(String field) {
// 判断字段是否存在若不存在则抛出异常
if (!fieldMap.containsKey(field)) {
throw new LabelNotFoundException("当前sheet不存在的标签id" + field);
}
fieldMap.get(field).content.clear();
return this;
}
/**
* 用于将生成测试用例方法继承自{@link Case}类的方法所成成的测试用例添加到测试用例文件中
*
* @param testCase 测试用例生成方法
* @return 类本身
*/
public TestCaseWrite addCase(Case testCase) {
//获取用例内容
// 获取用例内容
HashMap<String, ArrayList<String>> labelMap = testCase.getFieldTextMap();
//遍历relevanceMap将用例字段内容写入到xml中
// 遍历relevanceMap将用例字段内容写入到xml中
relevanceMap.forEach((field, label) -> {
//若字段为优先级字段则进行特殊处理
if (FieldType.RANK.getValue().equals(field)) {
//添加优先级字段若可以转换则使用内置的添加优先级方法若不能转换则直接存储
try {
addRank(Integer.valueOf(labelMap.get(label).get(0)));
} catch (Exception e) {
addContent(field, false, labelMap.get(label).get(0));
}
} else {
addContent(field, false, labelMap.get(label).toArray(new String[] {}));
}
addContent(field, labelMap.get(label).toArray(new String[] {}));
});
return this;
}
@ -440,19 +383,24 @@ public class TestCaseWrite {
} else {
sheetElement = caseXml.getRootElement().addElement("sheet").addAttribute("name", sheetName);
}
// 创建case标签
String caseUuid = UUID.randomUUID().toString();
Element caseElement = sheetElement.addElement("case").addAttribute("id", caseUuid);
// 为fieldMap中的所有key创建field标签并记录相应的value
fieldMap.forEach((id, field) -> {
//判断字段是否需要进行编号若需要编号则调用编号方法
if (field.serialNumber) {
addSerialNumber(field);
}
// 添加field标签并设置name属性字段名称mark属性备注内容
// dom4j当属性值传入null时则直接不会创建该属性故此处无需做判断字段id是否在fieldMarkMap中
Element fieldElement = caseElement.addElement("field").addAttribute("name", id);
// 判断当前是否有添加内容若未添加内容则创建一个value属性为空的text标签
if (field.content != null) {
// 读取所有texts字符串数组的所有内容并为每一元素创建一个text标签将值加入属性中
Arrays.stream(field.content).forEach(text -> {
field.content.forEach(text -> {
fieldElement.addElement("text").addAttribute("value", text);
});
} else {
@ -466,7 +414,7 @@ public class TestCaseWrite {
if (caseValueMap != null && caseValueMap.size() != 0) {
caseValueMap.forEach((field, content) -> {
try {
addContent(field, false, content);
addContent(field, content);
} catch (LabelNotFoundException e) {
}
});
@ -535,7 +483,7 @@ public class TestCaseWrite {
Field field = fieldMap.get(fieldId);
// 获取text标签
List<Element> textList = fieldElement.elements("text");
// 判断当前字段是否需要分行编写内容
if (field.rowText < 1) {
writeCommonField(xs, fieldElement, fieldId, field, textList, index);
@ -723,6 +671,7 @@ public class TestCaseWrite {
// 设置颜色
xf.setColor(Short.valueOf(colorsText));
}
// 拼接文本
xrts.append(textList.get(index).attributeValue("value"), xf);
}
@ -757,11 +706,14 @@ public class TestCaseWrite {
for (int index = 0; index < column.size(); index++) {
// 查找xml文件中数据有效性标签
List<Element> datasList = sheetElement.elements("datas");
boolean datas = false;
ArrayList<String> datas = new ArrayList<String>();
// 遍历所有的数据有效性标签若存在则将datas设置为true
for (Element datasElemenet : datasList) {
if (datasElemenet.attributeValue("id").equals(column.get(index).attributeValue("id"))) {
datas = true;
//存储当前的数据有效性的内容
((List<Element>)(datasElemenet.elements())).forEach(textElement -> {
datas.add(textElement.attributeValue("name"));
});
break;
}
}
@ -769,10 +721,59 @@ public class TestCaseWrite {
// 存储字段信息
fieldMap.put(column.get(index).attributeValue("id"),
new Field(column.get(index).attributeValue("id"), column.get(index).attributeValue("align"), index,
column.get(index).attributeValue("row_text"), datas));
column.get(index).attributeValue("row_text"), datas,
Boolean.valueOf(column.get(index).attributeValue("index"))));
}
}
/**
* 用于对需要进行替换的特殊词语进行替换
* @param contents 文本内容
*/
private String[] replaceWord(String[] contents) {
// 查找特殊词语并对词语进行替换
for (String word : replaceWordMap.keySet()) {
// 查找所有的内容并将特殊词语进行替换
for (int i = 0; i < contents.length; i++) {
// 若需要添加序号则先获取当前列表中的字段个数以便于继续编号
contents[i] = contents[i].replaceAll(word, replaceWordMap.get(word));
}
}
return contents;
}
/**
* 将数据转化为相应的数据有效性中的内容当不存在数据有效性或传入的数据无法转换时则返回原串
* @param contents 文本内容
* @param field 字段相应的对象
* @return 转换后的文本内容
*/
private String[] dataValidityChange(String[] contents, Field field) {
//判断字段是否有数据有效性若没有则直接返回原串
if (field.datas.size() == 0) {
return contents;
}
// 查找所有的内容并将特殊词语进行替换
for (int i = 0; i < contents.length; i++) {
// 若需要添加序号则先获取当前列表中的字段个数以便于继续编号
contents[i] = field.getDataValidation(contents[i]);
}
return contents;
}
/**
* 对段落的文本进行编号
* @param field 段落类对象
*/
private void addSerialNumber(Field field) {
for (int index = 0; index < field.content.size(); index++) {
field.content.set(index, String.valueOf(index + 1) + "." + field.content.get(index));
}
}
/**
* 用于测试fieldMap中的内容编码结束后删除
*/
@ -1033,16 +1034,20 @@ public class TestCaseWrite {
* 用于标记每行写入的段落数默认为0当数字小于1时则认为不分行
*/
public int rowText = 0;
/**
* 用于标记是否对字段进行编号
*/
public boolean serialNumber = false;
/**
* 用于存储字段在用例中对应的内容
*/
public String[] content = null;
public ArrayList<String> content = new ArrayList<>();
/**
* 存储字段是否包含数据有效性由于在创建模板时数据有效性已被写入到模板文件中故此处无需存储
*/
public boolean datas;
public ArrayList<String> datas = new ArrayList<>();
/**
* 用于构造Field
@ -1052,19 +1057,30 @@ public class TestCaseWrite {
* @param index 字段在单元格中的位置
* @param datas 字段是否存在数据有效性
*/
public Field(String id, String align, int index, String rowText, boolean datas) {
/**
* 用于构造Field
*
* @param id 字段id
* @param align 单元格对齐方式
* @param index 字段在单元格中的位置
* @param rowText 换行段落数
* @param datas 字段是否存在数据有效性
* @param numberSign 字段是否需要编号
*/
public Field(String id, String align, int index, String rowText, ArrayList<String> datas, boolean numberSign) {
this.id = id;
this.align = align;
this.index = index;
this.datas = datas;
this.rowText = rowText == null ? -1 : Integer.valueOf(rowText);
this.serialNumber = numberSign;
}
/**
* 用于清空content中的内容
*/
public void clearContent() {
content = null;
content.clear();
}
/**
@ -1097,13 +1113,48 @@ public class TestCaseWrite {
return xcs;
}
/**
* 用于返回当前字段相应需要填入表格中的数据数据有效性中的内容该方法只能接收能转换为数字的字符串
* 若字符串无法转换为数字则返回原串若可以转换则将其转换为数字后通过方法获取数据有效性中的数据
* 存在以下三种情况
* <ol>
* <li>当转换的数值小于0时则获取数据有效性中的第一个数据</li>
* <li>当转换的数值大于数据有效性集合内容的最大数值时则获取数据有效性中的最后一个数据</li>
* <li>当转换的数值大于0小于数据有效性集合内容的最大数值时则获取对应的数据</li>
* </ol>
* <b>注意</b>数据有效性的为与优先级接轨故下标将从1开始即传入1时表示获取第1个元素而不是第2个
* @param indexText 下标字符串
* @return 数据有效性中对应的数据无法转换则返回传入的字符串
*/
public String getDataValidation(String indexText) {
//若数据有效性字段内容为空则直接返回传入的值
if (datas.size() == 0) {
return indexText;
}
//若存在数据有效性则将传入的数值字符串进行转换若无法转换为数字则直接返回所填字段
try {
int index = Integer.valueOf(indexText) - 1;
//再次判断转换的数字是否符合要求若小于0则返回第一个数据若大于集合长度则返回最后一个数据
if (index < 0) {
return datas.get(0);
} else if (index > datas.size()) {
return datas.get(datas.size() - 1);
} else {
return datas.get(index);
}
} catch (NumberFormatException e) {
return indexText;
}
}
/**
* 用于创建表格的数据有效性若当前字段无数据有效性或文件中无数据有效性 相应的内容时则不创建数据有效性
*/
public void addDataValidation(XSSFSheet caseSheet, int startRowIndex, int endRowIndex) {
// 判断当前是否存在数据有效性不存在则结束
if (!datas) {
if (datas.size() == 0) {
return;
}

View File

@ -0,0 +1,124 @@
package pres.auxiliary.work.testcase;
import java.io.File;
import java.io.IOException;
import org.dom4j.DocumentException;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import pres.auxiliary.work.n.tcase.InformationCase;
import pres.auxiliary.work.n.tcase.InformationCase.InputRuleType;
import pres.auxiliary.work.n.tcase.LabelType;
import pres.auxiliary.work.n.tcase.MarkColorsType;
import pres.auxiliary.work.n.tcase.TestCaseTemplet;
import pres.auxiliary.work.n.tcase.TestCaseWrite;
public class ProgramWriteTestCaseDemo {
/**
* 指向生成的测试用例文件
*/
File testCaseFile = new File("src/test/java/pres/auxiliary/work/testcase/测试用例.xlsx");
/**
* 指向测试用例文件字段配置文件
*/
File templetXml = new File("ConfigurationFiles/CaseConfigurationFile/FileTemplet/jira测试用例导入模板.xml");
/**
* 指向与InformationCase使用到的预设测试用例配置文件
*/
File informationCase = new File("ConfigurationFiles/CaseConfigurationFile/CaseTemplet/AddInformation.xml");
/**
* 用于写入用例到文件中
*/
TestCaseWrite tcw;
/**
* 用于使用信息类相关的测试用例模板
*/
InformationCase ic;
/**
* 生成测试用例文件并初始化参数
* @throws DocumentException
* @throws IOException
*/
@BeforeTest
public void createCaseFile() throws IOException, DocumentException {
TestCaseTemplet tct = new TestCaseTemplet(templetXml, testCaseFile);
//为方便演示则允许覆盖用例文件
tct.setCoverFile(true);
//生成用例文件
tct.create();
//初始化
tcw = new TestCaseWrite(templetXml, testCaseFile);
ic = new InformationCase(informationCase);
}
/**
* 用于打开生成的测试用例文件所在的文件夹
* @throws IOException
*/
@AfterTest
public void openCaseFolder() throws IOException {
//写入用例
tcw.writeFile();
//打开用例文件夹
java.awt.Desktop.getDesktop().open(new File("src/test/java/pres/auxiliary/work/testcase"));
}
/**
* 设置测试用例文件中的字段与测试用例模板类之间的字段关联
*/
@BeforeClass
public void setFieldRelevance() {
//设置测试用例文件中字段与测试用例模板中的字段对应关系
tcw.relevanceCase("步骤", LabelType.STEP.getName());
tcw.relevanceCase("预期", LabelType.EXCEPT.getName());
tcw.relevanceCase("优先级", LabelType.RANK.getName());
tcw.relevanceCase("前置条件", LabelType.PRECONDITION.getName());
tcw.relevanceCase("标题", LabelType.TITLE.getName());
//设置每条测试用例中值都一样的字段
tcw.setFieldValue("设计者", "彭宇琦");
tcw.setFieldValue("状态", "2");
}
/**
* 设置模块信息
*/
@BeforeGroups(groups="添加项目")
public void setCaseModule() {
//设置测试用例模板中需要使用的字段值
ic.setReplaceWord(InformationCase.BUTTON_NAME, "保存");
ic.setReplaceWord(InformationCase.ADD_INFORMATION, "项目");
//设置模块信息
tcw.setFieldValue("模块", "项目管理");
}
@Test(groups="添加项目")
public void addTestCase() {
tcw.addCase(ic.addWholeInformationCase()).end();
tcw.addCase(ic.addUnWholeInformationCase()).end();
tcw.addCase(ic.addBasicTextboxCase("项目名称", true, false, false)).end();
tcw.addCase(ic.addBasicTextboxCase("项目代号", true, false, false, InputRuleType.CAP, InputRuleType.NUM)).end();
ic.setReplaceWord(InformationCase.SUCCESS_EXCEPT_TEXT_START, "选择后,其下方的日期随选项而改变");
tcw.addCase(ic.addRadioButtonCase("起始日期")).end().fieldComment("步骤", "添加下方的日期控件内容会改变的步骤");
tcw.addCase(ic.addStartDateCase("起始日期开始时间", "起始日期结束时间", true, true, false)).end();
tcw.addCase(ic.addEndDateCase("起始日期结束时间", "起始日期开始时间", true, true, false)).end();
tcw.addCase(ic.addBasicTextboxCase("可用工作日", false, true, false, InputRuleType.NUM)).end();
tcw.addCase(ic.addBasicTextboxCase("项目名称", false, true, false)).end();
tcw.addCase(ic.addSelectboxCase("项目类型", false, false, false)).end();
tcw.addCase(ic.addSelectboxCase("关联产品", false, false, false)).end().changeTextColor("步骤", 1, 2, MarkColorsType.BLUE).fieldComment("步骤", "添加与产品联动的步骤与预期");
tcw.addCase(ic.addSelectboxCase("关联计划", false, false, false)).end().changeTextColor("步骤", 1, 2, MarkColorsType.BLUE).fieldComment("步骤", "添加与计划联动的步骤与预期");
tcw.addCase(ic.addLengthRuleTextboxCase("项目简介", false, true, false, 0, 500)).end();
tcw.addCase(ic.addRadioButtonCase("访问控制")).end();
}
}

View File

@ -58,12 +58,6 @@ public class WriteTestCaseTest {
wtc = new TestCaseWrite(conFile, tempFile);
wtc.setPresupposeField(FieldType.EXPECT, "预期");
wtc.setPresupposeField(FieldType.PRECONDITION, "前置条件");
wtc.setPresupposeField(FieldType.RANK, "优先级");
wtc.setPresupposeField(FieldType.STEP, "步骤");
wtc.setPresupposeField(FieldType.TITLE, "标题");
wtc.relevanceCase("步骤", LabelType.STEP.getName());
wtc.relevanceCase("预期", LabelType.EXCEPT.getName());
wtc.relevanceCase("优先级", LabelType.RANK.getName());
@ -85,21 +79,12 @@ public class WriteTestCaseTest {
// wtc.getCaseXml();
// java.awt.Desktop.getDesktop().open(wtc.getCaseXml());
java.awt.Desktop.getDesktop().open(tempFile.getParentFile());
java.awt.Desktop.getDesktop().open(tempFile);
}
@BeforeMethod
public void addContent(Method method) {
System.out.println("=======正在运行:" + method.getName() + "=======");
// wtc.addRank(1);
// wtc.addStep("步骤1", "步骤2", "步骤3");
// wtc.addTitle("这是标题");
// wtc.addPrecondition("前置条件1", "前置条件2", "前置条件3");
// wtc.addExcept("预期1", "预期2", "预期3");
// wtc.addContent("目的", false, "这是目的1", "这是目的2");
// wtc.addContent("模块", false, "这是模块");
// wtc.addContent("状态", false, "这是状态");
// wtc.addContent("项目", false, "这是项目");
// wtc.addContent("设计者", false, "这是设计者");
}
/**
@ -114,53 +99,16 @@ public class WriteTestCaseTest {
* 测试{@link TestCaseWrite#addContent(String, String)}方法
*/
@Test
public void addContentTest() {
wtc.addContent("标题", false, "这是标题").addContent("目的", false, "这是目的");
public void addContentTest_NotDataValidetion() {
wtc.addContent("标题", "这是标题").addContent("目的", "这是目的");
}
/**
* 测试{@link TestCaseWrite#setPresupposeField(FieldType, String)}方法
*/
@Test(enabled = false)
public void setPresupposeFieldTest() {
wtc.setPresupposeField(FieldType.EXPECT, "预期");
wtc.setPresupposeField(FieldType.PRECONDITION, "前置条件");
wtc.setPresupposeField(FieldType.RANK, "优先级");
wtc.setPresupposeField(FieldType.STEP, "步骤");
wtc.setPresupposeField(FieldType.TITLE, "标题");
}
/**
* 测试{@link TestCaseWrite#setRank(String...)}方法
* 测试{@link TestCaseWrite#addContent(String, String)}方法
*/
@Test
public void setRankTest() {
wtc.setRank("hehe", "haha", "xixi");
wtc.addRank(2);
}
/**
* 测试{@link TestCaseWrite#addStep(String...)}方法
*/
@Test
public void addStepTest() {
wtc.addStep("步骤1", "2020-03-03", "2020/03/03");
}
/**
* 测试{@link TestCaseWrite#addExcept(String...)}方法
*/
@Test
public void addExceptTest() {
wtc.addExcept("预期1", "预期2", "预期3");
}
/**
* 测试{@link TestCaseWrite#addPrecondition(String...)}方法
*/
@Test
public void addPreconditionTest() {
wtc.addPrecondition("前置条件1", "前置条件2", "前置条件3");
public void addContentTest_hasDataValidetion() {
wtc.addContent("优先级", "1").addContent("状态", "2", "3", "5", "-1", "哈哈哈");
}
/**
@ -173,37 +121,6 @@ public class WriteTestCaseTest {
wtc.addCase(ic.addRadioButtonCase("测试控件")).end();
}
/**
* 测试{@link TestCaseWrite#addTitle(String)}方法
*/
@Test
public void addTitleTest() {
wtc.addTitle("2020-02-03");
}
/**
* 测试{@link TestCaseWrite#addRank(int)}方法
*/
@Test
public void addRankTest_NotData() {
wtc.addRank(1);
wtc.addRank(-1);
wtc.addRank(100);
}
/**
* 测试{@link TestCaseWrite#end()}方法
*/
@Test
public void endTest() {
wtc.addRank(1);
wtc.addStep("步骤1", "步骤2", "步骤3");
wtc.addTitle("这是标题");
wtc.addPrecondition("前置条件1", "前置条件2", "前置条件3");
wtc.addExcept("预期1", "预期2", "预期3");
wtc.end();
}
/**
* 测试{@link TestCaseWrite#setReplactWord(String, String)}方法
@ -213,11 +130,10 @@ public class WriteTestCaseTest {
wtc.setReplactWord("特别", "TB");
wtc.setReplactWord("BT", "变态");
wtc.addRank(1);
wtc.addStep("#特别#1", "步骤#BT#", "步骤3");
wtc.addTitle("这是#特别#标题#BT#");
wtc.addPrecondition("#特别#前置条#BT#件1", "前#特别#置条#BT#件2", "前置条#BT#件3#特别#");
wtc.addExcept("预#特别#1", "预#特别#期2", "预期3#BT#");
wtc.addContent("步骤", "#特别#1", "步骤#BT#", "步骤3");
wtc.addContent("标题", "这是#特别#标题#BT#");
wtc.addContent("前置条件", "#特别#前置条#BT#件1", "前#特别#置条#BT#件2", "前置条#BT#件3#特别#");
wtc.addContent("预期" ,"预#特别#1", "预#特别#期2", "预期3#BT#");
}
/**
@ -271,4 +187,118 @@ public class WriteTestCaseTest {
wtc.end().markStepAndExcept(2, MarkColorsType.RED).fieldComment("目的", "目的标记").changeFieldBackground("设计者",
MarkColorsType.YELLOW);
}
/**
* 测试{@link TestCaseWrite#removeContent(String, int...)}方法
*/
@Test
public void removeContentTest_1() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").removeContent("步骤", 2).end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").removeContent("前置条件", 2).end();
}
/**
* 测试{@link TestCaseWrite#removeContent(String, int...)}方法
*/
@Test
public void removeContentTest_2() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").removeContent("前置条件", 2).end();
}
/**
* 测试{@link TestCaseWrite#removeContent(String, int...)}方法
*/
@Test
public void removeContentTest_3() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").removeContent("步骤", 5).end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").removeContent("前置条件", 5).end();
}
/**
* 测试{@link TestCaseWrite#insertContent(String, int, String...)}方法
*/
@Test
public void insertContentTest_1() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").insertContent("步骤", 2, "2.1", "2.2").end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").insertContent("前置条件", 2, "2.1", "2.2").end();
}
/**
* 测试{@link TestCaseWrite#insertContent(String, int, String...)}方法
*/
@Test
public void insertContentTest_2() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").insertContent("前置条件", 2, "2.1", "2.2").end();
}
/**
* 测试{@link TestCaseWrite#insertContent(String, int, String...)}方法
*/
@Test
public void insertContentTest_3() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").insertContent("步骤", 2).end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").insertContent("前置条件", 2).end();
}
/**
* 测试{@link TestCaseWrite#insertContent(String, int, String...)}方法
*/
@Test
public void insertContentTest_4() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").insertContent("步骤", 6, "2.1", "2.2").end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").insertContent("前置条件", 6, "2.1", "2.2").end();
}
/**
* 测试{@link TestCaseWrite#insertContent(String, int, String...)}方法
*/
@Test
public void insertContentTest_5() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").insertContent("步骤", 5, "2.1", "2.2").end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").insertContent("前置条件", 5, "2.1", "2.2").end();
}
/**
* 测试{@link TestCaseWrite#replaceContent(String, int, String...)}方法
*/
@Test
public void replaceContentTest_1() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").replaceContent("步骤", 2, "2.1", "2.2").end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").replaceContent("前置条件", 2, "2.1", "2.2").end();
}
/**
* 测试{@link TestCaseWrite#replaceContent(String, int, String...)}方法
*/
@Test
public void replaceContentTest_2() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").replaceContent("前置条件", 2, "2.1", "2.2").end();
}
/**
* 测试{@link TestCaseWrite#replaceContent(String, int, String...)}方法
*/
@Test
public void replaceContentTest_3() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").replaceContent("步骤", 2).end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").replaceContent("前置条件", 2).end();
}
/**
* 测试{@link TestCaseWrite#replaceContent(String, int, String...)}方法
*/
@Test
public void replaceContentTest_4() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").replaceContent("步骤", 6, "2.1", "2.2").end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").replaceContent("前置条件", 6, "2.1", "2.2").end();
}
/**
* 测试{@link TestCaseWrite#replaceContent(String, int, String...)}方法
*/
@Test
public void replaceContentTest_5() {
wtc.addContent("步骤", "1", "2", "3", "4", "5").replaceContent("步骤", 5, "2.1", "2.2").end();
wtc.addContent("前置条件", "1", "2", "3", "4", "5").replaceContent("前置条件", 5, "2.1", "2.2").end();
}
}

View File

@ -1,73 +0,0 @@
package pres.auxiliary.work.testcase;
import java.io.File;
import java.io.IOException;
import org.dom4j.DocumentException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import pres.auxiliary.work.n.tcase.FieldType;
import pres.auxiliary.work.n.tcase.MarkColorsType;
import pres.auxiliary.work.n.tcase.TestCaseTemplet;
import pres.auxiliary.work.n.tcase.TestCaseWrite;
public class WriteTestCaseTest_WriteCase {
TestCaseWrite wtc;
/**
* 配置文件类对象
*/
File conFile = new File("src/test/java/pres/auxiliary/work/testcase/jira测试用例导入模板.xml");
/**
* 模板文件类对象
*/
File tempFile = new File("Result/测试用例.xlsx");
@BeforeClass
public void createTemplet() throws DocumentException, IOException {
TestCaseTemplet temp = new TestCaseTemplet(conFile, tempFile);
temp.setCoverFile(true);
temp.create();
wtc = new TestCaseWrite(conFile, tempFile);
wtc.setPresupposeField(FieldType.EXPECT, "预期");
wtc.setPresupposeField(FieldType.PRECONDITION, "前置条件");
wtc.setPresupposeField(FieldType.RANK, "优先级");
wtc.setPresupposeField(FieldType.STEP, "步骤");
wtc.setPresupposeField(FieldType.TITLE, "标题");
}
/**
* 打开文件夹
*
* @throws IOException
*/
@AfterClass
public void openFolder() throws IOException {
wtc.writeFile();
// wtc.getCaseXml();
java.awt.Desktop.getDesktop().open(tempFile.getParentFile());
}
@Test
public void step_01() {
wtc.addStep("第一步", "第二部", "第三部", "第三部").addExcept("预期1", "预期2", "预期3").addTitle("用例1").end().changeFieldBackground("步骤", MarkColorsType.BLUE);
wtc.addStep("第一步", "第二部", "第三部").addExcept("预期1", "预期2", "预期3").addTitle("用例2").end()
.changeTextColor(FieldType.STEP.getValue(), 0, MarkColorsType.RED);
wtc.addStep("第一步", "第二部").addExcept("预期1", "预期2").addTitle("用例3").end()
.changeTextColor(FieldType.STEP.getValue(), 1, MarkColorsType.BLUE)
.changeTextColor(FieldType.STEP.getValue(), 0, MarkColorsType.YELLOW);
wtc.addStep("第一步", "第二部", "第三部").addExcept("预期1", "预期2", "预期3").addTitle("用例4").end();
wtc.addStep("第一步", "第二").addExcept("预期1", "预期2").addTitle("用例5").end()
.changeTextColor(FieldType.STEP.getValue(), 0, MarkColorsType.GREEN);
wtc.addStep("第一步", "第二部").addExcept("预期1", "预期2").addTitle("用例6").end().changeRowTextColor(MarkColorsType.RED);
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version='1.0' encoding='UTF-8'?>
<templet>
<!-- id控制sheet的代号name表示文件中sheet的名称freeze表示需要冻结的前几列 -->
<sheet name="测试用例" freeze='2'>
<column id="标题" name="Name" wide="30.88" align="center"/>
<column id="目的" name="Objective" wide="18.25" align="center"/>
<column id="前置条件" name="Precondition" wide="18.25" align="left"/>
<column id="模块" name="Folder" wide="22.00" align="left"/>
<column id="状态" name="Status" wide="10.00" align="left"/>
<column id="优先级" name="Priority" wide="10.00" align="left"/>
<column id="项目" name="Component" wide="10.00" align="left"/>
<column id="设计者" name="Owner" wide="10.00" align="left"/>
<column id="步骤" name="Step" wide="45.75" align="left" row_text='1'/>
<column id="预期" name="Expected Result" wide="45.75" align="left" row_text='1'/>
<sheet name='测试用例' freeze='2'>
<column id='标题' name='Name' wide='30.88' align='left'/>
<column id='目的' name='Objective' wide='18.25' align='left'/>
<column id='前置条件' name='Precondition' wide='18.25' align='left' index='true'/>
<column id='模块' name='Folder' wide='22.00' align='center'/>
<column id='状态' name='Status' wide='10.00' align='center'/>
<column id='优先级' name='Priority' wide='10.00' align='center'/>
<column id='项目' name='Component' wide='10.00' align='center'/>
<column id='设计者' name='Owner' wide='10.00' align='center'/>
<column id='步骤' name='Step' wide='45.75' align='left' row_text='1' index='true'/>
<column id='预期' name='Expected Result' wide='45.75' align='left' row_text='1' index='true'/>
<datas id='状态'>
<data name='Approved' />
@ -28,10 +28,10 @@
<!-- 测试程序时使用 -->
<!--
<sheet name="测试用例2" freeze='3'>
<column id="标题" name="Name" wide="30.88" align="center"/>
<column id="目的" name="Objective" wide="18.25" align="center"/>
<column id="前置条件" name="Precondition" wide="18.25" align="center"/>
<sheet name='测试用例2' freeze='3'>
<column id='标题' name='Name' wide='30.88' align='center'/>
<column id='目的' name='Objective' wide='18.25' align='center'/>
<column id='前置条件' name='Precondition' wide='18.25' align='center'/>
<datas id='目的'>
<data name='1' />

View File

@ -0,0 +1,32 @@
package test.javase;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
import javax.xml.crypto.Data;
import pres.auxiliary.tool.randomstring.RandomString;
import pres.auxiliary.tool.randomstring.StringMode;
public class TestArrayList {
public static void main(String[] args) {
ArrayList<String> al = new ArrayList<String>();
int count = 10000000;
System.out.println("开始添加" + count + "个随机内容");
Date start = new Date();
for (int i = 0; i < count; i++) {
al.add(new RandomString(StringMode.CH).toString(10, 30));
}
System.out.println("添加完毕,耗时:" + (new Date().getTime() - start.getTime()));
System.out.println("随机抽取10个内容");
start = new Date();
for (int i = 0; i < 10; i++) {
System.out.println("" + (i + 1) + "个内容:" + al.get(new Random().nextInt(10000)));
}
System.out.println("抽取完毕,耗时:" + (new Date().getTime() - start.getTime()));
}
}