diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 2bb6b66..046d4b1 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,9 @@
+v2.4.5
+======
+Sep 07, 2024
+* Optimize method in WebUI keyword
+* Remove handle QR Code (google.zxing)
+
v2.4.4
======
Sep 05, 2024
diff --git a/docs/com/anhtester/helpers/Helpers.html b/docs/com/anhtester/helpers/Helpers.html
index 09c5872..c518808 100644
--- a/docs/com/anhtester/helpers/Helpers.html
+++ b/docs/com/anhtester/helpers/Helpers.html
@@ -73,7 +73,7 @@
Class Helpers
java.lang.Object
-
com.anhtester.helpers.Helpers
+
com.anhtester.helpers.SystemHelpers
diff --git a/docs/com/anhtester/helpers/class-use/Helpers.html b/docs/com/anhtester/helpers/class-use/Helpers.html
index ed6e64a..9c307ef 100644
--- a/docs/com/anhtester/helpers/class-use/Helpers.html
+++ b/docs/com/anhtester/helpers/class-use/Helpers.html
@@ -2,7 +2,7 @@
-Uses of Class com.anhtester.helpers.Helpers
+Uses of Class com.anhtester.helpers.SystemHelpers
@@ -49,9 +49,9 @@
-No usage of com.anhtester.helpers.Helpers
+No usage of com.anhtester.helpers.SystemHelpers
diff --git a/pom.xml b/pom.xml
index 5eb1a0e..0ee2bd7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.anhtester
anhtester-selenium-java
- 2.4.4
+ 2.4.5
AutomationFrameworkSelenium
https://github.com/anhtester/AutomationFrameworkSelenium
Test Automation Framework Selenium Java with TestNG building by Anh Tester
@@ -31,7 +31,7 @@
1.9.22.1
1.5.4
2.23.1
- 2.0.13
+ 2.0.16
2.29.0
2.30.0
2.13.0
@@ -47,7 +47,6 @@
2.3.1
0.7.7.0
8.0.33
- 3.5.3
1.18.34
33.3.0-jre
1.6.2
@@ -283,19 +282,6 @@
${mysql-connector-java.version}
-
-
- com.google.zxing
- javase
- ${google.zxing.version}
-
-
-
- com.google.zxing
- core
- ${google.zxing.version}
-
-
org.aspectj
diff --git a/src/main/java/com/anhtester/constants/FrameworkConstants.java b/src/main/java/com/anhtester/constants/FrameworkConstants.java
index 654ac90..aee5ec9 100644
--- a/src/main/java/com/anhtester/constants/FrameworkConstants.java
+++ b/src/main/java/com/anhtester/constants/FrameworkConstants.java
@@ -5,7 +5,7 @@
package com.anhtester.constants;
-import com.anhtester.helpers.Helpers;
+import com.anhtester.helpers.SystemHelpers;
import com.anhtester.helpers.PropertiesHelpers;
import com.anhtester.utils.ReportUtils;
@@ -20,7 +20,7 @@ private FrameworkConstants() {
PropertiesHelpers.loadAllFiles();
}
- public static final String PROJECT_PATH = Helpers.getCurrentDir();
+ public static final String PROJECT_PATH = SystemHelpers.getCurrentDir();
public static final String EXCEL_DATA_FILE_PATH = PropertiesHelpers.getValue("EXCEL_DATA_FILE_PATH");
public static final String JSON_DATA_FILE_PATH = PropertiesHelpers.getValue("JSON_DATA_FILE_PATH");
public static final String EXCEL_CMS_LOGIN = PropertiesHelpers.getValue("EXCEL_CMS_LOGIN");
diff --git a/src/main/java/com/anhtester/helpers/CaptureHelpers.java b/src/main/java/com/anhtester/helpers/CaptureHelpers.java
index 3536e1b..de19307 100644
--- a/src/main/java/com/anhtester/helpers/CaptureHelpers.java
+++ b/src/main/java/com/anhtester/helpers/CaptureHelpers.java
@@ -92,7 +92,7 @@ public static void stopRecord() {
public static void captureScreenshot(WebDriver driver, String screenName) {
try {
- String path = Helpers.getCurrentDir() + FrameworkConstants.EXPORT_CAPTURE_PATH;
+ String path = SystemHelpers.getCurrentDir() + FrameworkConstants.EXPORT_CAPTURE_PATH;
File file = new File(path);
if (!file.exists()) {
LogUtils.info("No Folder: " + path);
@@ -124,7 +124,7 @@ public static File getScreenshotFile(String screenshotName) {
throw new RuntimeException(e);
}
- String path = Helpers.getCurrentDir() + FrameworkConstants.EXTENT_REPORT_FOLDER + File.separator + "images";
+ String path = SystemHelpers.getCurrentDir() + FrameworkConstants.EXTENT_REPORT_FOLDER + File.separator + "images";
File folder = new File(path);
if (!folder.exists()) {
folder.mkdir();
@@ -151,7 +151,7 @@ public static String getScreenshotRelativePath(String screenshotName) {
throw new RuntimeException(e);
}
- String path = Helpers.getCurrentDir() + FrameworkConstants.EXTENT_REPORT_FOLDER + File.separator + "images";
+ String path = SystemHelpers.getCurrentDir() + FrameworkConstants.EXTENT_REPORT_FOLDER + File.separator + "images";
File folder = new File(path);
if (!folder.exists()) {
@@ -182,7 +182,7 @@ public static String getScreenshotAbsolutePath(String screenshotName) {
throw new RuntimeException(e);
}
- String path = Helpers.getCurrentDir() + FrameworkConstants.EXTENT_REPORT_FOLDER + File.separator + "images";
+ String path = SystemHelpers.getCurrentDir() + FrameworkConstants.EXTENT_REPORT_FOLDER + File.separator + "images";
File folder = new File(path);
if (!folder.exists()) {
diff --git a/src/main/java/com/anhtester/helpers/JsonHelpers.java b/src/main/java/com/anhtester/helpers/JsonHelpers.java
index c1f6e1d..b4f41c4 100644
--- a/src/main/java/com/anhtester/helpers/JsonHelpers.java
+++ b/src/main/java/com/anhtester/helpers/JsonHelpers.java
@@ -14,11 +14,11 @@ public class JsonHelpers {
private StringBuffer stringBuffer;
private DocumentContext jsonContext;
private String lines;
- private String jsonFilePathDefault = Helpers.getCurrentDir() + "src/test/resources/datajson/store.json";
+ private String jsonFilePathDefault = SystemHelpers.getCurrentDir() + "src/test/resources/datajson/store.json";
public void setJsonFile(String jsonPath) {
try {
- bufferedReader = new BufferedReader(new FileReader(Helpers.getCurrentDir() + jsonPath));
+ bufferedReader = new BufferedReader(new FileReader(SystemHelpers.getCurrentDir() + jsonPath));
stringBuffer = new StringBuffer();
while ((lines = bufferedReader.readLine()) != null) {
stringBuffer.append(lines);
diff --git a/src/main/java/com/anhtester/helpers/PropertiesHelpers.java b/src/main/java/com/anhtester/helpers/PropertiesHelpers.java
index 1743436..3aa6ab2 100644
--- a/src/main/java/com/anhtester/helpers/PropertiesHelpers.java
+++ b/src/main/java/com/anhtester/helpers/PropertiesHelpers.java
@@ -34,7 +34,7 @@ public static Properties loadAllFiles() {
for (String f : files) {
Properties tempProp = new Properties();
- linkFile = Helpers.getCurrentDir() + f;
+ linkFile = SystemHelpers.getCurrentDir() + f;
file = new FileInputStream(linkFile);
tempProp.load(file);
properties.putAll(tempProp);
@@ -56,7 +56,7 @@ public static Properties getProperties() {
public static void setFile(String relPropertiesFilePath) {
properties = new Properties();
try {
- linkFile = Helpers.getCurrentDir() + relPropertiesFilePath;
+ linkFile = SystemHelpers.getCurrentDir() + relPropertiesFilePath;
file = new FileInputStream(linkFile);
properties.load(file);
file.close();
@@ -68,7 +68,7 @@ public static void setFile(String relPropertiesFilePath) {
public static void setDefaultFile() {
properties = new Properties();
try {
- linkFile = Helpers.getCurrentDir() + relPropertiesFilePathDefault;
+ linkFile = SystemHelpers.getCurrentDir() + relPropertiesFilePathDefault;
file = new FileInputStream(linkFile);
properties.load(file);
file.close();
@@ -82,7 +82,7 @@ public static String getValue(String key) {
try {
if (file == null && properties == null) {
properties = new Properties();
- linkFile = Helpers.getCurrentDir() + relPropertiesFilePathDefault;
+ linkFile = SystemHelpers.getCurrentDir() + relPropertiesFilePathDefault;
file = new FileInputStream(linkFile);
properties.load(file);
file.close();
@@ -101,10 +101,10 @@ public static void setValue(String key, String keyValue) {
try {
if (file == null) {
properties = new Properties();
- file = new FileInputStream(Helpers.getCurrentDir() + relPropertiesFilePathDefault);
+ file = new FileInputStream(SystemHelpers.getCurrentDir() + relPropertiesFilePathDefault);
properties.load(file);
file.close();
- out = new FileOutputStream(Helpers.getCurrentDir() + relPropertiesFilePathDefault);
+ out = new FileOutputStream(SystemHelpers.getCurrentDir() + relPropertiesFilePathDefault);
}
//Write to the same Prop file as the extracted file
out = new FileOutputStream(linkFile);
diff --git a/src/main/java/com/anhtester/helpers/Helpers.java b/src/main/java/com/anhtester/helpers/SystemHelpers.java
similarity index 97%
rename from src/main/java/com/anhtester/helpers/Helpers.java
rename to src/main/java/com/anhtester/helpers/SystemHelpers.java
index 31da7e2..fa94a16 100644
--- a/src/main/java/com/anhtester/helpers/Helpers.java
+++ b/src/main/java/com/anhtester/helpers/SystemHelpers.java
@@ -12,9 +12,9 @@
import java.util.Locale;
import java.util.regex.Pattern;
-public final class Helpers {
+public final class SystemHelpers {
- public Helpers() {
+ public SystemHelpers() {
super();
}
diff --git a/src/main/java/com/anhtester/keywords/WebUI.java b/src/main/java/com/anhtester/keywords/WebUI.java
index 71e24ad..18b115c 100644
--- a/src/main/java/com/anhtester/keywords/WebUI.java
+++ b/src/main/java/com/anhtester/keywords/WebUI.java
@@ -8,7 +8,7 @@
import com.anhtester.constants.FrameworkConstants;
import com.anhtester.driver.DriverManager;
import com.anhtester.enums.FailureHandling;
-import com.anhtester.helpers.Helpers;
+import com.anhtester.helpers.SystemHelpers;
import com.anhtester.report.AllureManager;
import com.anhtester.report.ExtentReportManager;
import com.anhtester.report.ExtentTestManager;
@@ -16,12 +16,6 @@
import com.anhtester.utils.DateUtils;
import com.anhtester.utils.LogUtils;
import com.google.common.util.concurrent.Uninterruptibles;
-import com.google.zxing.BinaryBitmap;
-import com.google.zxing.LuminanceSource;
-import com.google.zxing.MultiFormatReader;
-import com.google.zxing.Result;
-import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
-import com.google.zxing.common.HybridBinarizer;
import io.qameta.allure.Step;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.Dimension;
@@ -42,16 +36,12 @@
import org.testng.asserts.SoftAssert;
import javax.annotation.Nullable;
-import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
-import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.List;
@@ -82,7 +72,9 @@ public static void smartWait() {
if (FrameworkConstants.ACTIVE_PAGE_LOADED.trim().toLowerCase().equals("true")) {
waitForPageLoaded();
}
- sleep(FrameworkConstants.WAIT_SLEEP_STEP);
+ if (FrameworkConstants.WAIT_SLEEP_STEP > 0) {
+ sleep(FrameworkConstants.WAIT_SLEEP_STEP);
+ }
}
/**
@@ -93,7 +85,7 @@ public static void smartWait() {
public static void addScreenshotToReport(String screenName) {
if (FrameworkConstants.SCREENSHOT_ALL_STEPS.equals(FrameworkConstants.YES)) {
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.addScreenShot(Helpers.makeSlug(screenName));
+ ExtentReportManager.addScreenShot(SystemHelpers.makeSlug(screenName));
}
//CaptureHelpers.captureScreenshot(DriverManager.getDriver(), Helpers.makeSlug(screenshotName));
AllureManager.takeScreenshotStep();
@@ -108,7 +100,7 @@ public static void addScreenshotToReport(String screenName) {
public static void takeElementScreenshot(By by, String screenName) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
try {
- String path = Helpers.getCurrentDir() + FrameworkConstants.EXPORT_CAPTURE_PATH;
+ String path = SystemHelpers.getCurrentDir() + FrameworkConstants.EXPORT_CAPTURE_PATH;
File file = new File(path);
if (!file.exists()) {
LogUtils.info("No Folder: " + path);
@@ -135,7 +127,7 @@ public static void takeElementScreenshot(By by, String screenName) {
public static void takeFullPageScreenshot(String screenName) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss");
try {
- String path = Helpers.getCurrentDir() + FrameworkConstants.EXPORT_CAPTURE_PATH;
+ String path = SystemHelpers.getCurrentDir() + FrameworkConstants.EXPORT_CAPTURE_PATH;
File file = new File(path);
if (!file.exists()) {
LogUtils.info("No Folder: " + path);
@@ -249,18 +241,17 @@ public static boolean verifyFileEqualsInDownloadDirectory(String fileName) {
* @return true if file is downloaded, else is false
*/
public static boolean verifyDownloadFileContainsName(String fileName, int timeoutSeconds) {
- boolean check = false;
int i = 0;
while (i < timeoutSeconds) {
boolean exist = verifyFileContainsInDownloadDirectory(fileName);
- if (exist == true) {
+ if (exist) {
i = timeoutSeconds;
- return check = true;
+ return true;
}
sleep(1);
i++;
}
- return check;
+ return false;
}
/**
@@ -271,18 +262,17 @@ public static boolean verifyDownloadFileContainsName(String fileName, int timeou
* @return true if file is downloaded, else is false
*/
public static boolean verifyDownloadFileEqualsName(String fileName, int timeoutSeconds) {
- boolean check = false;
int i = 0;
while (i < timeoutSeconds) {
boolean exist = verifyFileEqualsInDownloadDirectory(fileName);
- if (exist == true) {
+ if (exist) {
i = timeoutSeconds;
- return check = true;
+ return true;
}
sleep(1);
i++;
}
- return check;
+ return false;
}
/**
@@ -299,7 +289,7 @@ public static void deleteAllFileInDownloadDirectory() {
}
}
} catch (Exception e) {
- e.getMessage();
+ LogUtils.error(e.getMessage());
}
}
@@ -318,7 +308,7 @@ public static void deleteAllFileInDirectory(String pathDirectory) {
}
}
} catch (Exception e) {
- e.getMessage();
+ LogUtils.error(e.getMessage());
}
}
@@ -375,7 +365,7 @@ public static boolean verifyFileDownloadedWithJS_Contains(String fileName) {
*/
@Step("Get to URL {0} with authentication")
public static void getToUrlAuthentication(String url, String username, String password) {
- // Get the devtools from the running driver and create a session
+ // Get the devtools from the running drivers and create a session
DevTools devTools = ((HasDevTools) DriverManager.getDriver()).getDevTools();
devTools.createSession();
@@ -399,42 +389,6 @@ public static void getToUrlAuthentication(String url, String username, String pa
Uninterruptibles.sleepUninterruptibly(Duration.ofSeconds(3));
}
- /**
- * Get code text of QR Code image
- *
- * @param by là an element of object type By
- * @return text of QR Code
- */
- @Step("Get QR code from image {0}")
- public static String getQRCodeFromImage(By by) {
- String qrCodeURL = WebUI.getAttributeElement(by, "src");
- //Create an object of URL Class
- URL url = null;
- try {
- url = new URL(qrCodeURL);
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- //Pass the URL class object to store the file as image
- BufferedImage bufferedimage = null;
- try {
- bufferedimage = ImageIO.read(url);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- // Process the image
- LuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedimage);
- BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
- //To Capture details of QR code
- Result result = null;
- try {
- result = new MultiFormatReader().decode(binaryBitmap);
- } catch (com.google.zxing.NotFoundException e) {
- throw new RuntimeException(e);
- }
- return result.getText();
- }
-
//Handle HTML5 validation message and valid value
/**
@@ -444,9 +398,9 @@ public static String getQRCodeFromImage(By by) {
* @return true/false corresponds to required
*/
@Step("Verify HTML5 message of element {0} required field")
- public static Boolean verifyHTML5RequiredField(By by) {
+ public static boolean verifyHTML5RequiredField(By by) {
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
- Boolean verifyRequired = (Boolean) js.executeScript("return arguments[0].required;", getWebElement(by));
+ boolean verifyRequired = (Boolean) js.executeScript("return arguments[0].required;", getWebElement(by));
return verifyRequired;
}
@@ -457,9 +411,9 @@ public static Boolean verifyHTML5RequiredField(By by) {
* @return true/false corresponds to Valid
*/
@Step("Verify HTML5 message of element {0} valid")
- public static Boolean verifyHTML5ValidValueField(By by) {
+ public static boolean verifyHTML5ValidValueField(By by) {
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
- Boolean verifyValid = (Boolean) js.executeScript("return arguments[0].validity.valid;", getWebElement(by));
+ boolean verifyValid = (Boolean) js.executeScript("return arguments[0].validity.valid;", getWebElement(by));
return verifyValid;
}
@@ -589,7 +543,7 @@ public static void sleep(double second) {
try {
Thread.sleep((long) (second * 1000));
} catch (InterruptedException e) {
- e.printStackTrace();
+ LogUtils.error(e.getMessage());
}
}
@@ -609,7 +563,10 @@ public static ChromeOptions notificationsAllow() {
// Create a ChromeOptions session
ChromeOptions options = new ChromeOptions();
-
+ options.addArguments("--headless");
+ options.addArguments("--no-sandbox");
+ options.addArguments("--disable-dev-shm-usage");
+ options.addArguments("--disable-gpu");
// Use the setExperimentalOption function to execute the value through the above prefs object
options.setExperimentalOption("prefs", prefs);
@@ -633,7 +590,10 @@ public static ChromeOptions notificationsBlock() {
// Create a ChromeOptions session
ChromeOptions options = new ChromeOptions();
-
+ options.addArguments("--headless");
+ options.addArguments("--no-sandbox");
+ options.addArguments("--disable-dev-shm-usage");
+ options.addArguments("--disable-gpu");
// Use the setExperimentalOption function to execute the value through the above prefs object
options.setExperimentalOption("prefs", prefs);
@@ -654,14 +614,14 @@ public static void uploadFileWithLocalForm(By by, String filePath) {
Actions action = new Actions(DriverManager.getDriver());
//Click to open form upload
action.moveToElement(getWebElement(by)).click().perform();
- sleep(3);
+ sleep(2);
// Create Robot class
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
- e.printStackTrace();
+ LogUtils.error(e.getMessage());
}
// Copy File path to Clipboard
@@ -677,7 +637,7 @@ public static void uploadFileWithLocalForm(By by, String filePath) {
// Release the Control V
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_V);
- robot.delay(2000);
+ robot.delay(1000);
// Press Enter
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
@@ -741,7 +701,7 @@ public static void uploadFileWithSendKeys(By by, String filePath) {
}
/**
- * Get current URL from current driver
+ * Get current URL from current drivers
*
* @return the current URL as String
*/
@@ -809,10 +769,10 @@ public static boolean verifyElementChecked(By by) {
smartWait();
boolean checked = getWebElement(by).isSelected();
- if (checked == true) {
+ if (checked) {
return true;
} else {
- Assert.assertTrue(false, "The element NOT checked.");
+ Assert.assertTrue(false, "❌ The element NOT checked.");
return false;
}
}
@@ -831,7 +791,7 @@ public static boolean verifyElementChecked(By by, String message) {
boolean checked = getWebElement(by).isSelected();
- if (checked == true) {
+ if (checked) {
return true;
} else {
Assert.assertTrue(false, message);
@@ -864,7 +824,6 @@ public static boolean selectOptionDynamic(By objectListItem, String text) {
}
} catch (Exception e) {
LogUtils.info(e.getMessage());
- e.getMessage();
}
return false;
}
@@ -882,7 +841,7 @@ public static boolean verifyOptionDynamicExist(By by, String text) {
try {
List elements = getWebElements(by);
-
+
for (WebElement element : elements) {
LogUtils.info(element.getText());
if (element.getText().toLowerCase().trim().contains(text.toLowerCase().trim())) {
@@ -891,7 +850,6 @@ public static boolean verifyOptionDynamicExist(By by, String text) {
}
} catch (Exception e) {
LogUtils.info(e.getMessage());
- e.getMessage();
}
return false;
}
@@ -912,7 +870,6 @@ public static int getOptionDynamicTotal(By objectListItem) {
return elements.size();
} catch (Exception e) {
LogUtils.info(e.getMessage());
- e.getMessage();
}
return 0;
}
@@ -1169,9 +1126,9 @@ public static void switchToWindowOrTabByUrl(String url) {
*/
@Step("Close current Window")
public static void closeCurrentWindow() {
- LogUtils.info("Close current Window." + getCurrentUrl());
+ LogUtils.info("Close current Window: " + getCurrentUrl());
DriverManager.getDriver().close();
- LogUtils.info("Close current Window");
+ LogUtils.info("Closed current Window");
}
@@ -1190,7 +1147,7 @@ public static boolean verifyTotalOfWindowsOrTab(int number) {
* Open new Tab
*/
@Step("Open new Tab")
- public static void openNewTab() {
+ public static void openAndSwitchNewTab() {
smartWait();
// Opens a new tab and switches to new tab
DriverManager.getDriver().switchTo().newWindow(WindowType.TAB);
@@ -1201,7 +1158,7 @@ public static void openNewTab() {
* Open new Window
*/
@Step("Open new Window")
- public static void openNewWindow() {
+ public static void openAndSwitchNewWindow() {
smartWait();
// Opens a new window and switches to new window
DriverManager.getDriver().switchTo().newWindow(WindowType.WINDOW);
@@ -1213,7 +1170,6 @@ public static void openNewWindow() {
*/
@Step("Switch to Main Window")
public static void switchToMainWindow() {
- smartWait();
DriverManager.getDriver().switchTo().window(DriverManager.getDriver().getWindowHandles().toArray()[0].toString());
LogUtils.info("Switch to Main Window." + DriverManager.getDriver());
}
@@ -1225,7 +1181,6 @@ public static void switchToMainWindow() {
*/
@Step("Switch to Main Window by ID {0}")
public static void switchToMainWindow(String originalWindow) {
- smartWait();
DriverManager.getDriver().switchTo().window(originalWindow);
LogUtils.info("Switch to Main Window." + originalWindow);
}
@@ -1235,7 +1190,6 @@ public static void switchToMainWindow(String originalWindow) {
*/
@Step("Switch to Last Window")
public static void switchToLastWindow() {
- smartWait();
Set windowHandles = DriverManager.getDriver().getWindowHandles();
WebDriver newDriver = DriverManager.getDriver().switchTo().window(DriverManager.getDriver().getWindowHandles().toArray()[windowHandles.size() - 1].toString());
LogUtils.info("Switch to Last Window." + newDriver.getCurrentUrl());
@@ -1330,46 +1284,45 @@ public static List getListElementsText(By by) {
* @return true/false
*/
@Step("Verify element exists {0}")
- public static boolean verifyElementExists(By by) {
+ public static boolean checkElementExists(By by) {
smartWait();
+ boolean result;
- boolean res;
List elementList = getWebElements(by);
if (elementList.size() > 0) {
- res = true;
- LogUtils.info("Element existing");
+ LogUtils.info("✅ Element " + by + " existing.");
+ result = true;
} else {
- res = false;
- LogUtils.error("Element not exists");
-
+ LogUtils.error("❌ Element " + by + " NOT exists.");
+ result = false;
}
- return res;
+ return result;
}
/**
* Verify if two object are equal.
*
- * @param value1 The object one
- * @param value2 The object two
+ * @param actual The object one
+ * @param expected The object two
* @return true/false
*/
@Step("Verify Equals: {0} ---AND--- {1}")
- public static boolean verifyEquals(Object value1, Object value2) {
- boolean result = value1.equals(value2);
- if (result == true) {
- LogUtils.info("Verify Equals: " + value1 + " = " + value2);
+ public static boolean verifyEquals(Object actual, Object expected) {
+ boolean result = actual.equals(expected);
+ if (result) {
+ LogUtils.info("Verify Equals: " + actual + " = " + expected);
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Verify Equals: " + value1 + " = " + value2);
+ ExtentReportManager.pass("Verify Equals: " + actual + " = " + expected);
}
- AllureManager.saveTextLog("Verify Equals: " + value1 + " = " + value2);
+ AllureManager.saveTextLog("Verify Equals: " + actual + " = " + expected);
} else {
- LogUtils.info("Verify Equals: " + value1 + " != " + value2);
+ LogUtils.error("Verify Equals: " + actual + " != " + expected);
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.fail("Verify Equals: " + value1 + " != " + value2);
+ ExtentReportManager.fail("Verify Equals: " + actual + " != " + expected);
}
- AllureManager.saveTextLog("Verify Equals: " + value1 + " != " + value2);
- Assert.assertEquals(value1, value2, value1 + " != " + value2);
+ AllureManager.saveTextLog("❌ Verify Equals: " + actual + " != " + expected);
+ Assert.assertEquals(actual, expected, "❌ " + actual + " != " + expected);
}
return result;
}
@@ -1377,27 +1330,27 @@ public static boolean verifyEquals(Object value1, Object value2) {
/**
* Verify if two object are equal.
*
- * @param value1 The object one
- * @param value2 The object two
+ * @param actual The object one
+ * @param expected The object two
* @param message The custom message if false
* @return true/false
*/
@Step("Verify Equals: {0} ---AND--- {1}")
- public static boolean verifyEquals(Object value1, Object value2, String message) {
- boolean result = value1.equals(value2);
- if (result == true) {
- LogUtils.info("Verify Equals: " + value1 + " = " + value2);
+ public static boolean verifyEquals(Object actual, Object expected, String message) {
+ boolean result = actual.equals(expected);
+ if (result) {
+ LogUtils.info("Verify Equals: " + actual + " = " + expected);
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Verify Equals: " + value1 + " = " + value2);
+ ExtentReportManager.pass("Verify Equals: " + actual + " = " + expected);
}
- AllureManager.saveTextLog("Verify Equals: " + value1 + " = " + value2);
+ AllureManager.saveTextLog("Verify Equals: " + actual + " = " + expected);
} else {
- LogUtils.info("Verify Equals: " + value1 + " != " + value2);
+ LogUtils.error("Verify Equals: " + actual + " != " + expected);
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.fail("Verify Equals: " + value1 + " != " + value2);
+ ExtentReportManager.fail("Verify Equals: " + actual + " != " + expected);
}
- AllureManager.saveTextLog("Verify Equals: " + value1 + " != " + value2);
- Assert.assertEquals(value1, value2, message);
+ AllureManager.saveTextLog("❌ Verify Equals: " + actual + " != " + expected);
+ Assert.assertEquals(actual, expected, "❌ " + message);
}
return result;
}
@@ -1405,27 +1358,27 @@ public static boolean verifyEquals(Object value1, Object value2, String message)
/**
* Verify if the first object contains the second object.
*
- * @param value1 The first object
- * @param value2 The second object
+ * @param actual The first object
+ * @param expected The second object
* @return true/false
*/
- @Step("Verify Contains: {0} ---AND--- {1}")
- public static boolean verifyContains(String value1, String value2) {
- boolean result = value1.contains(value2);
- if (result == true) {
- LogUtils.info("Verify Equals: " + value1 + " CONTAINS " + value2);
+ @Step("Verify Contains: {0} AND {1}")
+ public static boolean verifyContains(String actual, String expected) {
+ boolean result = actual.contains(expected);
+ if (result) {
+ LogUtils.info("Verify Equals: " + actual + " CONTAINS " + expected);
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Verify Contains: " + value1 + " CONTAINS " + value2);
+ ExtentReportManager.pass("Verify Contains: " + actual + " CONTAINS " + expected);
}
- AllureManager.saveTextLog("Verify Contains: " + value1 + "CONTAINS" + value2);
+ AllureManager.saveTextLog("Verify Contains: " + actual + "CONTAINS" + expected);
} else {
- LogUtils.info("Verify Contains: " + value1 + " NOT CONTAINS " + value2);
+ LogUtils.error("❌ Verify Contains: " + actual + " NOT CONTAINS " + expected);
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.fail("Verify Contains: " + value1 + " NOT CONTAINS " + value2);
+ ExtentReportManager.fail("Verify Contains: " + actual + " NOT CONTAINS " + expected);
}
- AllureManager.saveTextLog("Verify Contains: " + value1 + " NOT CONTAINS " + value2);
+ AllureManager.saveTextLog("Verify Contains: " + actual + " NOT CONTAINS " + expected);
- Assert.assertEquals(value1, value2, value1 + " NOT CONTAINS " + value2);
+ Assert.assertEquals(actual, expected, "❌ " + actual + " NOT CONTAINS " + expected);
}
return result;
}
@@ -1433,28 +1386,28 @@ public static boolean verifyContains(String value1, String value2) {
/**
* Verify if the first object contains the second object.
*
- * @param value1 The first object
- * @param value2 The second object
+ * @param actual The first object
+ * @param expected The second object
* @param message The custom message if false
* @return true/false
*/
- @Step("Verify Contains: {0} ---AND--- {1}")
- public static boolean verifyContains(String value1, String value2, String message) {
- boolean result = value1.contains(value2);
- if (result == true) {
- LogUtils.info("Verify Equals: " + value1 + " CONTAINS " + value2);
+ @Step("Verify Contains: {0} AND {1}")
+ public static boolean verifyContains(String actual, String expected, String message) {
+ boolean result = actual.contains(expected);
+ if (result) {
+ LogUtils.info("Verify Contains: " + actual + " CONTAINS " + expected);
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Verify Contains: " + value1 + " CONTAINS " + value2);
+ ExtentReportManager.pass("Verify Contains: " + actual + " CONTAINS " + expected);
}
- AllureManager.saveTextLog("Verify Contains: " + value1 + "CONTAINS" + value2);
+ AllureManager.saveTextLog("Verify Contains: " + actual + "CONTAINS" + expected);
} else {
- LogUtils.info("Verify Contains: " + value1 + " NOT CONTAINS " + value2);
+ LogUtils.error("❌ Verify Contains: " + actual + " NOT CONTAINS " + expected);
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.fail("Verify Contains: " + value1 + " NOT CONTAINS " + value2);
+ ExtentReportManager.fail("Verify Contains: " + actual + " NOT CONTAINS " + expected);
}
- AllureManager.saveTextLog("Verify Contains: " + value1 + " NOT CONTAINS " + value2);
+ AllureManager.saveTextLog("Verify Contains: " + actual + " NOT CONTAINS " + expected);
- Assert.assertEquals(value1, value2, message);
+ Assert.assertEquals(actual, expected, message);
}
return result;
}
@@ -1464,21 +1417,18 @@ public static boolean verifyContains(String value1, String value2, String messag
*
* @return true/false
*/
- @Step("Verify TRUE with condition: {0}")
- public static boolean verifyTrue(Boolean condition) {
- if (condition == true) {
+ @Step("Verify TRUE: {0}")
+ public static boolean verifyTrue(boolean condition) {
+ if (condition) {
LogUtils.info("Verify TRUE: " + condition);
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.pass("Verify TRUE: " + condition);
}
- AllureManager.saveTextLog("Verify TRUE: " + condition);
} else {
- LogUtils.info("Verify TRUE: " + condition);
+ LogUtils.error("❌ Verify TRUE: " + condition);
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.fail("Verify TRUE: " + condition);
}
- AllureManager.saveTextLog("Verify TRUE: " + condition);
-
Assert.assertTrue(condition, "The condition is FALSE.");
}
return condition;
@@ -1490,21 +1440,18 @@ public static boolean verifyTrue(Boolean condition) {
* @param message the custom message if false
* @return true/false
*/
- @Step("Verify TRUE with condition: {0}")
- public static boolean verifyTrue(Boolean condition, String message) {
- if (condition == true) {
+ @Step("Verify TRUE: {0}")
+ public static boolean verifyTrue(boolean condition, String message) {
+ if (condition) {
LogUtils.info("Verify TRUE: " + condition);
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.pass("Verify TRUE: " + condition);
}
- AllureManager.saveTextLog("Verify TRUE: " + condition);
} else {
- LogUtils.info("Verify TRUE: " + condition);
+ LogUtils.error("❌ Verify TRUE: " + condition);
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.fail("Verify TRUE: " + condition);
}
- AllureManager.saveTextLog("Verify TRUE: " + condition);
-
Assert.assertTrue(condition, message);
}
return condition;
@@ -1541,18 +1488,18 @@ public static boolean verifyElementTextEquals(By by, String text, FailureHandlin
boolean result = getTextElement(by).trim().equals(text.trim());
- if (result == true) {
+ if (result) {
LogUtils.info("Verify text of an element [Equals]: " + result);
} else {
- LogUtils.warn("Verify text of an element [Equals]: " + result);
+ LogUtils.error("❌ Verify text of an element [Equals]: " + result);
}
if (flowControl.equals(FailureHandling.STOP_ON_FAILURE)) {
- Assert.assertEquals(getTextElement(by).trim(), text.trim(), "The actual text is '" + getTextElement(by).trim() + "' not equals '" + text.trim() + "'");
+ Assert.assertEquals(getTextElement(by).trim(), text.trim(), "❌ The actual text is '" + getTextElement(by).trim() + "' not equals '" + text.trim() + "'");
}
if (flowControl.equals(FailureHandling.CONTINUE_ON_FAILURE)) {
- softAssert.assertEquals(getTextElement(by).trim(), text.trim(), "The actual text is '" + getTextElement(by).trim() + "' not equals '" + text.trim() + "'");
- if (result == false) {
+ softAssert.assertEquals(getTextElement(by).trim(), text.trim(), "❌ The actual text is '" + getTextElement(by).trim() + "' not equals '" + text.trim() + "'");
+ if (!result) {
ExtentReportManager.fail("The actual text is '" + getTextElement(by).trim() + "' not equals '" + text.trim() + "'");
}
}
@@ -1583,19 +1530,19 @@ public static boolean verifyElementTextEquals(By by, String text) {
boolean result = getTextElement(by).trim().equals(text.trim());
- if (result == true) {
+ if (result) {
LogUtils.info("Verify text of an element [Equals]: " + result);
} else {
- LogUtils.warn("Verify text of an element [Equals]: " + result);
+ LogUtils.error("❌ Verify text of an element [Equals]: " + result);
}
- Assert.assertEquals(getTextElement(by).trim(), text.trim(), "The actual text is '" + getTextElement(by).trim() + "' not equals '" + text.trim() + "'");
+ Assert.assertEquals(getTextElement(by).trim(), text.trim(), "❌ The actual text is '" + getTextElement(by).trim() + "' NOT equals '" + text.trim() + "'");
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.warning("Verify text of an element [Equals] : " + result);
ExtentReportManager.warning("The actual text is '" + getTextElement(by).trim() + "' not equals '" + text.trim() + "'");
}
- AllureManager.saveTextLog("Verify text of an element [Equals] : " + result + ". The actual text is '" + getTextElement(by).trim() + "' not equals '" + text.trim() + "'");
+ AllureManager.saveTextLog("Verify text of an element [Equals] : " + result + ". The actual text is '" + getTextElement(by).trim() + "' NOT equals '" + text.trim() + "'");
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -1617,23 +1564,23 @@ public static boolean verifyElementTextContains(By by, String text, FailureHandl
boolean result = getTextElement(by).trim().contains(text.trim());
- if (result == true) {
+ if (result) {
LogUtils.info("Verify text of an element [Contains]: " + result);
} else {
- LogUtils.warn("Verify text of an element [Contains]: " + result);
+ LogUtils.error("❌ Verify text of an element [Contains]: " + result);
}
if (flowControl.equals(FailureHandling.STOP_ON_FAILURE)) {
- Assert.assertTrue(result, "The actual text is " + getTextElement(by).trim() + " not contains " + text.trim());
+ Assert.assertTrue(result, "❌ The actual text is " + getTextElement(by).trim() + " NOT contains " + text.trim());
}
if (flowControl.equals(FailureHandling.CONTINUE_ON_FAILURE)) {
- softAssert.assertTrue(result, "The actual text is " + getTextElement(by).trim() + " not contains " + text.trim());
+ softAssert.assertTrue(result, "❌ The actual text is " + getTextElement(by).trim() + " NOT contains " + text.trim());
}
if (flowControl.equals(FailureHandling.OPTIONAL)) {
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.warning("Verify text of an element [Contains] - " + result);
+ ExtentReportManager.warning("Verify text of an element [Contains] : " + result);
}
- AllureManager.saveTextLog("Verify text of an element [Contains] - " + result);
+ AllureManager.saveTextLog("Verify text of an element [Contains] : " + result);
}
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -1655,13 +1602,13 @@ public static boolean verifyElementTextContains(By by, String text) {
boolean result = getTextElement(by).trim().contains(text.trim());
- if (result == true) {
+ if (result) {
LogUtils.info("Verify text of an element [Contains]: " + result);
} else {
- LogUtils.warn("Verify text of an element [Contains]: " + result);
+ LogUtils.error("❌ Verify text of an element [Contains]: " + result);
}
- Assert.assertTrue(result, "The actual text is " + getTextElement(by).trim() + " not contains " + text.trim());
+ Assert.assertTrue(result, "The actual text is " + getTextElement(by).trim() + " NOT contains " + text.trim());
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.info("Verify text of an element [Contains] : " + result);
@@ -1690,11 +1637,10 @@ public static boolean verifyElementClickable(By by) {
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.info("Verify element clickable " + by);
}
- AllureManager.saveTextLog("Verify element clickable " + by);
return true;
} catch (Exception e) {
- LogUtils.error(e.getMessage());
- Assert.fail("FAILED. Element not clickable " + by);
+ LogUtils.error("❌ Element not clickable " + by);
+ Assert.fail("❌ Element not clickable " + by);
return false;
}
}
@@ -1717,12 +1663,10 @@ public static boolean verifyElementClickable(By by, int timeout) {
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.info("Verify element clickable " + by);
}
- AllureManager.saveTextLog("Verify element clickable " + by);
return true;
} catch (Exception e) {
- LogUtils.error("FAILED. Element not clickable " + by);
- LogUtils.error(e.getMessage());
- Assert.fail("FAILED. Element not clickable " + by);
+ LogUtils.error("❌ Element not clickable " + by);
+ Assert.fail("❌ Element not clickable " + by);
return false;
}
}
@@ -1746,12 +1690,10 @@ public static boolean verifyElementClickable(By by, int timeout, String message)
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.info("Verify element clickable " + by);
}
- AllureManager.saveTextLog("Verify element clickable " + by);
return true;
} catch (Exception e) {
- LogUtils.error(message);
- LogUtils.error(e.getMessage());
- Assert.fail(message + "" + e.getMessage());
+ LogUtils.error("❌ " + message);
+ Assert.fail("❌ " + message);
return false;
}
}
@@ -1767,18 +1709,17 @@ public static boolean verifyElementPresent(By by) {
smartWait();
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
LogUtils.info("Verify element present " + by);
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.info("Verify element present " + by);
}
- AllureManager.saveTextLog("Verify element present " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
return true;
} catch (Exception e) {
- LogUtils.info("The element does NOT present. " + e.getMessage());
- Assert.fail("The element does NOT present. " + e.getMessage());
+ LogUtils.info("❌ The element does NOT present. " + by);
+ Assert.fail("❌ The element does NOT present. " + by);
return false;
}
}
@@ -1801,12 +1742,11 @@ public static boolean verifyElementPresent(By by, int timeout) {
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.info("Verify element present " + by);
}
- AllureManager.saveTextLog("Verify element present " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
return true;
} catch (Exception e) {
- LogUtils.info("The element does NOT present. " + e.getMessage());
- Assert.fail("The element does NOT present. " + e.getMessage());
+ LogUtils.info("❌ The element does NOT present. " + by);
+ Assert.fail("❌ The element does NOT present. " + by);
return false;
}
}
@@ -1823,19 +1763,18 @@ public static boolean verifyElementPresent(By by, String message) {
smartWait();
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
LogUtils.info("Verify element present " + by);
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.info("Verify element present " + by);
}
- AllureManager.saveTextLog("Verify element present " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
return true;
} catch (Exception e) {
- if (message.isEmpty() || message == null) {
- LogUtils.error("The element does NOT present. " + e.getMessage());
- Assert.fail("The element does NOT present. " + e.getMessage());
+ if (message.isEmpty() || message.isBlank()) {
+ LogUtils.error("❌ The element does NOT present. " + by);
+ Assert.fail("❌ The element does NOT present. " + by);
} else {
LogUtils.error(message);
Assert.fail(message);
@@ -1864,13 +1803,12 @@ public static boolean verifyElementPresent(By by, int timeout, String message) {
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.info("Verify element present " + by);
}
- AllureManager.saveTextLog("Verify element present " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
return true;
} catch (Exception e) {
- if (message.isEmpty() || message == null) {
- LogUtils.error("The element does NOT present. " + e.getMessage());
- Assert.fail("The element does NOT present. " + e.getMessage());
+ if (message.isEmpty() || message.isBlank()) {
+ LogUtils.error("❌ The element does NOT present. " + by);
+ Assert.fail("❌ The element does NOT present. " + by);
} else {
LogUtils.error(message);
Assert.fail(message);
@@ -1891,10 +1829,10 @@ public static boolean verifyElementNotPresent(By by) {
smartWait();
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
- LogUtils.error("The element presents. " + by);
- Assert.fail("The element presents. " + by);
+ LogUtils.error("❌ Element is present " + by);
+ Assert.fail("❌ The element presents. " + by);
return false;
} catch (Exception e) {
return true;
@@ -1915,8 +1853,8 @@ public static boolean verifyElementNotPresent(By by, int timeout) {
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeout));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
- LogUtils.error("Element is present " + by);
- Assert.fail("The element presents. " + by);
+ LogUtils.error("❌ Element is present " + by);
+ Assert.fail("❌ The element presents. " + by);
return false;
} catch (Exception e) {
return true;
@@ -1935,14 +1873,14 @@ public static boolean verifyElementNotPresent(By by, String message) {
smartWait();
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
- if (message.isEmpty() || message == null) {
- LogUtils.error("The element presents. " + by);
- Assert.fail("The element presents. " + by);
+ if (message.isEmpty() || message.isBlank()) {
+ LogUtils.error("❌ The element presents. " + by);
+ Assert.fail("❌ The element presents. " + by);
} else {
- LogUtils.error(message);
- Assert.fail(message + " " + by);
+ LogUtils.error("❌ " + message + by);
+ Assert.fail("❌ " + message + by);
}
return false;
} catch (Exception e) {
@@ -1961,16 +1899,15 @@ public static boolean verifyElementNotPresent(By by, String message) {
@Step("Verify element NOT present {0} with timeout {1} second")
public static boolean verifyElementNotPresent(By by, int timeout, String message) {
smartWait();
-
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeout));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
- if (message.isEmpty() || message == null) {
- LogUtils.error("The element presents. " + by);
- Assert.fail("The element presents. " + by);
+ if (message.isEmpty() || message.isBlank()) {
+ LogUtils.error("❌ The element presents. " + by);
+ Assert.fail("❌ The element presents. " + by);
} else {
- LogUtils.error(message + by);
- Assert.fail(message + by);
+ LogUtils.error("❌ " + message + by);
+ Assert.fail("❌ " + message + by);
}
return false;
} catch (Exception e) {
@@ -1985,14 +1922,11 @@ public static boolean verifyElementNotPresent(By by, int timeout, String message
* @param timeout System will wait at most timeout (seconds) to return result
* @return true/false
*/
- @Step("Verify element visible {0}")
+ @Step("Check element visible {0}")
public static boolean isElementVisible(By by, int timeout) {
- smartWait();
-
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeout));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
- LogUtils.info("Verify element visible " + by);
return true;
} catch (Exception e) {
return false;
@@ -2008,14 +1942,14 @@ public static boolean isElementVisible(By by, int timeout) {
@Step("Verify element visible {0}")
public static boolean verifyElementVisible(By by) {
smartWait();
-
+ LogUtils.info("Verify element visible " + by);
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
- LogUtils.info("Verify element visible " + by);
return true;
} catch (Exception e) {
- Assert.fail("The element is NOT visible. " + by);
+ LogUtils.info("❌ The element is NOT visible. " + by);
+ Assert.fail("❌ The element is NOT visible. " + by);
return false;
}
}
@@ -2030,15 +1964,14 @@ public static boolean verifyElementVisible(By by) {
@Step("Verify element visible {0} with timeout {1} second")
public static boolean verifyElementVisible(By by, int timeout) {
smartWait();
-
+ LogUtils.info("Verify element visible " + by);
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeout));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
- LogUtils.info("Verify element visible " + by);
return true;
} catch (Exception e) {
- LogUtils.error("The element is not visible. " + e.getMessage());
- Assert.fail("The element is NOT visible. " + by);
+ LogUtils.error("❌ The element is NOT visible. " + by);
+ Assert.fail("❌ The element is NOT visible. " + by);
return false;
}
}
@@ -2053,14 +1986,13 @@ public static boolean verifyElementVisible(By by, int timeout) {
@Step("Verify element visible {0}")
public static boolean verifyElementVisible(By by, String message) {
smartWait();
-
+ LogUtils.info("Verify element visible " + by);
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
- LogUtils.info("Verify element visible " + by);
return true;
} catch (Exception e) {
- if (message.isEmpty() || message == null) {
+ if (message.isEmpty()) {
LogUtils.error("The element is not visible. " + by);
Assert.fail("The element is NOT visible. " + by);
} else {
@@ -2082,14 +2014,13 @@ public static boolean verifyElementVisible(By by, String message) {
@Step("Verify element visible {0} with timeout {1} second")
public static boolean verifyElementVisible(By by, int timeout, String message) {
smartWait();
-
+ LogUtils.info("Verify element visible " + by);
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeout));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
- LogUtils.info("Verify element visible " + by);
return true;
} catch (Exception e) {
- if (message.isEmpty() || message == null) {
+ if (message.isEmpty()) {
LogUtils.error("The element is not visible. " + by);
Assert.fail("The element is NOT visible. " + by);
} else {
@@ -2100,7 +2031,6 @@ public static boolean verifyElementVisible(By by, int timeout, String message) {
}
}
-
/**
* Verify if the given web element is NOT visible.
*
@@ -2110,9 +2040,9 @@ public static boolean verifyElementVisible(By by, int timeout, String message) {
@Step("Verify element NOT visible {0}")
public static boolean verifyElementNotVisible(By by) {
smartWait();
-
+ LogUtils.info("Verify element NOT visible " + by);
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
return true;
} catch (Exception e) {
@@ -2132,7 +2062,7 @@ public static boolean verifyElementNotVisible(By by) {
@Step("Verify element NOT visible {0} with timeout {1} second")
public static boolean verifyElementNotVisible(By by, int timeout) {
smartWait();
-
+ LogUtils.info("Verify element NOT visible " + by);
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeout));
wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
@@ -2154,13 +2084,13 @@ public static boolean verifyElementNotVisible(By by, int timeout) {
@Step("Verify element NOT visible {0}")
public static boolean verifyElementNotVisible(By by, String message) {
smartWait();
-
+ LogUtils.info("Verify element NOT visible " + by);
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
return true;
} catch (Exception e) {
- if (message.isEmpty() || message == null) {
+ if (message.isEmpty()) {
LogUtils.error("FAILED. The element is visible " + by);
Assert.fail("FAILED. The element is visible " + by);
} else {
@@ -2182,13 +2112,13 @@ public static boolean verifyElementNotVisible(By by, String message) {
@Step("Verify element NOT visible {0} with timeout {1} second")
public static boolean verifyElementNotVisible(By by, int timeout, String message) {
smartWait();
-
+ LogUtils.info("Verify element NOT visible " + by);
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeout));
wait.until(ExpectedConditions.invisibilityOfElementLocated(by));
return true;
} catch (Exception e) {
- if (message.isEmpty() || message == null) {
+ if (message.isEmpty()) {
LogUtils.error("FAILED. The element is visible " + by);
Assert.fail("FAILED. The element is visible " + by);
} else {
@@ -2221,8 +2151,6 @@ public static void scrollToElementAtTop(By by) {
*/
@Step("Scroll to element {0}")
public static void scrollToElementAtBottom(By by) {
- smartWait();
-
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
js.executeScript("arguments[0].scrollIntoView(false);", getWebElement(by));
LogUtils.info("Scroll to element " + by);
@@ -2476,9 +2404,9 @@ public static WebElement highLightElement(By by) {
// draw a border around the found element
if (DriverManager.getDriver() instanceof JavascriptExecutor) {
- ((JavascriptExecutor) DriverManager.getDriver()).executeScript("arguments[0].style.border='3px solid red'", waitForElementVisible(by));
- sleep(1);
- LogUtils.info("Highlight on element " + by);
+ ((JavascriptExecutor) DriverManager.getDriver()).executeScript("arguments[0].style.border='3px solid fuchsia'", waitForElementVisible(by));
+ //sleep(1);
+ LogUtils.info("Highlight element " + by);
}
return getWebElement(by);
}
@@ -2513,15 +2441,15 @@ public static void openWebsite(String URL) {
*/
@Step("Navigate to URL {0}")
public static void navigateToUrl(String URL) {
+ sleep(FrameworkConstants.WAIT_SLEEP_STEP);
DriverManager.getDriver().navigate().to(URL);
waitForPageLoaded();
- LogUtils.info("Navigate to URL: " + URL);
+ LogUtils.info("\uD83C\uDF10 Navigate to URL: " + URL);
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.pass("Navigate to URL: " + URL);
}
- AllureManager.saveTextLog("Navigate to URL: " + URL);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -2535,13 +2463,14 @@ public static void navigateToUrl(String URL) {
*/
@Step("Set text on text box")
public static void setText(By by, String value) {
+ smartWait();
waitForElementVisible(by).sendKeys(value);
LogUtils.info("Set text " + value + " on " + by.toString());
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Set text " + value + " on " + by.toString());
+ ExtentReportManager.pass("Set text " + value + " on " + by);
}
- AllureManager.saveTextLog("Set text " + value + " on " + by.toString());
+ AllureManager.saveTextLog("Set text " + value + " on " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -2556,6 +2485,7 @@ public static void setText(By by, String value) {
*/
@Step("Set text on text box and press key")
public static void setText(By by, String value, Keys keys) {
+ smartWait();
waitForElementVisible(by).sendKeys(value, keys);
LogUtils.info("Set text " + value + " on " + by + " and press key " + keys.name());
@@ -2576,6 +2506,7 @@ public static void setText(By by, String value, Keys keys) {
*/
@Step("Set text on text box and press key")
public static void sendKeys(By by, Keys keys) {
+ smartWait();
waitForElementVisible(by).sendKeys(keys);
LogUtils.info("Press key " + keys.name() + " on element " + by);
@@ -2592,8 +2523,9 @@ public static void sendKeys(By by, Keys keys) {
*
* @param keys key on the keyboard to press
*/
- @Step("Set text on text box and press key")
+ @Step("Press key on keyboard")
public static void sendKeys(Keys keys) {
+ smartWait();
Actions actions = new Actions(DriverManager.getDriver());
actions.sendKeys(keys);
LogUtils.info("Press key " + keys.name() + " on keyboard");
@@ -2611,13 +2543,14 @@ public static void sendKeys(Keys keys) {
*
* @param by an element of object type By
*/
- @Step("Clear value in text box")
+ @Step("Clear text in text box")
public static void clearText(By by) {
+ smartWait();
waitForElementVisible(by).clear();
LogUtils.info("Clear text in textbox " + by.toString());
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Clear text in textbox " + by.toString());
+ ExtentReportManager.pass("Clear text in textbox " + by);
}
AllureManager.saveTextLog("Clear text in textbox");
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -2631,16 +2564,19 @@ public static void clearText(By by) {
*/
@Step("Clear text in text box with Ctrl A")
public static void clearTextCtrlA(By by) {
+ smartWait();
waitForElementVisible(by);
Actions actions = new Actions(DriverManager.getDriver());
+ sleep(1);
actions.click(getWebElement(by)).build().perform();
//actions.moveToElement(getWebElement(by)).click().build();
actions.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).build().perform();
+ sleep(1);
actions.sendKeys(Keys.DELETE).build().perform();
LogUtils.info("Clear text in textbox " + by.toString());
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Clear text in textbox " + by.toString());
+ ExtentReportManager.pass("Clear text in textbox " + by);
}
AllureManager.saveTextLog("Clear text in textbox");
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -2655,14 +2591,16 @@ public static void clearTextCtrlA(By by) {
*/
@Step("Clear and Fill text on text box")
public static void clearAndFillText(By by, String value) {
- waitForElementVisible(by).clear();
- waitForElementVisible(by).sendKeys(value);
+ smartWait();
+ waitForElementVisible(by);
+ getWebElement(by).clear();
+ getWebElement(by).sendKeys(value);
LogUtils.info("Clear and Fill " + value + " on " + by.toString());
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Clear and Fill " + value + " on " + by.toString());
+ ExtentReportManager.pass("Clear and Fill " + value + " on " + by);
}
- AllureManager.saveTextLog("Clear and Fill " + value + " on " + by.toString());
+ AllureManager.saveTextLog("Clear and Fill " + value + " on " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -2675,13 +2613,14 @@ public static void clearAndFillText(By by, String value) {
*/
@Step("Click on the element {0}")
public static void clickElement(By by) {
+ smartWait();
waitForElementClickable(by).click();
LogUtils.info("Clicked on the element " + by.toString());
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Clicked on the element " + by.toString());
+ ExtentReportManager.pass("Clicked on the element " + by);
}
- AllureManager.saveTextLog("Clicked on the element " + by.toString());
+ AllureManager.saveTextLog("Clicked on the element " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -2694,13 +2633,14 @@ public static void clickElement(By by) {
*/
@Step("Click on the element {0} with timeout {1}s")
public static void clickElement(By by, int timeout) {
+ smartWait();
waitForElementClickable(by, timeout).click();
LogUtils.info("Clicked on the element " + by.toString());
if (ExtentTestManager.getExtentTest() != null) {
- ExtentReportManager.pass("Clicked on the element " + by.toString());
+ ExtentReportManager.pass("Clicked on the element " + by);
}
- AllureManager.saveTextLog("Clicked on the element " + by.toString());
+ AllureManager.saveTextLog("Clicked on the element " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
@@ -2713,6 +2653,7 @@ public static void clickElement(By by, int timeout) {
*/
@Step("Click on the element by Javascript {0}")
public static void clickElementWithJs(By by) {
+ smartWait();
waitForElementPresent(by);
//Scroll to element với Javascript Executor
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
@@ -2757,13 +2698,13 @@ public static void clickLinkText(String linkText) {
*/
@Step("Right click on element {0}")
public static void rightClickElement(By by) {
+ smartWait();
Actions action = new Actions(DriverManager.getDriver());
- action.contextClick(waitForElementClickable(by)).build().perform();
+ action.contextClick(waitForElementVisible(by)).build().perform();
LogUtils.info("Right click on element " + by);
if (ExtentTestManager.getExtentTest() != null) {
ExtentReportManager.pass("Right click on element " + by);
}
- AllureManager.saveTextLog("Right click on element " + by);
addScreenshotToReport(Thread.currentThread().getStackTrace()[1].getMethodName() + "_" + DateUtils.getCurrentDateTime());
}
@@ -2777,7 +2718,6 @@ public static void rightClickElement(By by) {
@Step("Get text of element {0}")
public static String getTextElement(By by) {
smartWait();
- AllureManager.saveTextLog("Get text of element " + by.toString());
AllureManager.saveTextLog("==> The Text is: " + waitForElementVisible(by).getText());
return waitForElementVisible(by).getText().trim();
}
@@ -2925,35 +2865,67 @@ public static void checkContainsValueOnTableByColumn(int column, String value, S
}
}
+// /**
+// * Get the value of a column from the table
+// *
+// * @param column column position
+// * @return array of values of a column
+// */
+// public static ArrayList getValueTableByColumn(int column) {
+// smartWait();
+//
+// List totalRows = DriverManager.getDriver().findElements(By.xpath("//tbody/tr"));
+// sleep(1);
+// LogUtils.info("Number of results for column (" + column + "): " + totalRows.size()); //Không thích ghi log thì xóa nhen
+//
+// ArrayList arrayList = new ArrayList();
+//
+// if (totalRows.size() < 1) {
+// LogUtils.info("Not found value !!");
+// } else {
+// for (int i = 1; i <= totalRows.size(); i++) {
+// boolean res = false;
+// WebElement title = DriverManager.getDriver().findElement(By.xpath("//tbody/tr[" + i + "]/td[" + column + "]"));
+// arrayList.add(title.getText());
+// LogUtils.info("Row " + i + ":" + title.getText()); //Không thích ghi log thì xóa nhen
+// }
+// }
+//
+// return arrayList;
+// }
+
/**
* Get the value of a column from the table
*
* @param column column position
* @return array of values of a column
*/
- public static ArrayList getValueTableByColumn(int column) {
+ public static ArrayList getValueTableByColumn(int column) {
smartWait();
List totalRows = DriverManager.getDriver().findElements(By.xpath("//tbody/tr"));
sleep(1);
- LogUtils.info("Number of results for column (" + column + "): " + totalRows.size()); //Không thích ghi log thì xóa nhen
+ LogUtils.info("Number of results for column (" + column + "): " + totalRows.size());
- ArrayList arrayList = new ArrayList();
+ ArrayList arrayList = new ArrayList<>(); // Khai báo rõ ràng kiểu dữ liệu là String
if (totalRows.size() < 1) {
LogUtils.info("Not found value !!");
} else {
for (int i = 1; i <= totalRows.size(); i++) {
- boolean res = false;
WebElement title = DriverManager.getDriver().findElement(By.xpath("//tbody/tr[" + i + "]/td[" + column + "]"));
arrayList.add(title.getText());
- LogUtils.info("Row " + i + ":" + title.getText()); //Không thích ghi log thì xóa nhen
+ LogUtils.info("Row " + i + ":" + title.getText());
}
}
return arrayList;
}
+
+
+
+
//Wait Element
/**
@@ -2964,21 +2936,19 @@ public static ArrayList getValueTableByColumn(int column) {
* @return a WebElement object ready to be visible
*/
public static WebElement waitForElementVisible(By by, int timeOut) {
- smartWait();
-
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeOut), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeOut - 10));
- boolean check = verifyElementVisible(by, timeOut);
- if (check == true) {
+ boolean check = isElementVisible(by, 10);
+ if (check) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
} else {
scrollToElementAtTop(by);
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}
} catch (Throwable error) {
- Assert.fail("Timeout waiting for the element Visible. " + by.toString());
- LogUtils.error("Timeout waiting for the element Visible. " + by.toString());
+ LogUtils.error("❌ Timeout waiting for the element Visible. " + by.toString());
+ Assert.fail("❌ Timeout waiting for the element Visible. " + by.toString());
}
return null;
}
@@ -2990,21 +2960,20 @@ public static WebElement waitForElementVisible(By by, int timeOut) {
* @return a WebElement object ready to be visible
*/
public static WebElement waitForElementVisible(By by) {
- smartWait();
waitForElementPresent(by);
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
- boolean check = isElementVisible(by, 1);
- if (check == true) {
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT - 10));
+ boolean check = isElementVisible(by, 10);
+ if (check) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
} else {
scrollToElementAtBottom(by);
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}
} catch (Throwable error) {
- LogUtils.error("Timeout waiting for the element Visible. " + by.toString());
- Assert.fail("Timeout waiting for the element Visible. " + by.toString());
+ LogUtils.error("❌ Timeout waiting for the element Visible. " + by.toString());
+ Assert.fail("❌ Timeout waiting for the element Visible. " + by.toString());
}
return null;
}
@@ -3017,14 +2986,12 @@ public static WebElement waitForElementVisible(By by) {
* @return a WebElement object ready to CLICK
*/
public static WebElement waitForElementClickable(By by, long timeOut) {
- smartWait();
-
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeOut), Duration.ofMillis(500));
- return wait.until(ExpectedConditions.elementToBeClickable(getWebElement(by)));
+ return wait.until(ExpectedConditions.elementToBeClickable(by));
} catch (Throwable error) {
- Assert.fail("Timeout waiting for the element ready to click. " + by.toString());
- LogUtils.error("Timeout waiting for the element ready to click. " + by.toString());
+ LogUtils.error("❌ Timeout waiting for the element ready to click. " + by.toString());
+ Assert.fail("❌ Timeout waiting for the element ready to click. " + by.toString());
}
return null;
}
@@ -3036,14 +3003,12 @@ public static WebElement waitForElementClickable(By by, long timeOut) {
* @return a WebElement object ready to CLICK
*/
public static WebElement waitForElementClickable(By by) {
- smartWait();
-
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
- return wait.until(ExpectedConditions.elementToBeClickable(getWebElement(by)));
+ return wait.until(ExpectedConditions.elementToBeClickable(by));
} catch (Throwable error) {
- Assert.fail("Timeout waiting for the element ready to click. " + by.toString());
- LogUtils.error("Timeout waiting for the element ready to click. " + by.toString());
+ LogUtils.error("❌ Timeout waiting for the element ready to click. " + by.toString());
+ Assert.fail("❌ Timeout waiting for the element ready to click. " + by.toString());
}
return null;
}
@@ -3056,14 +3021,12 @@ public static WebElement waitForElementClickable(By by) {
* @return an existing WebElement object
*/
public static WebElement waitForElementPresent(By by, long timeOut) {
- smartWait();
-
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeOut), Duration.ofMillis(500));
return wait.until(ExpectedConditions.presenceOfElementLocated(by));
} catch (Throwable error) {
- LogUtils.error("Timeout waiting for the element to exist. " + by.toString());
- Assert.fail("Timeout waiting for the element to exist. " + by.toString());
+ LogUtils.error("❌ Timeout waiting for the element to exist. " + by.toString());
+ Assert.fail("❌ Timeout waiting for the element to exist. " + by.toString());
}
return null;
@@ -3076,14 +3039,12 @@ public static WebElement waitForElementPresent(By by, long timeOut) {
* @return an existing WebElement object
*/
public static WebElement waitForElementPresent(By by) {
- smartWait();
-
try {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT));
return wait.until(ExpectedConditions.presenceOfElementLocated(by));
} catch (Throwable error) {
- LogUtils.error("Element not exist. " + by.toString());
- Assert.fail("Element not exist. " + by.toString());
+ LogUtils.error("❌ Element not exist. (waitForElementPresent) " + by.toString());
+ Assert.fail("❌ Element not exist. (waitForElementPresent) " + by.toString());
}
return null;
}
@@ -3092,15 +3053,13 @@ public static WebElement waitForElementPresent(By by) {
* Wait for an alert to present.
*/
public static boolean waitForAlertPresent() {
- smartWait();
-
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
wait.until(ExpectedConditions.alertIsPresent());
return true;
} catch (Throwable error) {
- LogUtils.error("Alert NOT present.");
- Assert.fail("Alert NOT present.");
+ LogUtils.error("❌ Alert NOT present.");
+ Assert.fail("❌ Alert NOT present.");
return false;
}
}
@@ -3111,8 +3070,6 @@ public static boolean waitForAlertPresent() {
* @param timeOut Timeout waiting for an alert to present.
*/
public static boolean waitForAlertPresent(int timeOut) {
- smartWait();
-
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeOut), Duration.ofMillis(500));
wait.until(ExpectedConditions.alertIsPresent());
@@ -3132,8 +3089,6 @@ public static boolean waitForAlertPresent(int timeOut) {
* @return true/false
*/
public static boolean waitForElementHasAttribute(By by, String attributeName) {
- smartWait();
-
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_EXPLICIT), Duration.ofMillis(500));
return wait.until(ExpectedConditions.attributeToBeNotEmpty(waitForElementPresent(by), attributeName));
@@ -3162,8 +3117,8 @@ public static boolean verifyElementAttributeValue(By by, String attributeName, S
wait.until(ExpectedConditions.attributeToBe(by, attributeName, attributeValue));
return true;
} catch (Throwable error) {
- LogUtils.error("Object: " + by.toString() + ". Not found value: " + attributeValue + " with attribute type: " + attributeName + ". Actual get Attribute value is: " + getAttributeElement(by, attributeName));
- Assert.fail("Object: " + by.toString() + ". Not found value: " + attributeValue + " with attribute type: " + attributeName + ". Actual get Attribute value is: " + getAttributeElement(by, attributeName));
+ LogUtils.error("Element: " + by.toString() + ". Not found Attribute value: " + attributeValue + " with attribute name: " + attributeName + ". Actual get Attribute value is: " + getAttributeElement(by, attributeName));
+ Assert.fail("Element: " + by.toString() + ". Not found Attribute value: " + attributeValue + " with attribute name: " + attributeName + ". Actual get Attribute value is: " + getAttributeElement(by, attributeName));
return false;
}
}
@@ -3178,6 +3133,7 @@ public static boolean verifyElementAttributeValue(By by, String attributeName, S
*/
@Step("Verify element {0} has attribute {1} with timeout {2} second")
public static boolean verifyElementHasAttribute(By by, String attributeName, int timeOut) {
+ smartWait();
try {
WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeOut));
wait.until(ExpectedConditions.attributeToBeNotEmpty(waitForElementPresent(by), attributeName));
@@ -3194,7 +3150,7 @@ public static boolean verifyElementHasAttribute(By by, String attributeName, int
* Wait for a page to load with the default time from the config
*/
public static void waitForPageLoaded() {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_PAGE_LOADED), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(FrameworkConstants.WAIT_PAGE_LOADED));
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
// wait for Javascript to loaded
@@ -3210,7 +3166,7 @@ public static void waitForPageLoaded() {
try {
wait.until(jsLoad);
} catch (Throwable error) {
- error.printStackTrace();
+ LogUtils.error("Timeout waiting for page load. (" + FrameworkConstants.WAIT_PAGE_LOADED + "s)");
Assert.fail("Timeout waiting for page load. (" + FrameworkConstants.WAIT_PAGE_LOADED + "s)");
}
}
@@ -3220,7 +3176,7 @@ public static void waitForPageLoaded() {
* Wait for a page to load within the given time (in seconds)
*/
public static void waitForPageLoaded(int timeOut) {
- WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeOut), Duration.ofMillis(500));
+ WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeOut));
JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();
// wait for Javascript to loaded
@@ -3236,7 +3192,7 @@ public static void waitForPageLoaded(int timeOut) {
try {
wait.until(jsLoad);
} catch (Throwable error) {
- error.printStackTrace();
+ LogUtils.error("Timeout waiting for page load. (" + FrameworkConstants.WAIT_PAGE_LOADED + "s)");
Assert.fail("Timeout waiting for page load. (" + FrameworkConstants.WAIT_PAGE_LOADED + "s)");
}
}
@@ -3265,6 +3221,7 @@ public static void waitForJQueryLoad() {
//Wait for jQuery to load
wait.until(jQueryLoad);
} catch (Throwable error) {
+ LogUtils.error("Timeout waiting for JQuery load. (" + FrameworkConstants.WAIT_PAGE_LOADED + "s)");
Assert.fail("Timeout waiting for JQuery load. (" + FrameworkConstants.WAIT_PAGE_LOADED + "s)");
}
}
@@ -3295,6 +3252,7 @@ public static void waitForAngularLoad() {
//Wait for jQuery to load
wait.until(angularLoad);
} catch (Throwable error) {
+ LogUtils.error("Timeout waiting for Angular load. (" + FrameworkConstants.WAIT_PAGE_LOADED + "s)");
Assert.fail("Timeout waiting for Angular load. (" + FrameworkConstants.WAIT_PAGE_LOADED + "s)");
}
}
diff --git a/src/main/java/com/anhtester/report/TelegramManager.java b/src/main/java/com/anhtester/report/TelegramManager.java
index b0a0949..c9bf983 100644
--- a/src/main/java/com/anhtester/report/TelegramManager.java
+++ b/src/main/java/com/anhtester/report/TelegramManager.java
@@ -1,7 +1,7 @@
package com.anhtester.report;
import com.anhtester.constants.FrameworkConstants;
-import com.anhtester.helpers.Helpers;
+import com.anhtester.helpers.SystemHelpers;
import com.anhtester.utils.LogUtils;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.model.Message;
@@ -22,7 +22,7 @@ public class TelegramManager {
public static boolean sendFilePath(String filePath) {
boolean success = false;
try {
- File input = new File(Helpers.getCurrentDir() + filePath);
+ File input = new File(SystemHelpers.getCurrentDir() + filePath);
SendDocument request = new SendDocument(ChatId, input).parseMode(ParseMode.HTML).disableNotification(true);
SendResponse sendResponse = bot.execute(request);
boolean ok = sendResponse.isOk();
diff --git a/src/main/java/com/anhtester/utils/JsonUtils.java b/src/main/java/com/anhtester/utils/JsonUtils.java
index f9c9cc3..3956f85 100644
--- a/src/main/java/com/anhtester/utils/JsonUtils.java
+++ b/src/main/java/com/anhtester/utils/JsonUtils.java
@@ -6,7 +6,7 @@
package com.anhtester.utils;
import com.anhtester.constants.FrameworkConstants;
-import com.anhtester.helpers.Helpers;
+import com.anhtester.helpers.SystemHelpers;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext;
@@ -31,7 +31,7 @@ public class JsonUtils {
private static StringBuffer stringBuffer;
private static DocumentContext jsonContext;
private static String lines;
- private static String jsonFilePathDefault = Helpers.getCurrentDir() + "src/test/resources/datajson/store.json";
+ private static String jsonFilePathDefault = SystemHelpers.getCurrentDir() + "src/test/resources/datajson/store.json";
private JsonUtils() {
super();
@@ -41,7 +41,7 @@ private JsonUtils() {
//Nó được thực thi trước phương thức main tại lúc khởi tạo lớp này.
static {
try {
- CONFIGMAP = new ObjectMapper().readValue(new File(Helpers.getCurrentDir() + FrameworkConstants.JSON_DATA_FILE_PATH), new TypeReference>() {
+ CONFIGMAP = new ObjectMapper().readValue(new File(SystemHelpers.getCurrentDir() + FrameworkConstants.JSON_DATA_FILE_PATH), new TypeReference>() {
});
} catch (FileNotFoundException e) {
@@ -64,7 +64,7 @@ public static String get(String key) {
public static StringBuffer readJsonFile(String jsonPath) {
try {
- bufferedReader = new BufferedReader(new FileReader(Helpers.getCurrentDir() + jsonPath));
+ bufferedReader = new BufferedReader(new FileReader(SystemHelpers.getCurrentDir() + jsonPath));
stringBuffer = new StringBuffer();
while ((lines = bufferedReader.readLine()) != null) {
stringBuffer.append(lines);
@@ -79,7 +79,7 @@ public static StringBuffer readJsonFile(String jsonPath) {
public static void setJsonFile(String jsonPath) {
try {
- bufferedReader = new BufferedReader(new FileReader(Helpers.getCurrentDir() + jsonPath));
+ bufferedReader = new BufferedReader(new FileReader(SystemHelpers.getCurrentDir() + jsonPath));
stringBuffer = new StringBuffer();
while ((lines = bufferedReader.readLine()) != null) {
stringBuffer.append(lines);
diff --git a/src/test/java/com/anhtester/dataprovider/DataProviderAddProduct.java b/src/test/java/com/anhtester/dataprovider/DataProviderAddProduct.java
index 633a146..65ffe13 100644
--- a/src/test/java/com/anhtester/dataprovider/DataProviderAddProduct.java
+++ b/src/test/java/com/anhtester/dataprovider/DataProviderAddProduct.java
@@ -2,14 +2,14 @@
import com.anhtester.constants.FrameworkConstants;
import com.anhtester.helpers.ExcelHelpers;
-import com.anhtester.helpers.Helpers;
+import com.anhtester.helpers.SystemHelpers;
import org.testng.annotations.DataProvider;
public class DataProviderAddProduct {
@DataProvider(name = "data_provider_add_product")
public Object[][] dataAddProduct() {
ExcelHelpers excelHelpers = new ExcelHelpers();
- Object[][] data = excelHelpers.getDataHashTable(Helpers.getCurrentDir() + FrameworkConstants.EXCEL_CMS_DATA, "AddProduct", 2, 2);
+ Object[][] data = excelHelpers.getDataHashTable(SystemHelpers.getCurrentDir() + FrameworkConstants.EXCEL_CMS_DATA, "AddProduct", 2, 2);
return data;
}
}
diff --git a/src/test/java/com/anhtester/dataprovider/DataProviderManager.java b/src/test/java/com/anhtester/dataprovider/DataProviderManager.java
index dda2f41..87cb7b3 100644
--- a/src/test/java/com/anhtester/dataprovider/DataProviderManager.java
+++ b/src/test/java/com/anhtester/dataprovider/DataProviderManager.java
@@ -7,7 +7,7 @@
import com.anhtester.constants.FrameworkConstants;
import com.anhtester.helpers.ExcelHelpers;
-import com.anhtester.helpers.Helpers;
+import com.anhtester.helpers.SystemHelpers;
import com.anhtester.helpers.PropertiesHelpers;
import com.anhtester.projects.crm.models.ClientModel;
import com.anhtester.projects.crm.models.SignInModel;
@@ -47,7 +47,7 @@ public void testGetClientData(Hashtable data) {
@DataProvider(name = "getSignInDataHashTable", parallel = true)
public static Object[][] getSignInData() {
ExcelHelpers excelHelpers = new ExcelHelpers();
- Object[][] data = excelHelpers.getDataHashTable(Helpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_FILE_PATH, "SignIn", 1, 2);
+ Object[][] data = excelHelpers.getDataHashTable(SystemHelpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_FILE_PATH, "SignIn", 1, 2);
System.out.println("getSignInData: " + data);
return data;
}
@@ -55,7 +55,7 @@ public static Object[][] getSignInData() {
@DataProvider(name = "getClientDataHashTable", parallel = true)
public static Object[][] getClientData() {
ExcelHelpers excelHelpers = new ExcelHelpers();
- Object[][] data = excelHelpers.getDataHashTable(Helpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_FILE_PATH, "Client", 1, 2);
+ Object[][] data = excelHelpers.getDataHashTable(SystemHelpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_FILE_PATH, "Client", 1, 2);
System.out.println("getClientData: " + data);
return data;
}
diff --git a/src/test/java/com/anhtester/projects/cms/admin/pages/products/AddProductPage.java b/src/test/java/com/anhtester/projects/cms/admin/pages/products/AddProductPage.java
index ad282c7..4f62021 100644
--- a/src/test/java/com/anhtester/projects/cms/admin/pages/products/AddProductPage.java
+++ b/src/test/java/com/anhtester/projects/cms/admin/pages/products/AddProductPage.java
@@ -1,7 +1,7 @@
package com.anhtester.projects.cms.admin.pages.products;
import com.anhtester.driver.DriverManager;
-import com.anhtester.helpers.Helpers;
+import com.anhtester.helpers.SystemHelpers;
import com.anhtester.keywords.WebUI;
import com.anhtester.projects.cms.CommonPageCMS;
import com.anhtester.utils.LogUtils;
@@ -79,13 +79,13 @@ public void addProduct(String productName, String category, String unit, String
WebUI.clickElement(selectChooseGalleryImgs);
WebUI.clickElement(uploadNewImageTab);
//Upload images Gallery with Form
- //WebUI.uploadFileWithLocalForm(buttonBrowseImages, Helpers.getCurrentDir() + "src\\test\\resources\\testdataCMS\\" + imgName);
+ //WebUI.uploadFileWithLocalForm(buttonBrowseImages, SystemHelpers.getCurrentDir() + "src\\test\\resources\\testdataCMS\\" + imgName);
//Upload images Gallery with sendKeys
- DriverManager.getDriver().findElement(inputGalleryImages).sendKeys(Helpers.getCurrentDir() + "src\\test\\resources\\testdataCMS\\" + imgName);
+ DriverManager.getDriver().findElement(inputGalleryImages).sendKeys(SystemHelpers.getCurrentDir() + "src\\test\\resources\\testdataCMS\\" + imgName);
WebUI.clickElement(selectFileTab);
LogUtils.info(imgName);
- LogUtils.info(Helpers.splitString(imgName, "[.]"));
- String imageName = Helpers.splitString(imgName, "[.]").get(0);
+ LogUtils.info(SystemHelpers.splitString(imgName, "[.]"));
+ String imageName = SystemHelpers.splitString(imgName, "[.]").get(0);
//Search and select images
WebUI.setText(inputSearchImg, imageName, Keys.ENTER);
WebUI.waitForJQueryLoad();
diff --git a/src/test/java/com/anhtester/projects/crm/testcases/TestHandle.java b/src/test/java/com/anhtester/projects/crm/testcases/TestHandle.java
index fcaef46..46a9828 100644
--- a/src/test/java/com/anhtester/projects/crm/testcases/TestHandle.java
+++ b/src/test/java/com/anhtester/projects/crm/testcases/TestHandle.java
@@ -8,7 +8,7 @@
import com.anhtester.common.BaseTest;
import com.anhtester.constants.FrameworkConstants;
import com.anhtester.driver.DriverManager;
-import com.anhtester.helpers.Helpers;
+import com.anhtester.helpers.SystemHelpers;
import com.anhtester.keywords.WebUI;
import com.anhtester.projects.crm.pages.Dashboard.DashboardPageCRM;
import com.anhtester.projects.crm.pages.Projects.ProjectPageCRM;
@@ -182,7 +182,7 @@ public void testUploadFileFormDialog() {
By divFileUpload = By.xpath("//div[@id='uploadifive-file_upload']");
By inputFileUpload = By.xpath("//div[@id='file_select_button']//input[@id='file_upload']");
- String filePath = Helpers.getCurrentDir() + "src\\test\\resources\\testdata\\TxtFileData.txt";
+ String filePath = SystemHelpers.getCurrentDir() + "src\\test\\resources\\testdata\\TxtFileData.txt";
WebUI.uploadFileWithLocalForm(divFileUpload, filePath);
@@ -244,17 +244,6 @@ public void checkDataTableWithPagination() {
}
-
- @Test
- public void QRCode() {
- WebUI.openWebsite("http://qrcode.meetheed.com/qrcode_examples.php");
- WebUI.maximizeWindow();
- WebUI.waitForPageLoaded();
- WebUI.moveToElement(By.xpath("(//div[@class = 'topBox'])[1]/img"));
- WebUI.sleep(1);
- WebUI.logConsole(WebUI.getQRCodeFromImage(By.xpath("(//div[@class = 'topBox'])[1]/img")));
- }
-
@Test
public void handleZoomInZoomOut() {
WebUI.openWebsite("https://anhtester.com");
@@ -327,8 +316,8 @@ public void handleUploadFile() {
WebUI.waitForPageLoaded();
WebUI.sleep(1);
- final String path1 = Helpers.getCurrentDir() + "src\\test\\resources\\testdata\\DOCX_File_01.docx";
- final String path2 = Helpers.getCurrentDir() + "src\\test\\resources\\testdata\\LoginCSV.csv";
+ final String path1 = SystemHelpers.getCurrentDir() + "src\\test\\resources\\testdata\\DOCX_File_01.docx";
+ final String path2 = SystemHelpers.getCurrentDir() + "src\\test\\resources\\testdata\\LoginCSV.csv";
//Cách 1 sendKeys link từ source
WebUI.uploadFileWithSendKeys(By.xpath("//input[@id='uploadFile']"), path1);
diff --git a/src/test/java/com/anhtester/projects/crm/testcases/TestSimpleCode.java b/src/test/java/com/anhtester/projects/crm/testcases/TestSimpleCode.java
index 3694ed8..544ec85 100644
--- a/src/test/java/com/anhtester/projects/crm/testcases/TestSimpleCode.java
+++ b/src/test/java/com/anhtester/projects/crm/testcases/TestSimpleCode.java
@@ -7,11 +7,9 @@
import com.anhtester.constants.FrameworkConstants;
import com.anhtester.helpers.*;
-import com.anhtester.helpers.*;
import com.anhtester.keywords.WebUI;
import com.anhtester.report.TelegramManager;
import com.anhtester.utils.*;
-import com.anhtester.utils.*;
import org.testng.annotations.Test;
public class TestSimpleCode {
@@ -117,7 +115,7 @@ public void testRemoveAccent() {
@Test
public void testMakeSlug() {
- WebUI.logConsole(Helpers.makeSlug("Anh Tester Automation Testing"));
+ WebUI.logConsole(SystemHelpers.makeSlug("Anh Tester Automation Testing"));
}
@Test
@@ -129,14 +127,14 @@ public void testReadFileJSON() {
@Test
public void testGetCurrentDirectory() {
- WebUI.logConsole(Helpers.getCurrentDir());
+ WebUI.logConsole(SystemHelpers.getCurrentDir());
}
@Test
public void testSplitString() {
String s1 = "Automation, Testing, Selenium, Java";
- for (String arr : Helpers.splitString(s1, ", ")) {
+ for (String arr : SystemHelpers.splitString(s1, ", ")) {
WebUI.logConsole(arr);
}
}
@@ -152,7 +150,7 @@ public void testEncryptDecryptData() {
@Test
public void testCreateFolder() {
- Helpers.createFolder("src/test/resources/TestCreateNewFolder");
+ SystemHelpers.createFolder("src/test/resources/TestCreateNewFolder");
}
@Test
@@ -163,7 +161,7 @@ public void testPropertiesFile() {
WebUI.logConsole(PropertiesHelpers.getValue("URL_CRM"));
WebUI.logConsole(PropertiesHelpers.getValue("AUTHOR"));
WebUI.logConsole(FrameworkConstants.EXCEL_DATA_FILE_PATH);
- WebUI.logConsole(Helpers.getCurrentDir() + PropertiesHelpers.getValue("EXCEL_DATA_FILE_PATH"));
+ WebUI.logConsole(SystemHelpers.getCurrentDir() + PropertiesHelpers.getValue("EXCEL_DATA_FILE_PATH"));
// PropertiesHelpers.setFile("src/test/resources/config/data.properties");
// PropertiesHelpers.setValue("base_url", "https://anhtetser.com");
}
@@ -185,10 +183,10 @@ public void testReadAndWriteTxtFile() {
@Test
public void testExcelFile1() {
PropertiesHelpers.loadAllFiles();
- WebUI.logConsole(Helpers.getCurrentDir() + PropertiesHelpers.getValue("EXCEL_DATA_FILE_PATH"));
+ WebUI.logConsole(SystemHelpers.getCurrentDir() + PropertiesHelpers.getValue("EXCEL_DATA_FILE_PATH"));
// Handle Excel file
ExcelHelpers excelHelpers = new ExcelHelpers();
- excelHelpers.setExcelFile(Helpers.getCurrentDir() + PropertiesHelpers.getValue("EXCEL_DATA_FILE_PATH"), "SignIn");
+ excelHelpers.setExcelFile(SystemHelpers.getCurrentDir() + PropertiesHelpers.getValue("EXCEL_DATA_FILE_PATH"), "SignIn");
WebUI.logConsole(excelHelpers.getCellData(1, "EMAIL"));
WebUI.logConsole(excelHelpers.getCellData(1, "PASSWORD"));
excelHelpers.setCellData("pass", 1, "EXPECTED_TITLE");
@@ -198,7 +196,7 @@ public void testExcelFile1() {
public void testExcelFile2() throws Exception {
PropertiesHelpers.loadAllFiles();
ExcelHelpers excelHelpers = new ExcelHelpers();
- WebUI.logConsole(excelHelpers.getDataHashTable(Helpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_FILE_PATH, "SignIn", 1, 2));
+ WebUI.logConsole(excelHelpers.getDataHashTable(SystemHelpers.getCurrentDir() + FrameworkConstants.EXCEL_DATA_FILE_PATH, "SignIn", 1, 2));
}
// @Test