1

I have test class defined as this-

public class Sample extends BaseTest {
private LoginPage loginPage;

@Override
public void initialize() {
    loginPage = createInstance(LoginPage.class)
    browserContext = getBrowserContext();
}
@Test(testName = "sampleTestName", retryAnalyzer = RerunFailedTestCases.class)
public void sampleTestName() {
    loginPage.performLogin();
    loginPage.validateLogInSuccessful();
}

In BaseTest I am initializing BrowserContext and enabling video recording for the tests-

public abstract class BaseTest {
protected BrowserContext browserContext = browser.newContext(new Browser.NewContextOptions()
        .setIgnoreHTTPSErrors(true)
        .setPermissions(Arrays.asList("geolocation"))
        .setRecordVideoDir(Paths.get(VIDEOS_DIR)));
}

My requirement is-

  1. Record video of test with testMethod name
  2. only keep video of the failed tests
Rajeev Dixit
  • 1,533
  • 2
  • 16
  • 25

2 Answers2

0

Here is the Playwright for Java doc on the Video class, which shows how to get the video associated with the page, deleting a video (or deciding it should be), and saving as or telling it what file name to use.

So basically at some point in your test or a before/after hook, even potentially in your base class, you can tell the video to save as the test name (couple resources below if unsure how to obtain that), and to delete when successful/doesn’t fail (couple resources below on determining test result).

Hope that helps!

Some Resources

I’m not as familiar with Java and its runners, but you may already know how to do some of these. If not, here’s a few resources I found:

Getting test result

Finding test name

David R
  • 493
  • 2
  • 8
0

I guess there is no way to set a customer file name. Video file names are all like '2b47a96bf34817179232490' but you can set the directory of the file like

Path videoDirectory = Paths.get("my-custom-path");
browser.newContext(new Browser.NewContextOptions().setRecordVideoDir(videoDirectory));
canbax
  • 3,432
  • 1
  • 27
  • 44