public abstract class AbstractLocation extends Object implements ReadLocation, AddPlaceholder
文件名:AbstractReadConfig.java
用途: 定义读取自动化测试中元素定位方式的基本方法
编码时间:2020年9月28日上午7:37:00
修改时间:2023年5月24日 下午5:46:55
Modifier and Type | Field and Description |
---|---|
static String |
END_SIGN
定义替换符结束标志
|
protected String |
name
元素名称
|
protected Placeholder |
placeholder
占位符类对象
|
static String |
START_SIGN
定义替换符开始标志
|
Constructor and Description |
---|
AbstractLocation() |
Modifier and Type | Method and Description |
---|---|
void |
addReplaceFunction(String regex,
DataFunction function)
用于添加待替换的词语及相应的替换方法
|
void |
addReplaceWord(String word,
String replaceWord)
该方法用于添加被替换的词语以及替换的内容
|
String |
getEndElementPlaceholder()
该方法用于返回元素占位符结束标识
|
Placeholder |
getPlaceholder()
该方法用于返回占位符类对象
|
String |
getStartElementPlaceholder()
该方法用于返回元素占位符起始标识
|
void |
setElementPlaceholder(String startSign,
String endSign)
该方法用于设置自定义的元素占位符标识
|
protected ElementType |
toElementType(String value)
用于将读取到的元素类型的文本值转换为元素类型枚举类对象
|
protected long |
toWaitTime(String text)
用于对等待时间进行转换
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
find, getBeforeTime, getElementLocation, getElementType, getIframeNameList, getWaitTime
public static final String START_SIGN
public static final String END_SIGN
protected Placeholder placeholder
protected String name
public void setElementPlaceholder(String startSign, String endSign)
ReadLocation
注意:该方法接收的标识符是正则表达式,若传入的标识符为特殊符号(如:*),则需要使用双反斜杠来转义(如:\\*)
setElementPlaceholder
in interface ReadLocation
startSign
- 占位符起始标识endSign
- 占位符结束标识public String getStartElementPlaceholder()
ReadLocation
getStartElementPlaceholder
in interface ReadLocation
public String getEndElementPlaceholder()
ReadLocation
getEndElementPlaceholder
in interface ReadLocation
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()
ReadLocation
getPlaceholder
in interface ReadLocation
protected ElementType toElementType(String value)
value
- 元素类型文本值protected long toWaitTime(String text)
text
- 获取的文本Copyright © 2024. All rights reserved.