public class OFFOn { // ... public static void verifySnackbarText(WebDriver driver, String expectedText) { String snackbarText = driver.findElement(By.id("ir.mci.ecareapp:id/snackbar_text")).getText(); if (snackbarText.equals(expectedText)) { System.out.println("Pass"); } else { String pageName = getExecutingClassName(); Screenshot.takeScreenshotIfSnackbarVisible(driver, pageName); System.out.println("Fail"); Assert.fail("Test failed"); } } private static String getExecutingClassName() { try { // Get the current stack trace StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); // Find the method that called the verifySnackbarText method for (int i = 0; i < stackTrace.length; i++) { if (stackTrace[i].getMethodName().equals("verifySnackbarText")) { // Get the class name of the calling method String className = stackTrace[i + 1].getClassName(); // Extract the simple class name (without package name) int lastIndex = className.lastIndexOf('.'); if (lastIndex != -1) { className = className.substring(lastIndex + 1); } return className; } } } catch (Exception e) { e.printStackTrace(); } return ""; } } /////////////////////////////// OFFOn.verifySnackbarText(driver, "عملیات موفقیت آمیز");