public interface AddPlaceholder
文件名:AddPlaceholder.java
用途:定义使用占位符工具的类必须实现的方法
编码时间:2023年5月23日 下午3:09:39
修改时间:2023年5月23日 下午3:09:39
Modifier and Type | Method and Description |
---|---|
void |
addReplaceFunction(String regex,
DataFunction function)
用于添加待替换的词语及相应的替换方法
|
void |
addReplaceWord(String word,
String replaceWord)
该方法用于添加被替换的词语以及替换的内容
|
void addReplaceWord(String word, String replaceWord)
word
- 需要替换的内容replaceWord
- 替换后的内容void addReplaceFunction(String regex, DataFunction function)
该方法允许添加待替换词语的处理方式,在写入用例时,若指定的待替换内容符合此方法指定的正则时,则会使用存储的替换方式,
对词语进行替换。例如,占位符前后标志均为“#”,则:
@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()
);
regex
- 需要替换的内容正则表达式function
- 替换词语使用的函数Copyright © 2024. All rights reserved.