-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from eliasnogueira/allure-screenshot
Allure screenshot
- Loading branch information
Showing
6 changed files
with
58 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/eliasnogueira/report/AllureTestLifecycleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/io.qameta.allure.listener.TestLifecycleListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.eliasnogueira.report.AllureTestLifecycleListener |