From 4369a338379dadbad891a93fe8d7153ed0f3c7a4 Mon Sep 17 00:00:00 2001 From: mmrahman Date: Wed, 2 Jun 2021 10:41:55 -0400 Subject: [PATCH 1/2] Added script to support video recording add to extent report --- pom.xml | 14 ++++++++++++++ .../com/dougnoel/sentinel/steps/BaseSteps.java | 11 ++++++++++- .../java/features/47 Swag Labs Login.feature | 5 ++++- src/test/java/tests/SentinelTests.java | 18 +++++++++++++----- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index fb6a4ba8..8c341b36 100644 --- a/pom.xml +++ b/pom.xml @@ -101,6 +101,8 @@ dougnoel_sentinel dougnoel https://sonarcloud.io + + 0.7.7.0 @@ -369,6 +371,13 @@ import + + + com.github.stephenc.monte + monte-screen-recorder + ${screen-recorder.version} + + org.apache.commons commons-lang3 @@ -534,6 +543,11 @@ org.apache.logging.log4j log4j-api + + + com.github.stephenc.monte + monte-screen-recorder + org.apache.commons diff --git a/src/main/java/com/dougnoel/sentinel/steps/BaseSteps.java b/src/main/java/com/dougnoel/sentinel/steps/BaseSteps.java index da4fd885..ccf617de 100644 --- a/src/main/java/com/dougnoel/sentinel/steps/BaseSteps.java +++ b/src/main/java/com/dougnoel/sentinel/steps/BaseSteps.java @@ -3,6 +3,8 @@ import static com.dougnoel.sentinel.elements.ElementFunctions.getElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; + +import com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter; import com.dougnoel.sentinel.configurations.Configuration; import com.dougnoel.sentinel.configurations.Time; import com.dougnoel.sentinel.pages.PageManager; @@ -10,6 +12,7 @@ import io.cucumber.java.Before; import io.cucumber.java.Scenario; import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; import io.cucumber.java.en.When; /** @@ -172,4 +175,10 @@ public static void pressBrowserButton(String option) { } } -} \ No newline at end of file + @Then("^video recording (.*?)( was not)?(?: was)? attached to the report?$") + public static void addVideoToReport(String elementName, String assertion) { + if(Configuration.toString("addVideoToReport")!=null && !elementName.contains("not")) + ExtentCucumberAdapter.addTestStepLog("Click to see video recording"); + + } +} diff --git a/src/test/java/features/47 Swag Labs Login.feature b/src/test/java/features/47 Swag Labs Login.feature index 434cded2..fe1898b9 100644 --- a/src/test/java/features/47 Swag Labs Login.feature +++ b/src/test/java/features/47 Swag Labs Login.feature @@ -13,10 +13,13 @@ Feature: 47 Swag Labs Login And I click the Login Button Then I am redirected to the Sauce Demo Main Page And I verify the App Logo exists + And video recording was attached to the report @47B Scenario: 47B Failed Login with Locked Out User Given I am on the Sauce Demo Login Page When I fill the account information for account LockedOutUser into the Username field and the Password field And I click the Login Button - Then I verify the Error Message contains the text "Sorry, this user has been locked out." \ No newline at end of file + Then I verify the Error Message contains the text "Sorry, this user has been locked out." + And video recording was not attached to the report + \ No newline at end of file diff --git a/src/test/java/tests/SentinelTests.java b/src/test/java/tests/SentinelTests.java index 6a9d8272..baa28fe9 100644 --- a/src/test/java/tests/SentinelTests.java +++ b/src/test/java/tests/SentinelTests.java @@ -3,13 +3,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.runner.RunWith; - import com.dougnoel.sentinel.configurations.Configuration; -import com.dougnoel.sentinel.exceptions.SentinelException; import com.dougnoel.sentinel.pages.PageManager; import com.dougnoel.sentinel.webdrivers.WebDriverFactory; - +import com.dougnoel.sentinel.utilities.*; import io.cucumber.junit.CucumberOptions; import io.cucumber.junit.Cucumber; @@ -20,14 +19,21 @@ , plugin = {"json:target/cucumber.json", "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"} , strict = true -// , tags = { "@text" } + //, tags = { "@47" } ) public class SentinelTests { private static final Logger log = LogManager.getLogger(SentinelTests.class); // Create a logger. + @BeforeClass + public static void setUpBeforeClass() { + WebDriverFactory.instantiateWebDriver(); + if(Configuration.toString("addVideoToReport")!=null) + SentinelScreenRecorder.startRecording("extent-cucumber"); + } + @AfterClass - public static void tearDownAfterClass() throws SentinelException { + public static void tearDownAfterClass() throws Exception { String totalWaitTime = Configuration.toString("totalWaitTime"); if (totalWaitTime != null) { log.warn("This test took {} total seconds longer due to explicit waits. Sentinel handles dynamic waits. If you have a reason for adding explicit waits, you should probably be logging a bug ticket to get the framework fixed at: http://https://github.com/dougnoel/sentinel/issues", totalWaitTime); @@ -36,5 +42,7 @@ public static void tearDownAfterClass() throws SentinelException { if (System.getProperty("leaveBrowserOpen", "false") == "false") { PageManager.quit(); } + if(Configuration.toString("addVideoToReport")!=null) + SentinelScreenRecorder.stopRecording(); } } \ No newline at end of file From 5958d486a3a4422ef055a621c9e0d97c34f89f99 Mon Sep 17 00:00:00 2001 From: Doug Noel Date: Fri, 14 Jan 2022 09:54:22 -0500 Subject: [PATCH 2/2] Added in custom screen recorder code that was missing. --- .../filemanagers/SentinelScreenRecorder.java | 31 +++++++++++++++++++ src/test/java/tests/SentinelTests.java | 12 +++---- 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/dougnoel/sentinel/filemanagers/SentinelScreenRecorder.java diff --git a/src/main/java/com/dougnoel/sentinel/filemanagers/SentinelScreenRecorder.java b/src/main/java/com/dougnoel/sentinel/filemanagers/SentinelScreenRecorder.java new file mode 100644 index 00000000..602ec680 --- /dev/null +++ b/src/main/java/com/dougnoel/sentinel/filemanagers/SentinelScreenRecorder.java @@ -0,0 +1,31 @@ +package com.dougnoel.sentinel.filemanagers; + +import java.awt.*; +import org.monte.media.Format; +import org.monte.media.math.Rational; +import org.monte.screenrecorder.ScreenRecorder; +import static org.monte.media.AudioFormatKeys.*; +import static org.monte.media.VideoFormatKeys.*; + +public class SentinelScreenRecorder { + private static ScreenRecorder screenRecorder; + + public static void startRecording() throws Exception { + + GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() + .getDefaultConfiguration(); + screenRecorder = new ScreenRecorder(gc, new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI), + new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, + CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, 24, FrameRateKey, + Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60), + new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)), + null); + screenRecorder.start(); + + } + + public static void stopRecording() throws Exception { + screenRecorder.stop(); + } + +} diff --git a/src/test/java/tests/SentinelTests.java b/src/test/java/tests/SentinelTests.java index f1189a49..daaef1a6 100644 --- a/src/test/java/tests/SentinelTests.java +++ b/src/test/java/tests/SentinelTests.java @@ -6,13 +6,12 @@ import org.junit.BeforeClass; import org.junit.runner.RunWith; import com.dougnoel.sentinel.configurations.Configuration; +import com.dougnoel.sentinel.filemanagers.SentinelScreenRecorder; import com.dougnoel.sentinel.pages.PageManager; import com.dougnoel.sentinel.webdrivers.WebDriverFactory; -import com.dougnoel.sentinel.utilities.*; import io.cucumber.junit.CucumberOptions; import io.cucumber.junit.Cucumber; -import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) @CucumberOptions(monochrome = true @@ -27,10 +26,11 @@ public class SentinelTests { private static final Logger log = LogManager.getLogger(SentinelTests.class); // Create a logger. @BeforeClass - public static void setUpBeforeClass() { + public static void setUpBeforeClass() throws Exception { WebDriverFactory.instantiateWebDriver(); - if(Configuration.toString("addVideoToReport")!=null) - SentinelScreenRecorder.startRecording("extent-cucumber"); +// if(Configuration.toString("addVideoToReport")!=null) + + SentinelScreenRecorder.startRecording(); } @AfterClass @@ -43,7 +43,7 @@ public static void tearDownAfterClass() throws Exception { if (System.getProperty("leaveBrowserOpen", "false") == "false") { PageManager.quit(); } - if(Configuration.toString("addVideoToReport")!=null) +// if(Configuration.toString("addVideoToReport")!=null) SentinelScreenRecorder.stopRecording(); } }