String methodName = new Object(){}.getClass().getEnclosingMethod().getName();
(OR)
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
String methodName = new Object(){}.getClass().getEnclosingMethod().getName();
(OR)
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
//Example '(866) 825-3227' then you can use below regular expression
public static boolean validatePhone(String phone) {
String phonePattern = "\\([0-9]{3}) [0-9]{3}\\-[0-9]{4}";
// e.g. (866) 825-3227
Pattern pattern = Pattern.compile(phonePattern);
Matcher matcher = pattern.matcher(phone);
return matcher.matches();
}
public void resize(WebElement elementToResize, int xOffset, int yOffset) {
try {
if (elementToResize.isDisplayed()) {
Actions action = new Actions(driver);
action.clickAndHold(elementToResize).moveByOffset(xOffset, yOffset).release().build().perform();
} else {
System.out.println("Element was not displayed to drag");
}
} catch (StaleElementReferenceException e) {
System.out.println("Element with " + elementToResize + "is not attached to the page document " + e.getStackTrace());
} catch (NoSuchElementException e) {
System.out.println("Element " + elementToResize + " was not found in DOM " + e.getStackTrace());
} catch (Exception e) {
System.out.println("Unable to resize" + elementToResize + " - " + e.getStackTrace());
}
}
moveToElement(WebElement toElement, int xOffset, int yOffset)
Moves the mouse to an offset from the top-left corner of the element.
Actions builder = new Actions(driver);
builder.moveToElement(knownElement, 10, 25).click().build().perform();