Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.cloudbeat.common.annotation;

import io.cloudbeat.common.reporter.model.TestStatus;

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Documented
@Inherited
@Repeatable(CbFailures.class)
public @interface CbFailure {
Class<? extends Exception> value();
String reason() default "";
String status() default "";
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.cloudbeat.common.annotation;

import java.lang.annotation.*;

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface CbFailures {
CbFailure[] value();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.cloudbeat.common.annotation;

import java.lang.annotation.*;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Repeatable(CbJiraLinks.class)
public @interface CbJira {
String value();
String source() default CbLink.SRC_JIRA;
String type() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.cloudbeat.common.annotation;

import java.lang.annotation.*;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface CbJiraLinks {
CbJira[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.cloudbeat.common.annotation;

import java.lang.annotation.*;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Repeatable(CbLinks.class)
public @interface CbLink {
String value();
String source() default ""; // e.g. Jira, XRay, ADO, etc.
String type() default ""; // e.g. Story, Task, Test Plan, Test Case, etc.
// Possible "source" values
public static final String SRC_URL = "url";
public static final String SRC_JIRA = "jira";
public static final String SRC_XRAY = "xray";
public static final String SRC_AZURE_DEVOPS = "ado";
public static final String SRC_TESTRAIL = "testrail";

// Possible "type" values
public static final String TYPE_EPIC = "epic";
public static final String TYPE_STORY = "story";
public static final String TYPE_TASK = "task";
public static final String TYPE_TEST_PLAN = "plan";
public static final String TYPE_TEST_CASE = "case";
public static final String TYPE_TEST_BUG = "bug";
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.cloudbeat.common.annotation;

import java.lang.annotation.*;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface CbLinks {
CbLink[] value();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.cloudbeat.common.annotation;

import java.lang.annotation.*;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Repeatable(CbXrayLinks.class)
public @interface CbXray {
String value();
String source() default CbLink.SRC_XRAY;
String type() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.cloudbeat.common.annotation;

import java.lang.annotation.*;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface CbXrayLinks {
CbXray[] value();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.cloudbeat.common.reporter.model.AttachmentType;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -55,6 +56,20 @@ public static Attachment prepareScreenshotAttachment(final byte[] data) {
}
return attachment;
}
public static Attachment preparePageSourceAttachment(final String pageSource) {
if (pageSource == null) return null;
Attachment attachment = new Attachment(AttachmentType.SNAPSHOT);
attachment.setSubtype(AttachmentSubType.SNAPSHOT_HTML);
final String fileExtension = "htm";
Path htmlFilePath = getAttachmentFilePath(attachment, fileExtension);
if (htmlFilePath == null) return null;
try {
Files.write(htmlFilePath, pageSource.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
return null;
}
return attachment;
}
public static Attachment prepareHarAttachment(final HarLog harLog) {
Attachment attachment = new Attachment(AttachmentType.HAR);
final String fileExtension = "har";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ else if (lastSuiteResult.get() != null)
Attachment attachment = AttachmentHelper.prepareScreencastAttachment(videoFilePath);
resultWithAttachment.addAttachment(attachment);
}

public void addScreencastAttachment(final byte[] videoData, final boolean addToStep) {
final IResultWithAttachment resultWithAttachment;
if (addToStep && startedStepsQueue.get() != null && !startedStepsQueue.get().isEmpty()) {
Expand Down Expand Up @@ -709,7 +710,29 @@ else if (lastSuiteResult.get() != null)
resultWithAttachment.addAttachment(attachment);
}


public void addPageSourceAttachment(final String pageSource, final boolean addToStep) {
final IResultWithAttachment resultWithAttachment;
if (addToStep && startedStepsQueue.get() != null && !startedStepsQueue.get().isEmpty()) {
resultWithAttachment = startedStepsQueue.get().peek();
}
else if (!addToStep) {
if (lastCaseResult.get() != null)
resultWithAttachment = lastCaseResult.get();
else if (lastSuiteResult.get() != null)
resultWithAttachment = lastSuiteResult.get();
else
return;
}
else
return;
Attachment attachment = AttachmentHelper.preparePageSourceAttachment(pageSource);
resultWithAttachment.addAttachment(attachment);
}
public void addPageSourceAttachment(final String pageSource, final IResultWithAttachment result) {
if (result == null) return;
Attachment attachment = AttachmentHelper.preparePageSourceAttachment(pageSource);
result.addAttachment(attachment);
}

private static String getHostName() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
public enum AttachmentSubType {
IMAGE_SCREENSHOT("screenshot"),
VIDEO_SCREENCAST("screencast"),
NETWORK_HAR("har");
NETWORK_HAR("har"),
SNAPSHOT_PLAYWRIGHT("playwrightTrace"),
SNAPSHOT_XML("xml"),
SNAPSHOT_HTML("html"),
SNAPSHOT_TEXT("text");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public enum AttachmentType {
TEXT("text"),
LOG("log"),
HAR("har"),
OTHER("other");
OTHER("other"),
SNAPSHOT("snapshot");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.cloudbeat.common.CbTestContext;
import io.cloudbeat.common.helper.StackTraceHelper;
import io.cloudbeat.common.helper.WebDriverHelper;

import java.io.PrintWriter;
import java.io.StringWriter;

Expand Down Expand Up @@ -32,12 +31,12 @@ public FailureResult(Throwable throwable) {
StackTraceElement[] filteredStackTrace =
StackTraceHelper.getStackTraceStartingFromPackage(throwable.getStackTrace(), testPackageName);
this.subtype = throwable.getClass().getSimpleName();
this.type = throwable.getClass().getSimpleName();
this.type = getFailureType(throwable);
this.data = stackTrace;
this.stacktrace = StackTraceHelper.stackTraceToStringArray(filteredStackTrace);
this.message = throwable.getMessage();
if(this.message == null) {
this.message = "UNKNOWN_ERROR ";
this.message = "UNKNOWN_ERROR";
}
// set location attribute
if (filteredStackTrace.length > 0) {
Expand All @@ -52,6 +51,23 @@ private static String getTestPackageName() {
return ctx.getCurrentTestClass().getPackage().getName();
return null;
}
private static String getFailureType(Throwable throwable) {
String className = throwable.getClass().getName();
if (className.startsWith("org.openqa.selenium")) {
String simpleName = throwable.getClass().getSimpleName();
if (simpleName.equals("NoSuchElementException"))
return "ELEMENT_NOT_FOUND";
if (simpleName.equals("TimeoutException"))
return "TIMEOUT";
if (simpleName.equals("ElementNotVisibleException")
|| simpleName.equals("ElementNotInteractableException"))
return "ELEMENT_NOT_VISIBLE";
return "SELENIUM_ERROR";
}
if (throwable instanceof AssertionError)
return "ASSERT_ERROR";
return FAILURE_TYPE;
}

public String getType() {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public interface AbstractWebDriver {
public void disableDevToolsNetworkCapturing();
public HarLog getHarLog();
public String getScreenshot();
public String getPageSource();
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,31 @@ public void afterSwitchToWindow(final String windowName) {
}


public void onException(final Throwable throwable) {
public void onException(final Throwable throwable, boolean takeScreenshot, boolean savePageSource) {
String screenshot = null;
String pageSource = null;
// try to take a screenshot
try {
// try to take a screenshot
String screenshot = wrapper.getScreenshot();
if (lastStepId != null)
reporter.failStep(lastStepId, throwable, screenshot);
else
reporter.setScreenshotOnException(screenshot);
if (takeScreenshot)
screenshot = wrapper.getScreenshot();
}
catch (Throwable e) {}
// try to take a page source
try {
if (savePageSource)
pageSource = wrapper.getPageSource();
}
catch (Throwable e) {}
if (lastStepId != null) {
StepResult stepResult = reporter.failStep(lastStepId, throwable, screenshot);
if (stepResult != null && pageSource != null)
reporter.addPageSourceAttachment(pageSource, stepResult);
}
else {
reporter.setScreenshotOnException(screenshot);
if (pageSource != null)
reporter.addPageSourceAttachment(pageSource, true);
}
}

public void beforeGetText(final AbstractWebElement elm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ public final class WrapperOptions {
private boolean ignoreFindElement = true;
private boolean ignoreFindElements = false;
private boolean fullPageScreenshot = true;
private boolean takeScreenshotOnError = true;
private boolean savePageSourceOnError = false;

public WrapperOptions() {}

public WrapperOptions(boolean ignoreFindElement, boolean fullPageScreenshot) {
this.ignoreFindElement = ignoreFindElement;
this.fullPageScreenshot = fullPageScreenshot;
}
public WrapperOptions(boolean ignoreFindElement, boolean fullPageScreenshot, boolean takeScreenshotOnError, boolean savePageSourceOnError) {
this.ignoreFindElement = ignoreFindElement;
this.fullPageScreenshot = fullPageScreenshot;
}

public boolean isIgnoreFindElement() {
return ignoreFindElement;
Expand All @@ -23,6 +29,12 @@ public boolean isIgnoreFindElements() {
public boolean isFullPageScreenshot() {
return fullPageScreenshot;
}
public boolean isTakeScreenshotOnError() {
return takeScreenshotOnError;
}
public boolean isSavePageSourceOnError() {
return savePageSourceOnError;
}

public void setIgnoreFindElement(boolean ignoreFindElement) {
this.ignoreFindElement = ignoreFindElement;
Expand All @@ -35,4 +47,10 @@ public void setIgnoreFindElements(boolean ignoreFindElements) {
public void setFullPageScreenshot(boolean fullPageScreenshot) {
this.fullPageScreenshot = fullPageScreenshot;
}
public void setTakeScreenshotOnError(boolean takeScreenshotOnError) {
this.takeScreenshotOnError = takeScreenshotOnError;
}
public void setSavePageSourceOnError(boolean savePageSourceOnError) {
this.savePageSourceOnError = savePageSourceOnError;
}
}
Loading
Loading