From d257043768e9aa84b60ac67017c366f4397830a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BD=AD=E5=AE=87=E7=90=A6?= <465615774@qq.com>
Date: Sat, 7 Mar 2020 19:41:11 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E4=BE=8B=E6=A8=A1?=
=?UTF-8?q?=E6=9D=BF=E7=9B=B8=E5=85=B3=E7=9A=84=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../CaseTemplet/AddInformation.xml | 488 +++++++++++++-----
.../CaseTemplet/BrowseList.xml | 20 +-
.../CaseConfigurationFile/CaseTemplet/Map.xml | 10 +-
.../CaseTemplet/Username.xml | 18 +-
.../CaseTemplet/Video.xml | 12 +-
.../{ => FileTemplet}/CaseTemplet.xml | 0
.../jira测试用例导入模板.xml | 0
.../auxiliary/work/n/tcase/AbstractCase.java | 5 -
.../pres/auxiliary/work/n/tcase/Case.java | 233 +++++++++
.../auxiliary/work/n/tcase/DataListCase.java | 15 +
.../work/n/tcase/InformationCase.java | 27 +
.../auxiliary/work/n/tcase/WriteTestCase.java | 19 +-
12 files changed, 667 insertions(+), 180 deletions(-)
rename ConfigurationFiles/CaseConfigurationFile/{ => FileTemplet}/CaseTemplet.xml (100%)
rename ConfigurationFiles/{NewCaseConfigurationFile => CaseConfigurationFile/FileTemplet}/jira测试用例导入模板.xml (100%)
delete mode 100644 src/main/java/pres/auxiliary/work/n/tcase/AbstractCase.java
create mode 100644 src/main/java/pres/auxiliary/work/n/tcase/Case.java
create mode 100644 src/main/java/pres/auxiliary/work/n/tcase/DataListCase.java
create mode 100644 src/main/java/pres/auxiliary/work/n/tcase/InformationCase.java
diff --git a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/AddInformation.xml b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/AddInformation.xml
index ccd1782..803d5af 100644
--- a/ConfigurationFiles/Ca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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/BrowseList.xml b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/BrowseList.xml
index 3636769..1df5308 100644
--- a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/BrowseList.xml
+++ b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/BrowseList.xml
@@ -1,6 +1,6 @@
-
+
@@ -23,7 +23,7 @@
-
+
@@ -48,7 +48,7 @@
-
+
@@ -69,7 +69,7 @@
-
+
@@ -92,7 +92,7 @@
-
+
@@ -117,7 +117,7 @@
-
+
@@ -136,7 +136,7 @@
-
+
@@ -159,7 +159,7 @@
-
+
@@ -177,7 +177,7 @@
-
+
@@ -192,7 +192,7 @@
-
+
diff --git a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Map.xml b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Map.xml
index 23f2aaa..5088915 100644
--- a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Map.xml
+++ b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Map.xml
@@ -1,6 +1,6 @@
-
+
@@ -26,7 +26,7 @@
-
+
@@ -43,7 +43,7 @@
-
+
@@ -64,7 +64,7 @@
-
+
@@ -87,7 +87,7 @@
-
+
diff --git a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Username.xml b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Username.xml
index 9a6c1c3..6395db6 100644
--- a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Username.xml
+++ b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Username.xml
@@ -1,6 +1,6 @@
-
+
@@ -14,7 +14,7 @@
-
+
@@ -36,7 +36,7 @@
-
+
@@ -55,7 +55,7 @@
-
+
@@ -72,7 +72,7 @@
-
+
@@ -100,7 +100,7 @@
-
+
@@ -122,7 +122,7 @@
-
+
@@ -146,7 +146,7 @@
-
+
@@ -172,7 +172,7 @@
-
+
diff --git a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Video.xml b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Video.xml
index 29017d0..a6f9598 100644
--- a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Video.xml
+++ b/ConfigurationFiles/CaseConfigurationFile/CaseTemplet/Video.xml
@@ -1,6 +1,6 @@
-
+
@@ -24,7 +24,7 @@
-
+
@@ -44,7 +44,7 @@
-
+
@@ -76,7 +76,7 @@
-
+
@@ -96,7 +96,7 @@
-
+
@@ -117,7 +117,7 @@
-
+
diff --git a/ConfigurationFiles/CaseConfigurationFile/CaseTemplet.xml b/ConfigurationFiles/CaseConfigurationFile/FileTemplet/CaseTemplet.xml
similarity index 100%
rename from ConfigurationFiles/CaseConfigurationFile/CaseTemplet.xml
rename to ConfigurationFiles/CaseConfigurationFile/FileTemplet/CaseTemplet.xml
diff --git a/ConfigurationFiles/NewCaseConfigurationFile/jira测试用例导入模板.xml b/ConfigurationFiles/CaseConfigurationFile/FileTemplet/jira测试用例导入模板.xml
similarity index 100%
rename from ConfigurationFiles/NewCaseConfigurationFile/jira测试用例导入模板.xml
rename to ConfigurationFiles/CaseConfigurationFile/FileTemplet/jira测试用例导入模板.xml
diff --git a/src/main/java/pres/auxiliary/work/n/tcase/AbstractCase.java b/src/main/java/pres/auxiliary/work/n/tcase/AbstractCase.java
deleted file mode 100644
index 16cfaf0..0000000
--- a/src/main/java/pres/auxiliary/work/n/tcase/AbstractCase.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package pres.auxiliary.work.n.tcase;
-
-public abstract class AbstractCase {
-
-}
diff --git a/src/main/java/pres/auxiliary/work/n/tcase/Case.java b/src/main/java/pres/auxiliary/work/n/tcase/Case.java
new file mode 100644
index 0000000..f1055ed
--- /dev/null
+++ b/src/main/java/pres/auxiliary/work/n/tcase/Case.java
@@ -0,0 +1,233 @@
+package pres.auxiliary.work.n.tcase;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+/**
+ * 文件名:AbstractCase.java
+ * 用途:定义测试用例模板类能返回的基本字段,提供其相应的get与set方法,但该方法不允许包外调用
+ * 编码时间:2020年3月3日下午8:07:23
+ * 修改时间:2020年3月4日 07:39:23
+ * @author 彭宇琦
+ * @version Ver1.0
+ * @since JDK 12
+ *
+ */
+public abstract class Case {
+
+ /**
+ * 步骤
+ */
+ private String[] step;
+
+ /**
+ * 预期
+ */
+ private String[] except;
+
+ /**
+ * 标题
+ */
+ private String title;
+
+ /**
+ * 关键词
+ */
+ private String keyWord;
+
+ /**
+ * 前置条件
+ */
+ private String[] precondition;
+
+ /**
+ * 用于存储需要替换的词语的开始标记
+ */
+ final String START_SIGN = "*{";
+ /**
+ * 用于存储需要替换的词语的结束标记
+ */
+ final String END_SIGN = "}*";
+
+ /**
+ * 优先级
+ */
+ private int rank;
+
+ /**
+ * 用于指向测试用例xml文件的Document对象
+ */
+ Document configXml;
+
+ /**
+ * 存储xml文件中其需要替换的词语
+ */
+ HashMap textMap = new HashMap();
+
+ /**
+ * 根据用例xml文件来构造Case类
+ * @param configXmlFile xml配置文件
+ * @throws IncorrectFileException 文件格式或路径不正确时抛出的异常
+ */
+ @SuppressWarnings("unchecked")
+ public Case(File configXmlFile) {
+ // 判断传入的configurationFile是否为一个文件类对象,若非文件类对象,则抛出异常
+ try {
+ configXml = new SAXReader().read(configXmlFile);
+ } catch (DocumentException e) {
+ throw new IncorrectFileException("用例xml文件有误" );
+ }
+
+ //获取xml中包含value的元素,并将其中包含需要替换的词语存储至textMap\
+ List textElement = configXml.selectNodes("//*[@value]");
+ textElement.stream().
+ //获取元素的value属性,将其转换为文本对象
+ map(e -> e.attributeValue("value")).
+ //筛选包含*{的文本
+ filter(e -> e.indexOf("*{") > -1).forEach(e -> {
+ //对文本按照*{切割,并筛选包含}*的文本
+ Arrays.asList(e.split("\\*\\{")).stream().filter(s -> s.indexOf("}*") > -1).
+ forEach(s -> {
+ //将需要存储的替换词语存入textMap中
+ textMap.put(s.substring(0, s.indexOf("}*")), "");
+ });
+ });
+ }
+
+ /**
+ * 返回步骤文本
+ * @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库中需要替换的词语
+ * @param value 被替换的词语
+ */
+ public void setReplaceWord(String word, String value) {
+ //判断该词语是否存在于textMap中,若不存在,则抛出异常
+ if (!textMap.containsKey(word)) {
+ throw new IncorrectFileException("未找到需要替换的词语:" + word);
+ }
+ //存储替换的词语
+ textMap.put(word, value);
+ }
+
+ /**
+ * 用于替换文本中需要替换的单词,返回替换后的文本
+ * @param text 需要替换的文本
+ * @return 替换后的文本
+ */
+ String replaceText(String text) {
+ StringBuilder sb = new StringBuilder(text);
+ //存储替换符的位置
+ int index = 0;
+ //循环,替换content中所有需要替换的信息
+ while( (index = sb.indexOf(START_SIGN)) != -1 ) {
+ //存储待替换的变量名
+ String var = sb.substring(index + START_SIGN.length(), sb.indexOf(END_SIGN));
+ //替换该变量名
+ sb.replace(index, sb.indexOf(END_SIGN) + END_SIGN.length(), textMap.get(var));
+ }
+
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/pres/auxiliary/work/n/tcase/DataListCase.java b/src/main/java/pres/auxiliary/work/n/tcase/DataListCase.java
new file mode 100644
index 0000000..452689d
--- /dev/null
+++ b/src/main/java/pres/auxiliary/work/n/tcase/DataListCase.java
@@ -0,0 +1,15 @@
+package pres.auxiliary.work.n.tcase;
+
+/**
+ * 文件名:DataListCase.java
+ * 用途:用于生成数据列表相关的测试用例
+ * 编码时间:2020年3月3日下午8:25:33
+ * 修改时间:2020年3月3日下午8:25:33
+ * @author
+ * @version Ver1.0
+ * @since JDK 12
+ *
+ */
+public class DataListCase extends Case {
+
+}
diff --git a/src/main/java/pres/auxiliary/work/n/tcase/InformationCase.java b/src/main/java/pres/auxiliary/work/n/tcase/InformationCase.java
new file mode 100644
index 0000000..63ada04
--- /dev/null
+++ b/src/main/java/pres/auxiliary/work/n/tcase/InformationCase.java
@@ -0,0 +1,27 @@
+package pres.auxiliary.work.n.tcase;
+
+import java.io.File;
+import java.util.HashMap;
+
+/**
+ * 文件名:InformationCase.java
+ * 用途:用于输出与页面新增或编辑信息相关的用例
+ * 编码时间:2020年3月5日上午8:30:12
+ * 修改时间:2020年3月5日上午8:30:12
+ * @author 彭宇琦
+ * @version Ver1.0
+ * @since JDK 12
+ */
+public class InformationCase extends Case {
+
+ /**
+ * 通过测试用例模板库的xml配置文件来构造InformationCase对象
+ * @param configXmlFile 用例模板库的xml文件对象
+ */
+ public InformationCase(File configXmlFile) {
+ super(configXmlFile);
+ }
+
+
+
+}
diff --git a/src/main/java/pres/auxiliary/work/n/tcase/WriteTestCase.java b/src/main/java/pres/auxiliary/work/n/tcase/WriteTestCase.java
index df7cc5a..70f87e2 100644
--- a/src/main/java/pres/auxiliary/work/n/tcase/WriteTestCase.java
+++ b/src/main/java/pres/auxiliary/work/n/tcase/WriteTestCase.java
@@ -43,7 +43,7 @@ import org.dom4j.io.SAXReader;
* 编码时间:2020年2月17日下午9:36:00
*
*
- * 修改时间:2020年2月17日下午9:36:00
+ * 修改时间:2020年3月3日下午8:07:23
*
*
* @author 彭宇琦
@@ -107,19 +107,16 @@ public class WriteTestCase {
* 只存在一个sheet标签时,则直接获取其对应sheet下所有column标签的id属性;若存在
* 多个sheet标签时,则读取第一个sheet标签,如需切换sheet标签,则可调用{@link #switchSheet(String)} 方法。
*
- * @param configurationFile 测试文件模板xml配置文件类对象
+ * @param configFile 测试文件模板xml配置文件类对象
* @param caseFile 测试用例文件类对象
- * @throws DocumentException xml文件内容不正确时抛出的异常
* @throws IncorrectFileException 文件格式或路径不正确时抛出的异常
*/
- public WriteTestCase(File configurationFile, File caseFile) throws DocumentException {
- // 判断传入的configurationFile是否为一个文件类对象,若非文件类对象,则抛出异常(isFile()方法包含判断文件是否存在)
- // 再判断文件是否包含文件路径是否包含“.xml”
- if (configurationFile.isFile() && configurationFile.getAbsolutePath().indexOf(".xml") > -1) {
- // 读取xml文件的信息
- configXml = new SAXReader().read(configurationFile);
- } else {
- throw new IncorrectFileException("不正确的文件格式:" + configurationFile.getAbsolutePath());
+ public WriteTestCase(File configFile, File caseFile) {
+ // 判断传入的configurationFile是否为一个文件类对象,若非文件类对象,则抛出异常
+ try {
+ configXml = new SAXReader().read(configFile);
+ } catch (DocumentException e) {
+ throw new IncorrectFileException("用例xml文件有误" );
}
// 获取xml文件中的第一个sheet标签,则将该标签的name属性内容传入getColumnId中