Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: Ismail Elshafeiy <ismail.elshafeiy@gmail.com>
  • Loading branch information
ismail-elshafeiy committed Dec 30, 2023
1 parent 64949b2 commit 7db0beb
Show file tree
Hide file tree
Showing 75 changed files with 2,892 additions and 2,558 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
.project
/.idea/
/.github/workflows/
/ScreenShot/
/src/test/resources/downloads/ScreenShot/
/.github/workflows/
/video/
12 changes: 0 additions & 12 deletions ConsoleLogs/testConsole.txt

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="src/test/resources/images/automation.png" alt="Me" width="250" height="200" style="display:block; margin-left:auto; margin-right:auto;"/>
<img src="src/test/resources/TestData/images/automation.png" alt="Me" width="250" height="200" style="display:block; margin-left:auto; margin-right:auto;"/>

# 🔧 Technologies

Expand Down
21 changes: 17 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<org.yaml.version>2.0</org.yaml.version>
<!-- Reports frameworks -->
<allure-testng.version>2.25.0</allure-testng.version>
<allure-maven.version>2.12.0</allure-maven.version>
<allure-maven.version>2.25.0</allure-maven.version>
<allure-maven-report.version>2.10.0</allure-maven-report.version>
<allure-environment-writer.version>1.0.0</allure-environment-writer.version>
<allure.cmd.download.url>
Expand Down Expand Up @@ -710,8 +710,22 @@
<artifactId>csv-comparator</artifactId>
<version>${csv-compartor-version}</version>
</dependency>
</dependencies>

<!-- https://mvnrepository.com/artifact/e-iceblue/spire.xls -->
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls</artifactId>
<version>13.11.0</version>
</dependency>

</dependencies>
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>

<build>
<resources>
Expand Down Expand Up @@ -763,8 +777,7 @@
</property>
<property>
<name>listener</name>
<value>com.engine.listeners.TestngListener, com.engine.listeners.WebListener
</value>
<value>com.engine.listeners.TestNGListener, com.engine.listeners.WebListener</value>
</property>
</properties>
</configuration>
Expand Down
134 changes: 75 additions & 59 deletions src/main/java/com/engine/actions/BrowserActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
import com.engine.Helper;
import com.engine.Waits;
import com.engine.constants.FrameworkConstants;
import com.engine.reports.Attachments;
import com.engine.dataDriven.PropertiesManager;
import com.engine.evidence.RecordVideo;
import com.engine.reports.AllureReport;
import com.engine.reports.ExtentReport;
import io.qameta.allure.Step;
import org.openqa.selenium.*;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.bidi.BiDiException;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.devtools.DevToolsException;
import org.openqa.selenium.print.PrintOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.testng.ITestResult;
import com.engine.reports.CustomReporter;

import java.io.File;
import java.nio.file.Files;
import java.util.*;

import static com.engine.reports.CustomReporter.passAction;
import static org.testng.Assert.fail;

