public abstract class AbstractCaseTemplet extends Object implements AddPlaceholder
文件名:CaseTemplet.java
用途:定义用例模板读取类的基础方法
编码时间:2023年1月13日 上午8:03:08
修改时间:2023年5月23日 下午3:05:00
Modifier and Type | Field and Description |
---|---|
protected Placeholder |
placeholder
存储xml文件中所有的占位符
|
protected String |
REPLACE_WORD_SIGN
标记用于需要替换的词语
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractCaseTemplet()
定义无参构造,方便子类使用
|
Modifier and Type | Method and Description |
---|---|
void |
addReplaceFunction(String regex,
DataFunction function)
用于添加待替换的词语及相应的替换方法
|
void |
addReplaceWord(String word,
String replaceWord)
该方法用于添加被替换的词语以及替换的内容
|
Placeholder |
getPlaceholder()
该方法用于返回当前存储的占位符类对象
|
protected final String REPLACE_WORD_SIGN
protected Placeholder placeholder
protected AbstractCaseTemplet()
public void addReplaceWord(String word, String replaceWord)
AddPlaceholder
addReplaceWord
in interface AddPlaceholder
word
- 需要替换的内容replaceWord
- 替换后的内容public void addReplaceFunction(String regex, DataFunction function)
AddPlaceholder
该方法允许添加待替换词语的处理方式,在写入用例时,若指定的待替换内容符合此方法指定的正则时,则会使用存储的替换方式,
对词语进行替换。例如,占位符前后标志均为“#”,则:
@Test
public void addReplaceWordTest_DataDriverFunction() {
// 定义词语匹配规则和处理方式,当匹配到正则后,将获取“随机:”后的字母
// 若字母为“N”,则随机生成两位数字字符串
// 若字母为“Y”,则随机生成两位中文字符串
test.addReplaceWord(new DataDriverFunction("随机:[NC]", text -> {
return "N".equals(text.split(":")[1]) ? RandomString.randomString(2, 2, StringMode.NUM)
: RandomString.randomString(2, 2, StringMode.CH);
}));
}
部分定义方法可调用工具类Functions
类获取,以其中一个方法为例,其传参方法为如下:
DataDriverFunction
driverFunction = Functions.randomCarId()
;
addReplaceFunction(DataDriverFunction.getRegex()
, DataDriverFunction.getFunction()
);
addReplaceFunction
in interface AddPlaceholder
regex
- 需要替换的内容正则表达式function
- 替换词语使用的函数public Placeholder getPlaceholder()
Copyright © 2024. All rights reserved.