diff --git a/Test/ReadXml/测试文件.xml b/Test/ReadXml/测试文件.xml
new file mode 100644
index 0000000..d99f92e
--- /dev/null
+++ b/Test/ReadXml/测试文件.xml
@@ -0,0 +1,19 @@
+
+
+
+ //iframe[contains(@src,'${src}')]
+ //li[text()='${mon}']
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/pres/auxiliary/tool/randomstring/MobleNumberType.java b/src/main/java/pres/auxiliary/tool/randomstring/MobleNumberType.java
new file mode 100644
index 0000000..ee6a9ca
--- /dev/null
+++ b/src/main/java/pres/auxiliary/tool/randomstring/MobleNumberType.java
@@ -0,0 +1,43 @@
+package pres.auxiliary.tool.randomstring;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public enum MobleNumberType {
+ /**
+ * 中国电信运营商号码段
+ */
+ CHINA_TELECOM(133, 1349, 149, 153, 162, 1700, 1701, 1702, 173, 17400, 17401, 17402, 17403, 17404, 17405, 177, 180, 181, 189, 191, 193, 199),
+ /**
+ * 中国移动运营商号码段
+ */
+ CHINA_MOBILE(1340, 1341, 1342, 1343, 1344, 1345, 1346, 135, 136, 137, 138, 139, 147, 148, 150, 151, 152, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 158, 159, 165, 1703, 1705, 1706, 172, 178, 182, 183, 184, 187, 188, 198),
+ /**
+ * 中国联通运营商号码段
+ */
+ CHINA_UNICOM(130, 131, 132, 145, 146, 155, 156, 166, 167, 1704, 1707, 1708, 1709, 171, 175, 176, 185, 186);
+
+ /**
+ * 用于表示当前运营商号码段正则表达式
+ */
+ ArrayList numberList = new ArrayList<>();
+
+ /**
+ * 用于初始化数据
+ * @param nums 号码段
+ */
+ private MobleNumberType(int...nums) {
+ //添加数据
+ Arrays.stream(nums).forEach(num -> {
+ numberList.add(String.valueOf(num));
+ });
+ }
+
+ /**
+ * 用于返回运营商号码段
+ * @return 号码段
+ */
+ public ArrayList getRegex() {
+ return numberList;
+ }
+}
diff --git a/src/main/java/pres/auxiliary/tool/randomstring/PresetString.java b/src/main/java/pres/auxiliary/tool/randomstring/PresetString.java
index 3f33f7c..4807f28 100644
--- a/src/main/java/pres/auxiliary/tool/randomstring/PresetString.java
+++ b/src/main/java/pres/auxiliary/tool/randomstring/PresetString.java
@@ -110,33 +110,47 @@ public class PresetString {
* @return 生成的身份证号码
*/
public static String IdentityCard() {
- String s = "45030119";
-
- rs.clear();
- rs.addMode(StringMode.NUM);
- s += rs.toString(2);
-
- Random r = new Random();
-
- // 生成月
- int i = (1 + r.nextInt(11));
- // 判断生成的随机字符串是否小于10,小于10则向s中补全一个0
- if (i < 10) {
- s += "0";
+ StringBuilder sb = new StringBuilder();
+ RandomString rs = new RandomString("123456789");
+
+ //省份
+ int[] province = {13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91};
+ //城市
+ String[] city = {"01", "02", "03"};
+ //区县
+ String[] county = {"01", "02", "03", "04", "05"};
+ //生日年份前两位
+ int[] year = {19, 18};
+
+ //加权数
+ int[] factors = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
+ //校验位
+ String[] parity = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
+
+ //随机添加一个省份
+ sb.append(province[new Random().nextInt(province.length)]);
+ //随机添加一个城市
+ sb.append(city[new Random().nextInt(city.length)]);
+ //随机添加一个区县
+ sb.append(county[new Random().nextInt(county.length)]);
+ //随机生日年份
+ sb.append(year[new Random().nextInt(year.length)]).append(rs.toString(2));
+ //随机生日月份及日子
+ sb.append("0" + rs.toString(1)).append("0" + rs.toString(1));
+ //随机三位数
+ sb.append(rs.toString(3));
+
+ //计算加权数
+ int sum = 0;
+ for (int i = 0; i < 17; i++) {
+ int code = Integer.valueOf(sb.substring(i, i + 1));
+ int factor = Integer.valueOf(factors[i]);
+ sum += (code * factor);
}
- s += i;
-
- // 生成日
- i = (1 + r.nextInt(27));
- // 判断生成的随机字符串是否小于10,小于10则向s中补全一个0
- if (i < 10) {
- s += "0";
- }
- s += i;
-
- s += rs.toString(4);
-
- return s;
+ //根据加权数添加校验位
+ sb.append(parity[(sum % 11)]);
+
+ return sb.toString();
}
/**
@@ -176,6 +190,9 @@ public class PresetString {
return s;
}
+ }
+
+ private static String getMobleNumber(MobleNumberType mobleNumberType) {
}
diff --git a/src/main/java/pres/auxiliary/tool/randomstring/RandomWord.java b/src/main/java/pres/auxiliary/tool/randomstring/RandomWord.java
new file mode 100644
index 0000000..9573607
--- /dev/null
+++ b/src/main/java/pres/auxiliary/tool/randomstring/RandomWord.java
@@ -0,0 +1,127 @@
+package pres.auxiliary.tool.randomstring;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Random;
+
+public class RandomWord {
+ /**
+ * 用于存储需要随机返回的词语
+ */
+ private ArrayList returnWordList = new ArrayList<>();
+ /**
+ * 用于存储默认返回的词语
+ */
+ private ArrayList conditionWordList = new ArrayList<>();
+
+ /**
+ * 指向生成的词语是否能重复
+ */
+ private boolean isRepeat = true;
+
+ /**
+ * 用于向无需条件亦可直接返回的词语组中添加词语
+ * @param words 词语组
+ */
+ public void addRetuenWord(String...words) {
+ returnWordList.addAll(Arrays.asList(words));
+ }
+
+ /**
+ * 用于向无需条件亦可直接返回的词语组中添加词语
+ * @param wordLst 词语集合
+ */
+ public void addRetuenWord(ArrayList wordLst) {
+ conditionWordList.addAll(wordLst);
+ }
+
+ /**
+ * 用于向符合条件后返回的词语组中添加词语
+ * @param words 词语组
+ */
+ public void addConditionWord(String...words) {
+ conditionWordList.addAll(Arrays.asList(words));
+ }
+
+ /**
+ * 用于向符合条件后返回的词语组中添加词语
+ * @param wordLst 词语集合
+ */
+ public void addConditionWord(ArrayList wordLst) {
+ returnWordList.addAll(wordLst);
+ }
+
+ /**
+ * 用于设置词语是否可以重复生成
+ * @param isRepeat 词语是否可重复
+ */
+ public void setRepeat(boolean isRepeat) {
+ this.isRepeat = isRepeat;
+ }
+
+ /**
+ * 用于随机生成指定随机个数的词语
+ * @param minLength 最少词语个数
+ * @param maxLength 最多词语个数
+ * @return 生成的词语集合
+ */
+ public ArrayList toWord(int minLength, int maxLength) {
+ return toWord(getLength(minLength, maxLength));
+ }
+
+ /**
+ * 用于随机生成指定个数的词语
+ * @param length 输出的词语个数
+ * @return 生成的词语集合
+ */
+ public ArrayList toWord(int length) {
+ //克隆returnWordList,便于对不能生成重复词语的情况下,移除集合中的元素,达到快速返回的目的
+ @SuppressWarnings("unchecked")
+ ArrayList wordList = (ArrayList) returnWordList.clone();
+
+ //存储生成的词语
+ ArrayList randomWordList = new ArrayList<>();
+ //循环,生成相应的词语
+ for (int i = 0; i < length; i++) {
+ //获取随机下标
+ int index = getRandomIndex(wordList);
+ //存储下标对应的词语
+ randomWordList.add(wordList.get(index));
+ //若生成的词语不可重复,则直接移除wordList中对应的词语
+ if (!isRepeat) {
+ wordList.remove(index);
+ }
+ }
+
+ return wordList;
+ }
+
+ /**
+ * 用于根据词语是否允许重复,返回实际的最大生成词语个数
+ * @param maxLength 设置的最大词语生成个数
+ * @return 实际最大词语生成个数
+ */
+ private int getLength(int minLength, int maxLength) {
+ //若词语不允许重复生成且maxLength大于returnWordList.size(),则将maxLength改为maxLength
+ maxLength = (isRepeat && maxLength > returnWordList.size()) ? returnWordList.size() : maxLength;
+ //为避免最小长度与最大长度传参相反,故此处进行一个调换
+ int max = Math.max(minLength, maxLength);
+ int min = Math.min(minLength, maxLength);
+
+ //返回指定长度下的一个随机长度
+ return (new Random().nextInt(max - min + 1) + min);
+ }
+
+ /**
+ * 根据指定的集合,返回随机的一个下标
+ * @param wordList 词语集合
+ * @return 集合元素的随机下标
+ */
+ private int getRandomIndex(ArrayList wordList) {
+ //根据条件获取集合的长度
+ int maxLength = wordList.size();
+ //生成最大长度范围内的随机数
+ return new Random().nextInt(maxLength);
+
+ }
+}
diff --git a/src/main/java/pres/auxiliary/work/selenium/datadriven/ListFileRead.java b/src/main/java/pres/auxiliary/work/selenium/datadriven/ListFileRead.java
index 7302e7a..8b5abbd 100644
--- a/src/main/java/pres/auxiliary/work/selenium/datadriven/ListFileRead.java
+++ b/src/main/java/pres/auxiliary/work/selenium/datadriven/ListFileRead.java
@@ -137,9 +137,9 @@ public class ListFileRead {
columnIndex = columnIndex < 0 ? 0 : columnIndex;
//若传值大于最大maxRowNum时,则直接赋予maxRowNum
- startRowIndex = (startRowIndex >= maxRowNum) ? maxRowNum - 1 : startRowIndex;
+ startRowIndex = (startRowIndex >= maxRowNum) ? maxRowNum : startRowIndex;
startRowIndex = startRowIndex < 0 ? 0 : startRowIndex;
- endRowIndex = (endRowIndex >= maxRowNum) ? maxRowNum - 1 : endRowIndex;
+ endRowIndex = (endRowIndex >= maxRowNum) ? maxRowNum : endRowIndex;
endRowIndex = endRowIndex < 0 ? 0 : endRowIndex;
//若两个传值相同,则endRowIndex+1
@@ -185,9 +185,9 @@ public class ListFileRead {
endColumnIndex = endColumnIndex < 0 ? 0 : endColumnIndex;
//若传值大于最大maxRowNum时,则直接赋予maxRowNum,小于0,则直接赋予0
- startRowIndex = (startRowIndex >= maxRowNum) ? maxRowNum - 1 : startRowIndex;
+ startRowIndex = (startRowIndex >= maxRowNum) ? maxRowNum : startRowIndex;
startRowIndex = startRowIndex < 0 ? 0 : startRowIndex;
- endRowIndex = (endRowIndex >= maxRowNum) ? maxRowNum - 1 : endRowIndex;
+ endRowIndex = (endRowIndex >= maxRowNum) ? maxRowNum : endRowIndex;
endRowIndex = endRowIndex < 0 ? 0 : endRowIndex;
//若两个传值相同,则endXXXIndex+1
diff --git a/src/main/java/pres/auxiliary/work/selenium/datadriven/NumberDataDriven.java b/src/main/java/pres/auxiliary/work/selenium/datadriven/NumberDataDriven.java
deleted file mode 100644
index a1b3317..0000000
--- a/src/main/java/pres/auxiliary/work/selenium/datadriven/NumberDataDriven.java
+++ /dev/null
@@ -1,169 +0,0 @@
-package pres.auxiliary.work.selenium.datadriven;
-
-public class NumberDataDriven extends DataDriven {
-// /**
-// * 无参构造,不做任何操作,请使用{@link #setDataFile(File)}方法定义数据驱动文件
-// */
-// public NumberDataDriven() {
-// super();
-// }
-//
-// /**
-// * 用于指定数据驱动文件
-// *
-// * @param dataFile
-// * 数据驱动文件对象
-// */
-// public NumberDataDriven(File dataFile) {
-// super(dataFile);
-// }
-//
-// @Override
-// public File createDataFile(String saveFileName, int minSize, int maxSize, int length) throws IOException {
-// //用于存储生成的字符
-// StringBuilder sb = new StringBuilder("");
-// // 循环,向文件中添加随机数字
-// for (int i = 0; i < length; i++) {
-// // 添加随机数字
-// sb.append(new RandomString(StringMode.NUM).toString(minSize, maxSize));
-// sb.append("\r\n");
-// }
-// //删除最后一个换行符
-// sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + "\r\n".length());
-//
-// // 返回数据驱动文件
-// return createDataFile(saveFileName, sb);
-// }
-//
-// @Override
-// public File createDataFile(String saveFileName, int size, int length) throws IOException {
-// //用于存储生成的字符
-// StringBuilder sb = new StringBuilder("");
-// // 循环,向文件中添加随机数字
-// for (int i = 0; i < length; i++) {
-// // 添加随机数字
-// sb.append(new RandomString(StringMode.NUM).toString(size));
-// sb.append("\r\n");
-// }
-// //删除最后一个换行符
-// sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + "\r\n".length());
-//
-// // 返回数据驱动文件
-// return createDataFile(saveFileName, sb);
-// }
-//
-// /**
-// * 该方法用于从数字1开始,每次增加1步长来生成自然顺序的数字,并写入文件中
-// *
-// * @param saveFileName
-// * 数据驱动文件的文件名,若为空或为null,则默认为NewDataDriven(文件的后缀为.txt)
-// * @param length
-// * 数据生成个数
-// * @return 生成的数据驱动文件对象
-// * @throws IOException
-// *
-// * @see #createDataFile(String, int, int)
-// * @see #createDataFile(String, int, int, int)
-// */
-// public File createContinuesNumberDataFile(String saveFileName, int length) throws IOException {
-// //用于存储生成的字符
-// StringBuilder sb = new StringBuilder("");
-// // 循环,向文件中添加随机数字
-// for (int i = 1; i < length + 1; i++) {
-// // 添加随机数字
-// sb.append("" + i);
-// sb.append("\r\n");
-// }
-// //删除最后一个换行符
-// sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + "\r\n".length());
-//
-// // 返回数据驱动文件
-// return createDataFile(saveFileName, sb);
-// }
-//
-// /**
-// * 该方法用于根据起始数字,通过增加一定的步长来生成自然顺序的数字,并写入文件中
-// *
-// * @param saveFileName
-// * 数据驱动的文件名
-// * @param startNum
-// * 起始数字
-// * @param step
-// * 步长
-// * @param length
-// * 生成数字的个数
-// * @return 数据驱动文件对象
-// * @throws IOException
-// */
-// public File createContinuesNumberDataFile(String saveFileName, int startNum, int step, int length)
-// throws IOException {
-// //用于存储生成的字符
-// StringBuilder sb = new StringBuilder("");
-// // 循环,向文件中添加随机数字
-// for (int i = 0; i < length; i++) {
-// // 添加随机数字
-// sb.append("" + startNum);
-// sb.append("\r\n");
-//
-// // 数字增加一步
-// startNum += step;
-// }
-// //删除最后一个换行符
-// sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + "\r\n".length());
-//
-// // 返回数据驱动文件
-// return createDataFile(saveFileName, sb);
-// }
-//
-// /**
-// * 该方法用于向文件中添加身份证信息
-// *
-// * @param saveFileName
-// * 数据驱动的文件名
-// * @param length
-// * 生成身份证的个数
-// * @return 数据驱动文件对象
-// * @throws IOException
-// */
-// public File createIDCardDataFile(String saveFileName, int length) throws IOException {
-// //用于存储生成的字符
-// StringBuilder sb = new StringBuilder("");
-// // 循环,向文件中添加随机数字
-// for (int i = 0; i < length; i++) {
-// // 添加随机数字
-// sb.append(PresetString.IdentityCard());
-// sb.append("\r\n");
-// }
-// //删除最后一个换行符
-// sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + "\r\n".length());
-//
-// // 返回数据驱动文件
-// return createDataFile(saveFileName, sb);
-// }
-//
-// /**
-// * 该方法用于向文件中添加手机号码信息
-// *
-// * @param saveFileName
-// * 数据驱动的文件名
-// * @param length
-// * 生成手机号码的个数
-// * @return 数据驱动文件对象
-// * @throws IOException
-// */
-// public File createPhoneDataFile(String saveFileName, int length) throws IOException {
-// //用于存储生成的字符
-// StringBuilder sb = new StringBuilder("");
-// // 循环,向文件中添加随机数字
-// for (int i = 0; i < length; i++) {
-// // 添加随机数字
-// sb.append("139" + new RandomString(StringMode.NUM).toString(8));
-// sb.append("\r\n");
-// }
-// //删除最后一个换行符
-// sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + "\r\n".length());
-//
-// // 返回数据驱动文件
-// return createDataFile(saveFileName, sb);
-// }
-}
diff --git a/src/main/java/pres/auxiliary/work/selenium/datadriven/StringDataDriven.java b/src/main/java/pres/auxiliary/work/selenium/datadriven/StringDataDriven.java
deleted file mode 100644
index a769416..0000000
--- a/src/main/java/pres/auxiliary/work/selenium/datadriven/StringDataDriven.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package pres.auxiliary.work.selenium.datadriven;
-
-public class StringDataDriven extends DataDriven {
-
- /*
- @Override
- public File createDataFile(String saveFileName, int minSize, int maxSize, int length) throws IOException, DataNotFoundException {
- // 用于存储生成的字符
- StringBuilder sb = new StringBuilder("");
- // 循环,向文件中添加随机数字
- for (int i = 0; i < length; i++) {
- // 添加随机字母
- sb.append(new RandomString(StringMode.LOW, StringMode.CAP).toString(minSize, maxSize));
- sb.append("\r\n");
- }
- // 删除最后一个换行符
- sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + "\r\n".length());
-
- // 返回数据驱动文件
- return createDataFile(saveFileName, sb);
- }
-
- @Override
- public File createDataFile(String saveFileName, int size, int length) throws IOException {
- // 用于存储生成的字符
- StringBuilder sb = new StringBuilder("");
- // 循环,向文件中添加随机数字
- for (int i = 0; i < length; i++) {
- // 添加随机数字
- sb.append(new RandomString(StringMode.LOW, StringMode.CAP).toString(size));
- sb.append("\r\n");
- }
- // 删除最后一个换行符
- sb.delete(sb.lastIndexOf("\r\n"), sb.lastIndexOf("\r\n") + "\r\n".length());
-
- // 返回数据驱动文件
- return createDataFile(saveFileName, sb);
- }
- */
-
-}
diff --git a/src/main/java/pres/auxiliary/work/selenium/datadriven/TestNGDataDriver.java b/src/main/java/pres/auxiliary/work/selenium/datadriven/TestNGDataDriver.java
index 1664e94..48c1355 100644
--- a/src/main/java/pres/auxiliary/work/selenium/datadriven/TestNGDataDriver.java
+++ b/src/main/java/pres/auxiliary/work/selenium/datadriven/TestNGDataDriver.java
@@ -55,7 +55,8 @@ public class TestNGDataDriver {
/**
* 用于存储读取到的数据
*/
- private ArrayList dataList = new ArrayList<>();
+// private ArrayList dataList = new ArrayList<>();
+ private HashMap> dataMap = new HashMap<>(16);
/**
* 用于存储自定义的公式
@@ -67,6 +68,11 @@ public class TestNGDataDriver {
*/
private Time time = new Time();
+ /**
+ * 用于存储最大列的元素个数
+ */
+ private int maxColumnSize = -1;
+
/**
* 构造类,并将默认的数据驱动函数({@link Functions})加载至类中
*/
@@ -124,11 +130,14 @@ public class TestNGDataDriver {
public void addDataDriver(File dataFile, String pattern, boolean isFirstTitle) throws IOException {
//读取文件内的数据
ListFileRead data = new ListFileRead(dataFile, pattern);
- //由于数据按照列的形式读取,故此处将数据转置
- data.tableTransposition();
+ //获取当前标题行的总数
+ int titleIndex = titleList.size();
- //若设定首行为标题行,则根据首行元素读取标题
+ //若设定首行为标题行,则根据首行元素读取标题;若首行非标题行,则以列数进行命名
if (isFirstTitle) {
+ //将读取到的数据转置,得到以行的形式存储数据
+ data.tableTransposition();
+ //此时,返回data中第一列元素即为标题行的元素
//定位到首行
List dataTitleList = data.getColumn(0);
@@ -148,22 +157,44 @@ public class TestNGDataDriver {
titleList.add(title);
}
}
+ //存储标题后再重新转置,使data以列的形式进行返回
+ data.tableTransposition();
+ } else {
+ //若首行不是标题行,则获取data的最大列,按照“元素列 + 行号”的形式进行命名
+ for (int index = 0; index < data.getMaxColumnNumber(); index++) {
+ titleList.add("元素列" + (titleIndex + index));
+ }
}
//遍历所有行,读取所有的数据
- for (int rowIndex = isFirstTitle ? 1 : 0; rowIndex < data.getMaxColumnNumber(); rowIndex++) {
- addFileRowData(isFirstTitle ? rowIndex - 1 : rowIndex, data.getColumn(rowIndex));
+ for (int columnIndex = 0; columnIndex < data.getMaxColumnNumber(); columnIndex++) {
+ //将List转换为List