public class BrowserActions {
Expand All @@ -26,6 +33,10 @@ public BrowserActions(WebDriver driver) {
BrowserActions.driver = driver;
}

public static BrowserActions getInstance() {
return new BrowserActions(driver);
}

@Step("Navigate to URL: [{url}]")
public static void navigateToUrl(WebDriver driver, String url) {
try {
Expand Down Expand Up @@ -148,8 +159,6 @@ public static void getWindowPositions(WebDriver driver) {
}
}


//****** Switch Windows ******//
public enum PageType {
WINDOW("window"), TAB("tab");
private final String windowType;
Expand Down Expand Up @@ -201,21 +210,18 @@ public static void switchToNewWindowByClickHyperLink(WebDriver driver, By elemen
@Step("Check the test result and Close All Opened Browser Windows.....")
public static void closeAllOpenedBrowserWindows(WebDriver driver, ITestResult result) throws Throwable {
if (ITestResult.FAILURE == result.getStatus()) {
Attachments.attachScreenshotToAllureReport(driver);
Attachments.attachScreenshotToExtentReport(driver);
AllureReport.attachScreenshotToAllureReport(driver);
ExtentReport.attachScreenshotToExtentReport(driver);
CustomReporter.logConsoleLogs(driver, result);
// if (System.getProperty("videoParams_scope").trim().equals("DriverSession")) {
// RecordManager.attachVideoRecording();
// }
closeAllOpenedBrowserWindows(driver);
// eyesManager.abort();
}
// RecordManager.attachVideoRecording();
closeAllOpenedBrowserWindows(driver);
// eyesManager.abort();
}

@Step("Close All Opened Browser Windows.....")
public static void closeAllOpenedBrowserWindows(WebDriver driver) {
CustomReporter.logInfoStep("[Browser Action] Close all Opened Browser Windows");
RecordVideo.attachVideoRecording();
if (driver != null) {
try {
driver.quit();
Expand All @@ -232,7 +238,10 @@ public static void closeAllOpenedBrowserWindows(WebDriver driver) {
//*********************************************************************************************//

public enum AlertAction {
ACCEPT("accept"), DISMISS("dismiss"), SET_TEXT("Text"), GET_TEXT("Get Text");
ACCEPT("accept"),
DISMISS("dismiss"),
SET_TEXT("Text"),
GET_TEXT("Get Text");
private final String alertType;

AlertAction(String alertType) {
Expand Down Expand Up @@ -390,6 +399,21 @@ public BrowserActions goBack() {
return this;
}

public static void goBackUsingJavascript(WebDriver driver) {
try {
CustomReporter.logInfoStep("[Browser Action] Navigate Back from [" + getCurrentUrl(driver) + "]");
((JavascriptExecutor) driver).executeScript("window.history.go(-1)");
} catch (Exception e) {
CustomReporter.logInfoStep(e.getMessage());
fail(e.getMessage());
}
}

public BrowserActions goBackUsingJavascript() {
goBackUsingJavascript(driver);
return this;
}

public static void goForward(WebDriver driver) {
try {
driver.navigate().forward();
Expand All @@ -405,6 +429,22 @@ public BrowserActions goForward() {
return this;
}

public static void goForwardUsingJavascript(WebDriver driver) {
try {
((JavascriptExecutor) driver).executeScript("window.history.forward()");
CustomReporter.logInfoStep("[Browser Action] Navigate Forward [" + getCurrentUrl(driver) + "]");
} catch (Exception e) {
CustomReporter.logError(e.getMessage());
fail(e.getMessage());
}
}

public BrowserActions goForwardUsingJavascript() {
goForwardUsingJavascript(driver);
return this;
}


public static void refreshPage(WebDriver driver) {
try {
CustomReporter.logInfoStep("[Browser Action] Refresh current page [" + getCurrentUrl(driver) + "]");
Expand Down Expand Up @@ -495,13 +535,16 @@ public BrowserActions getCurrentUrlUsingJavaScript() {
return this;
}

//**********************************************************************************************//
//************************************** Others Methods **************************************//
//*********************************************************************************************//
public BrowserActions capturePageSnapshot() {
var serializedPageData = capturePageSnapshot(driver);
passAction(driver, serializedPageData);
return this;
}

public static String capturePageSnapshot(WebDriver driver) {
private static String capturePageSnapshot(WebDriver driver) {
CustomReporter.logConsole("Capturing page snapshot...");
var serializedPageData = "";
try {
Expand All @@ -526,53 +569,26 @@ public static String capturePageSnapshot(WebDriver driver) {
}
}

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);
}

private static String reportActionResult(WebDriver driver, String actionName, String testData,
Boolean passFailStatus,
Exception... rootCauseException) {
actionName = Helper.convertToSentenceCase(actionName);
String message;
if (Boolean.TRUE.equals(passFailStatus)) {
message = "Browser Action: " + actionName;
} else {
message = "Browser Action: " + actionName + " failed";
}
static String pdfPath = PropertiesManager.getPropertyValue("paths.properties", "pdfPath");

List<List<Object>> attachments = new ArrayList<>();
if (testData != null && !testData.isEmpty()) {
if (testData.length() >= 500 || testData.contains("</iframe>") || testData.contains("</html>") || testData.startsWith("From: <Saved by Blink>")) {
List<Object> actualValueAttachment = Arrays.asList("Browser Action Test Data - " + actionName,
"Actual Value", testData);
attachments.add(actualValueAttachment);
} else {
message = message + " \"" + testData.trim() + "\"";
}
}

if (rootCauseException != null && rootCauseException.length >= 1) {
List<Object> actualValueAttachment = Arrays.asList("Browser Action Exception - " + actionName,
"Stacktrace", CustomReporter.formatStackTraceToLogEntry(rootCauseException[0]));
attachments.add(actualValueAttachment);
}

message = message + ".";

message = message.replace("Browser Action: ", "");
if (!attachments.equals(new ArrayList<>())) {
CustomReporter.logAttachments(message, attachments);
} else {
CustomReporter.logInfoStep(message);
/**
* Print the page using the PrintOptions class and the PrintsPage interface of the WebDriver class
*
* @param driver - WebDriver Instance of the Browser
* @param pageRange - Page Range to be printed
* @throws
*/
public static void printPage(WebDriver driver, int pageRange) {
try {
CustomReporter.logInfoStep("Printing " + driver.getTitle() + " page....... ");
PrintsPage printer = ((PrintsPage) driver);
PrintOptions printOptions = new PrintOptions();
printOptions.setPageRanges(String.valueOf(pageRange));
Pdf pdf = printer.print(printOptions);
Files.write(new File(pdfPath + driver.getTitle() + Helper.getCurrentTime() + ".pdf").toPath(), OutputType.BYTES.convertFromBase64Png(pdf.getContent()));
} catch (Exception e) {
e.printStackTrace();
CustomReporter.logError("Page not printed: " + e.getMessage());
}
return message;
}


}
63 changes: 63 additions & 0 deletions src/main/java/com/engine/actions/ElementActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public ElementActions(WebDriver driver) {
this.driver = driver;
}

public static ElementActions getInstance() {
return new ElementActions(driver);
}


@Step("Click on element: [{elementLocator}]")
public static void click(WebDriver driver, By elementLocator) {
Expand Down Expand Up @@ -409,6 +413,65 @@ public static boolean ClipboardActions(WebDriver driver, ClipboardAction action)
return false;
}
}
//************************************** drawing Actions **********************************************//
//******************************************************************************************************************//

public static void drawCircle(WebDriver driver, By canvasElement) {
ElementHelper.locatingElementStrategy(driver, canvasElement);
try {
actions = new Actions(driver);
CustomReporter.logInfoStep("[Element Action] Drawing [" + driver.findElement(canvasElement).getText() + "] ");
actions.moveToElement(driver.findElement(canvasElement)).clickAndHold();
int numPoints = 10;
int radius = 50;
for (int i = 0; i < numPoints; i++) {
double theta = (2 * Math.PI * i) / numPoints;
int x = (int) (radius * Math.cos(theta));
int y = (int) (radius * Math.sin(theta));
actions.moveByOffset(x, y).perform();
}
actions.release(driver.findElement(canvasElement)).build().perform();
} catch (Exception e) {
CustomReporter.logError(e.getMessage());
fail(e.getMessage());
}
}

public static void drawUsingJavaScript(WebDriver driver, By canvasElement) {
int canvasWidth = driver.findElement(canvasElement).getSize().getWidth();
int canvasHeight = driver.findElement(canvasElement).getSize().getHeight();
// Calculate the offsets for drawing the signature
int startX = canvasWidth / 4; // Adjust as needed
int startY = canvasHeight / 2; // Adjust as needed
// Use JavaScript to simulate mouse movements for drawing
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousedown', {" +
"clientX: " + startX + ", clientY: " + startY + "}));", driver.findElement(canvasElement));
// Simulate drawing strokes (adjust offsets and add more points as needed)
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 100) + ", clientY: " + (startY + 30) + "}));", driver.findElement(canvasElement));
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 80) + ", clientY: " + (startY + 20) + "}));", driver.findElement(canvasElement));
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 60) + ", clientY: " + (startY + -20) + "}));", driver.findElement(canvasElement));
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 40) + ", clientY: " + (startY + -40) + "}));", driver.findElement(canvasElement));
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 20) + ", clientY: " + (startY + -60) + "}));", driver.findElement(canvasElement));
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 10) + ", clientY: " + (startY + -80) + "}));", driver.findElement(canvasElement));
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 5) + ", clientY: " + (startY + -100) + "}));", driver.findElement(canvasElement));
// Simulate drawing strokes (adjust offsets and add more points as needed)
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 70) + ", clientY: " + (startY + 10) + "}));", driver.findElement(canvasElement));
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mousemove', {" +
"clientX: " + (startX + 30) + ", clientY: " + (startY + 30) + "}));", driver.findElement(canvasElement));
// Release the mouse button to complete the signature
jsExecutor.executeScript("arguments[0].dispatchEvent(new MouseEvent('mouseup', {" +
"clientX: " + (startX + 100) + ", clientY: " + (startY + 100) + "}));", driver.findElement(canvasElement));

}
//******************************************* Java script actions **********************************************************//
//***********************************************************************************************************************************//

Expand Down
Loading

0 comments on commit 7db0beb

Please sign in to comment.