public abstract class AbstractSikuliLocation extends Object implements AddPlaceholder
文件名:AbstractSikuliLocation.java
用途: 定义读取并返回元素信息相关的基本方法
编码时间:2021年12月27日 上午8:29:45
修改时间:2022年2月10日 上午9:02:09
Modifier and Type | Field and Description |
---|---|
protected int |
DEFAULT_WAIT_TIME
定义默认等待时间
|
protected List<ElementLocationInfo> |
elementInfoList
存储元素信息集合,建议将该数据进行缓存,以减少不必要的麻烦处理
|
static String |
FORMAT_FILE_PATH
定义元素路径信息拼接的格式
|
static String |
FORMAT_REPLACE_REGEX
定义元素占位符替换规则格式
|
static String |
MATCH_END_SIGN
定义用于正则的默认替换符结束标记
|
static String |
MATCH_START_SIGN
定义用于正则的默认替换符开始标记
|
protected String |
name
存储当前查找的元素名称
|
protected Placeholder |
placeholder
占位符类对象
|
Constructor and Description |
---|
AbstractSikuliLocation() |
Modifier and Type | Method and Description |
---|---|
void |
addReplaceFunction(String regex,
DataFunction function)
用于添加待替换的词语及相应的替换方法
|
void |
addReplaceWord(String word,
String replaceWord)
该方法用于添加被替换的词语以及替换的内容
|
protected boolean |
compareElementName(String name)
该方法用于对当前的元素名称与传入的元素名称进行对比,判断是否一致,并返回是否判断结果
|
protected abstract AbstractSikuliLocation |
find(String name)
该方法用于查找并缓存指定的元素
|
abstract List<ElementLocationInfo> |
getElementLocationList(String name)
该方法用于返回元素的信息
|
String |
getEndElementPlaceholder()
该方法用于返回元素占位符结束标识
|
String |
getStartElementPlaceholder()
该方法用于返回元素占位符起始标识
|
abstract int |
getWaitTime(String name)
该方法用于返回元素的查找等待时间
|
void |
setElementPlaceholder(String startSign,
String endSign)
该方法用于设置自定义的元素占位符标识
|
public static final String MATCH_START_SIGN
public static final String MATCH_END_SIGN
public static final String FORMAT_FILE_PATH
public static final String FORMAT_REPLACE_REGEX
protected Placeholder placeholder
protected List<ElementLocationInfo> elementInfoList
protected final int DEFAULT_WAIT_TIME
protected String name
protected abstract AbstractSikuliLocation find(String name)
name
- 元素名称public void setElementPlaceholder(String startSign, String endSign)
注意:该方法接收的标识符是正则表达式,若传入的标识符为特殊符号(如:*),则需要使用双反斜杠来转义(如:\\*)
startSign
- 占位符起始标识endSign
- 占位符结束标识public String getStartElementPlaceholder()
public String getEndElementPlaceholder()
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 abstract List<ElementLocationInfo> getElementLocationList(String name)
name
- 元素名称public abstract int getWaitTime(String name)
注意:当没有等待时间或等待时间小于0时,则返回默认等待时间“DEFAULT_WAIT_TIME
”
name
- 元素名称protected boolean compareElementName(String name)
注意:该方法可对传入的元素名称是否为空进行判断,为空时将抛出UndefinedElementException
异常
name
- 元素名称UndefinedElementException
- 当传入的元素名称为空时,抛出的异常Copyright © 2024. All rights reserved.