-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* record video for all tests, or only for annotated with @video * save video for all tests, or only for failed. * etc.
- Loading branch information
Showing
27 changed files
with
450 additions
and
176 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...ecorder-junit/src/test/java/integration/videorecorder/junit5/MarkFailedTestsAsPassed.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,12 @@ | ||
package integration.videorecorder.junit5; | ||
|
||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.selenide.videorecorder.junit5.VideoRecorderExtension; | ||
|
||
public class MarkFailedTestsAsPassed extends VideoRecorderExtension { | ||
@Override | ||
public void afterTestExecution(ExtensionContext context) { | ||
boolean testFailed = "secondTest".equals(context.getRequiredTestMethod().getName()); | ||
afterTestExecution(context, testFailed); | ||
} | ||
} |
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 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 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
6 changes: 6 additions & 0 deletions
6
modules/video-recorder-junit/src/test/resources/selenide.properties
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,6 @@ | ||
selenide.video.enabled=true | ||
selenide.video.fps=6 | ||
selenide.video.crf=50 | ||
#selenide.video.mode=ALL | ||
selenide.video.save.mode=FAILED_ONLY | ||
#selenide.video.save.mode=ALL |
25 changes: 25 additions & 0 deletions
25
...corder-testng/src/test/java/integration/videorecorder/testng/MarkFailedTestsAsPassed.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,25 @@ | ||
package integration.videorecorder.testng; | ||
|
||
import com.codeborne.selenide.ex.ElementNotFound; | ||
import org.selenide.videorecorder.testng.VideoRecorderListener; | ||
import org.testng.ITestResult; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import static java.util.regex.Pattern.DOTALL; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.testng.ITestResult.SUCCESS; | ||
|
||
public class MarkFailedTestsAsPassed extends VideoRecorderListener { | ||
@Override | ||
public void onTestFailure(ITestResult result) { | ||
super.onTestFailure(result); | ||
if ("secondTest".equals(result.getName())) { | ||
assertThat(result.getThrowable()).isInstanceOf(ElementNotFound.class); | ||
assertThat(result.getThrowable().getMessage()).matches(Pattern.compile(".+Video: file:/.+\\.webm.*", DOTALL)); | ||
} | ||
|
||
result.setStatus(SUCCESS); | ||
result.setThrowable(null); | ||
} | ||
} |
34 changes: 20 additions & 14 deletions
34
...order-testng/src/test/java/integration/videorecorder/testng/VideoRecorderTestNg1Test.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 |
---|---|---|
@@ -1,37 +1,43 @@ | ||
package integration.videorecorder.testng; | ||
|
||
import com.codeborne.selenide.TypeOptions; | ||
import org.selenide.videorecorder.testng.VideoRecorderListener; | ||
import org.selenide.videorecorder.core.Video; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
import java.nio.file.Path; | ||
|
||
import static com.codeborne.selenide.Configuration.config; | ||
import static com.codeborne.selenide.Selenide.$; | ||
import static com.codeborne.selenide.Selenide.closeWebDriver; | ||
import static com.codeborne.selenide.Selenide.open; | ||
import static com.codeborne.selenide.TypeOptions.text; | ||
import static java.time.Duration.ofMillis; | ||
import static java.util.Objects.requireNonNull; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.selenide.videorecorder.testng.VideoRecorderListener.getRecordedVideo; | ||
|
||
@Listeners(VideoRecorderListener.class) | ||
@Listeners(MarkFailedTestsAsPassed.class) | ||
public class VideoRecorderTestNg1Test { | ||
|
||
@AfterMethod | ||
public void afterMethod() { | ||
Path path = VideoRecorderListener.getRecordedVideo().orElseThrow(); | ||
assertThat(path.toFile().length()).isGreaterThan(0); | ||
assertThat(path.toFile()).hasExtension("webm"); | ||
} | ||
|
||
@Test | ||
@Video | ||
public void firstTest() { | ||
open(config().browserPosition("50x50")); | ||
open(config().browserPosition("50x50").browserSize("800x500")); | ||
for (int i = 0; i < 3; i++) { | ||
open(requireNonNull(getClass().getClassLoader().getResource("search.html"))); | ||
$("[name=q]").type(TypeOptions.text("#1 TestNG TestNG TestNG TestNG TestNG TestNG TestNG #111") | ||
$("[name=q]").type(text("#1 TestNG TestNG TestNG TestNG TestNG TestNG TestNG #111") | ||
.withDelay(ofMillis(5))); | ||
} | ||
} | ||
|
||
@AfterMethod | ||
final void checkVideo() { | ||
assertThat(getRecordedVideo()) | ||
.as("Test is annotated with @Video, but did not fail -> no video") | ||
.isEmpty(); | ||
} | ||
|
||
@AfterMethod | ||
final void closeBrowser() { | ||
closeWebDriver(); | ||
} | ||
} |
35 changes: 25 additions & 10 deletions
35
...order-testng/src/test/java/integration/videorecorder/testng/VideoRecorderTestNg2Test.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 |
---|---|---|
@@ -1,37 +1,52 @@ | ||
package integration.videorecorder.testng; | ||
|
||
import com.codeborne.selenide.TypeOptions; | ||
import org.selenide.videorecorder.core.Video; | ||
import org.selenide.videorecorder.testng.VideoRecorderListener; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testng.ITestResult; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
import java.nio.file.Path; | ||
|
||
import static com.codeborne.selenide.Condition.visible; | ||
import static com.codeborne.selenide.Configuration.config; | ||
import static com.codeborne.selenide.Selenide.$; | ||
import static com.codeborne.selenide.Selenide.closeWebDriver; | ||
import static com.codeborne.selenide.Selenide.open; | ||
import static com.codeborne.selenide.TypeOptions.text; | ||
import static java.time.Duration.ofMillis; | ||
import static java.util.Objects.requireNonNull; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Listeners(VideoRecorderListener.class) | ||
@Listeners(MarkFailedTestsAsPassed.class) | ||
public class VideoRecorderTestNg2Test { | ||
|
||
@AfterMethod | ||
public void afterMethod() { | ||
Path path = VideoRecorderListener.getRecordedVideo().orElseThrow(); | ||
assertThat(path.toFile().length()).isGreaterThan(0); | ||
assertThat(path.toFile()).hasExtension("webm"); | ||
} | ||
private static final Logger log = LoggerFactory.getLogger(VideoRecorderTestNg2Test.class); | ||
|
||
@Test | ||
@Video | ||
public void secondTest() { | ||
open(config().browserPosition("300x500")); | ||
open(config().browserPosition("200x300").browserSize("800x500")); | ||
for (int i = 0; i < 3; i++) { | ||
open(requireNonNull(getClass().getClassLoader().getResource("search.html"))); | ||
$("[name=q]").type(TypeOptions.text("#2 TestNG TestNG TestNG TestNG TestNG TestNG TestNG #222") | ||
$("[name=q]").type(text("#2 TestNG TestNG TestNG TestNG TestNG TestNG TestNG #222") | ||
.withDelay(ofMillis(5))); | ||
} | ||
$("#nope").shouldBe(visible.because("We want this test to fail and save the video"), ofMillis(1)); | ||
} | ||
|
||
@AfterMethod | ||
final void assertVideoHasBeenSaved(ITestResult result) { | ||
Path path = VideoRecorderListener.getRecordedVideo().orElseThrow(); | ||
assertThat(path.toFile().length()).isGreaterThan(0); | ||
assertThat(path.toFile()).hasExtension("webm"); | ||
} | ||
|
||
@AfterMethod | ||
final void closeBrowser() { | ||
closeWebDriver(); | ||
} | ||
} |
34 changes: 20 additions & 14 deletions
34
...order-testng/src/test/java/integration/videorecorder/testng/VideoRecorderTestNg3Test.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 |
---|---|---|
@@ -1,37 +1,43 @@ | ||
package integration.videorecorder.testng; | ||
|
||
import com.codeborne.selenide.TypeOptions; | ||
import org.selenide.videorecorder.testng.VideoRecorderListener; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
import java.nio.file.Path; | ||
|
||
import static com.codeborne.selenide.Condition.visible; | ||
import static com.codeborne.selenide.Configuration.config; | ||
import static com.codeborne.selenide.Selenide.$; | ||
import static com.codeborne.selenide.Selenide.closeWebDriver; | ||
import static com.codeborne.selenide.Selenide.open; | ||
import static com.codeborne.selenide.TypeOptions.text; | ||
import static java.time.Duration.ofMillis; | ||
import static java.util.Objects.requireNonNull; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.selenide.videorecorder.testng.VideoRecorderListener.getRecordedVideo; | ||
|
||
@Listeners(VideoRecorderListener.class) | ||
@Listeners(MarkFailedTestsAsPassed.class) | ||
public class VideoRecorderTestNg3Test { | ||
|
||
@AfterMethod | ||
public void afterMethod() { | ||
Path path = VideoRecorderListener.getRecordedVideo().orElseThrow(); | ||
assertThat(path.toFile().length()).isGreaterThan(0); | ||
assertThat(path.toFile()).hasExtension("webm"); | ||
} | ||
|
||
@Test | ||
public void thirdTest() { | ||
open(config().browserPosition("50x1000")); | ||
open(config().browserPosition("50x600").browserSize("800x500")); | ||
for (int i = 0; i < 3; i++) { | ||
open(requireNonNull(getClass().getClassLoader().getResource("search.html"))); | ||
$("[name=q]").type(TypeOptions.text("#3 TestNG TestNG TestNG TestNG TestNG TestNG TestNG #333") | ||
$("[name=q]").type(text("#3 TestNG TestNG TestNG TestNG TestNG TestNG TestNG #333") | ||
.withDelay(ofMillis(5))); | ||
} | ||
$("#nope").shouldBe(visible.because("We want this test to fail, but video will not be saved."), ofMillis(1)); | ||
} | ||
|
||
@AfterMethod | ||
final void assertNoVideoHasBeenSaved() { | ||
assertThat(getRecordedVideo()) | ||
.as("Test failed, but it's not annotated with @Video -> no video") | ||
.isEmpty(); | ||
} | ||
|
||
@AfterMethod | ||
final void closeBrowser() { | ||
closeWebDriver(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
modules/video-recorder-testng/src/test/resources/selenide.properties
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,5 @@ | ||
#selenide.video.enabled=true | ||
selenide.video.fps=6 | ||
#selenide.video.crf=50 | ||
#selenide.video.mode=ALL | ||
#selenide.video.save.mode=ALL |
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 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
Oops, something went wrong.