Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #354 from sbtqa/fix-pagesource-attach
Browse files Browse the repository at this point in the history
add try catch to page source get
  • Loading branch information
kosteman authored Oct 13, 2021
2 parents 030874f + 49de00d commit e7454b5
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.openqa.selenium.InvalidElementStateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.sbtqa.tag.pagefactory.allure.ErrorHandler;
import ru.sbtqa.tag.pagefactory.allure.ParamsHelper;
import ru.sbtqa.tag.pagefactory.allure.Type;
Expand All @@ -17,6 +20,7 @@
@Aspect
public class ErrorHandlerAspect {

private static final Logger LOG = LoggerFactory.getLogger(ErrorHandlerAspect.class);
private static final Configuration PROPERTIES = Configuration.create();

private final ThreadLocal<String> stepText = ThreadLocal.withInitial(() -> "");
Expand All @@ -35,10 +39,13 @@ public void sendStepFinished(ProceedingJoinPoint joinPoint, Event event) throws
&& !stepText.get().equals(Allure.getLifecycle().getCurrentTestCaseOrStep().toString())) {
stepText.set(Allure.getLifecycle().getCurrentTestCaseOrStep().toString());
ErrorHandler.attachError(testStepFinished.result.getError());
System.out.println(" " + testStepFinished.result.getError());
ErrorHandler.attachScreenshot();
if (PROPERTIES.isReportXmlAttachEnabled()) {
ParamsHelper.addAttachmentToRender(Environment.getDriverService().getDriver().getPageSource().getBytes(), "Page source", Type.XML);
try {
ParamsHelper.addAttachmentToRender(Environment.getDriverService().getDriver().getPageSource().getBytes(), "Page source", Type.XML);
} catch (InvalidElementStateException e) {
LOG.error("Can't attach page source", e);
}
}
}
joinPoint.proceed();
Expand Down

0 comments on commit e7454b5

Please sign in to comment.