com.shaft.gui.browser.internal.BrowserActionsHelpers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SHAFT_ENGINE Show documentation
Show all versions of SHAFT_ENGINE Show documentation
SHAFT is a unified test automation engine. Powered by best-in-class frameworks, SHAFT provides a
wizard-like syntax to drive your automation efficiently, maximize your ROI, and minimize your learning curve.
Stop reinventing the wheel. Upgrade now!
package com.shaft.gui.browser.internal;
import com.google.common.net.InternetDomainName;
import com.shaft.db.DatabaseActions;
import com.shaft.driver.SHAFT;
import com.shaft.gui.internal.image.ScreenshotManager;
import com.shaft.tools.internal.support.JavaHelper;
import com.shaft.tools.internal.support.JavaScriptHelper;
import com.shaft.tools.io.ReportManager;
import com.shaft.tools.io.internal.FailureReporter;
import com.shaft.tools.io.internal.ReportManagerHelper;
import lombok.SneakyThrows;
import org.apache.logging.log4j.Level;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.*;
import org.openqa.selenium.bidi.BiDiException;
import org.openqa.selenium.bidi.browsingcontext.BrowsingContext;
import org.openqa.selenium.bidi.browsingcontext.ReadinessState;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.devtools.DevToolsException;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.awt.*;
import java.io.File;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.List;
import java.util.*;
public class BrowserActionsHelpers {
private static final Boolean HEADLESS_EXECUTION = SHAFT.Properties.web.headlessExecution();
private static final int NAVIGATION_TIMEOUT_INTEGER = SHAFT.Properties.timeouts.browserNavigationTimeout();
public static void passAction(String testData) {
String actionName = Thread.currentThread().getStackTrace()[2].getMethodName();
passAction(null, actionName, testData);
}
public static void passAction(WebDriver driver, String testData) {
String actionName = Thread.currentThread().getStackTrace()[2].getMethodName();
passAction(driver, actionName, testData);
}
public static void passAction(WebDriver driver, String actionName, String testData) {
reportActionResult(driver, actionName, testData, true);
}
public static void failAction(Exception... rootCauseException) {
String actionName = Thread.currentThread().getStackTrace()[2].getMethodName();
failAction(null, actionName, "", rootCauseException);
}
public static void failAction(WebDriver driver, String testData, Exception... rootCauseException) {
String actionName = Thread.currentThread().getStackTrace()[2].getMethodName();
failAction(driver, actionName, testData, rootCauseException);
}
public static void failAction(WebDriver driver, String actionName, String testData,
Exception... rootCauseException) {
String message = reportActionResult(driver, actionName, testData, false, rootCauseException);
if (rootCauseException != null && rootCauseException.length > 0) {
FailureReporter.fail(DatabaseActions.class, message, rootCauseException[0]);
} else {
FailureReporter.fail(message);
}
}
private static String reportActionResult(WebDriver driver, String actionName, String testData,
Boolean passFailStatus,
Exception... rootCauseException) {
actionName = JavaHelper.convertToSentenceCase(actionName);
String message;
if (Boolean.TRUE.equals(passFailStatus)) {
message = "Browser Action: " + actionName;
} else {
message = "Browser Action: " + actionName + " failed";
}
List> attachments = new ArrayList<>();
if (testData != null && !testData.isEmpty()) {
if (testData.length() >= 500 || testData.contains("") || testData.contains("