Skip to content

Commit

Permalink
Merge pull request #261 from eliasnogueira/allure-screenshot
Browse files Browse the repository at this point in the history
Allure screenshot
  • Loading branch information
eliasnogueira authored Apr 20, 2024
2 parents bbc7f86 + 476781b commit 16cd618
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 96 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.eliasnogueira</groupId>
<artifactId>selenium-java-lean-test-architecture</artifactId>
<version>3.4.2</version>
<version>3.4.3</version>

<scm>
<connection>scm:[email protected]:eliasnogueira/selenium-java-lean-test-architecture.git</connection>
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/eliasnogueira/report/AllureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@

package com.eliasnogueira.report;

import com.eliasnogueira.driver.DriverManager;
import com.eliasnogueira.enums.Target;
import com.github.automatedowl.tools.AllureEnvironmentWriter;
import com.google.common.collect.ImmutableMap;
import io.qameta.allure.Attachment;
import org.openqa.selenium.TakesScreenshot;

import java.util.HashMap;
import java.util.Map;

import static com.eliasnogueira.config.ConfigurationManager.configuration;
import static org.openqa.selenium.OutputType.BYTES;

public class AllureManager {

Expand All @@ -59,14 +55,4 @@ public static void setAllureEnvironmentInformation() {

AllureEnvironmentWriter.allureEnvironmentWriter(ImmutableMap.copyOf(basicInfo));
}

@Attachment(value = "Failed test screenshot", type = "image/png")
public static byte[] takeScreenshotToAttachOnAllureReport() {
return ((TakesScreenshot) DriverManager.getDriver()).getScreenshotAs(BYTES);
}

@Attachment(value = "Browser information", type = "text/plain")
public static String addBrowserInformationOnAllureReport() {
return DriverManager.getInfo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* MIT License
*
* Copyright (c) 2024 Elias Nogueira
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.eliasnogueira.report;

import com.eliasnogueira.driver.DriverManager;
import io.qameta.allure.Attachment;
import io.qameta.allure.listener.TestLifecycleListener;
import io.qameta.allure.model.TestResult;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

import static io.qameta.allure.model.Status.BROKEN;
import static io.qameta.allure.model.Status.FAILED;

/*
* Approach implemented using the https://github.com/biczomate/allure-testng7.5-attachment-example as reference
*/
public class AllureTestLifecycleListener implements TestLifecycleListener {

public AllureTestLifecycleListener() {
}

@Attachment(value = "Page Screenshot", type = "image/png")
public byte[] saveScreenshot(WebDriver driver) {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}

@Override
public void beforeTestStop(TestResult result) {
if (FAILED == result.getStatus() || BROKEN == result.getStatus()) {
saveScreenshot(DriverManager.getDriver());
}
}
}
2 changes: 0 additions & 2 deletions src/test/java/com/eliasnogueira/BaseWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Listeners;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

import static com.eliasnogueira.config.ConfigurationManager.configuration;

@Listeners({TestListener.class})
public abstract class BaseWeb {

@BeforeSuite
Expand Down
79 changes: 0 additions & 79 deletions src/test/java/com/eliasnogueira/TestListener.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.eliasnogueira.report.AllureTestLifecycleListener

0 comments on commit 16cd618

Please sign in to comment.