1.随机生成邮箱
def getEmailAddressPrefixWithCurrentTime() {
Date date = new Date();
DateFormat dFormat3 = new SimpleDateFormat("yyyyMMddHHmms");
String formatDate = dFormat3.format(date);
return (formatDate.substring(4, 13)+"@test.com");
}
@Keyword
2.随机生成字符串加数字的字符串
def getRegisterFirstNameWithCurrentTime() {
Date date = new Date();
DateFormat dFormat3 = new SimpleDateFormat("MMddHHmms");
String formatDate = dFormat3.format(date);
return ("ceci"+formatDate.substring(0, 9));
}
3.随机生成不同长度的字符串
def getItemName(int length){
String base="zaqwsxcerfvbgtyhnmjuikolp";
Random random= new Random();
StringBuffer name= new StringBuffer();
for (int i=0;i<length;i++){
int number=random.nextInt(base.length());
name.append(base.charAt(number));
}
return name.toString();
}
4.根据xpath 得出相同层级的数量
def getProductQty(xpath){
WebDriver driver=DriverFactory.getWebDriver
List<WebElement> elements=driver.findElements(By.xpath(xpath))
int number=elements.size()
return number
}
5.存所需的变量
static List orderNumList = new ArrayList();
@Keyword
def saveOrderInfo(orderNumber){
orderNumList.add(orderNumber)
}
6.取之前存入的变量
@Keyword
def getOrderInfo(){
String orderIdResult=orderNumList.get((orderNumList.size-1));
println orderIdResult
return orderIdResult;
}
}
7.模拟js 点击目标
def clickUsingJS(TestObject to, int timeout) {
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = WebUiCommonHelper.findWebElement(to, timeout)
JavascriptExecutor executor = ((driver) as JavascriptExecutor)
executor.executeScript('arguments[0].click()', element)
}