-
-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent Video being autosaved with generated name when enabled #526
Comments
Okay once again, shortly after issuing an issue I was able to help myself ... but still I would like to understand the purpose behind that autogenerated name and saving on default Here is my workaround: After running a playwright test I close the // Run runs a sequence of playwright steps for a single test
func (t *Test) Run(opts []playwright.Option) error {
t.Lock()
defer t.Unlock()
slog.Info("starting test suite", slog.String("test", t.TestName), slog.Int("steps", len(t.Steps)))
// start a playwright browser instance
pw, err := playwright.NewPW(opts...)
if err != nil {
return fmt.Errorf("cannot launch playwright: %w", err)
}
page := *pw.Page
// properly close browser after a test run
defer func() {
if err := page.Close(); err != nil {
slog.Error("error closing page", slog.String("test", t.TestName), slog.Any("error", err))
}
slog.Info("closed page", slog.String("test", t.TestName))
// first save the video under the correct name
if err := page.Video().SaveAs(fmt.Sprintf("%s_%s.webm", t.TestName, time.Now().Format("20060102150405"))); err != nil {
slog.Error("error saving video recording", slog.String("test", t.TestName), slog.Any("error", err))
}
// then delete the generated recording
if err := page.Video().Delete(); err != nil {
slog.Error("error deleting default video recoding", slog.String("test", t.TestName), slog.Any("error", err))
}
if err := pw.Close(); err != nil {
slog.Error("error closing browser", slog.String("test", t.TestName), slog.Any("error", err))
}
slog.Info("closed browser", slog.String("test", t.TestName))
}()
// run a test suite, increase error counter if fails, otherwise increment success counter
for _, step := range t.Steps {
slog.Debug("executing step", slog.String("name", step.Name))
startTime := time.Now()
err := pw.RunStep(step.Action, step.Locator)
endTime := time.Now()
errStr := ""
if err != nil {
errStr = err.Error()
slog.Error("error executing step", slog.String("name", step.Name), slog.Any("error", err.Error()))
}
t.StepHistogram.With(prometheus.Labels{
"test": t.TestName,
"step": step.Name,
"error": errStr,
"success": strconv.FormatBool(err == nil),
}).Observe(endTime.Sub(startTime).Seconds())
if err != nil {
return &StepError{
StepName: step.Name,
ErrorMsg: err.Error(),
}
}
slog.Debug("step successfully finished", slog.String("name", step.Name))
}
slog.Info("finished test suite", slog.String("test", t.TestName))
return nil
} |
So I've enabled the
RecordVideo
option and I can see that indeed a Video gets saved (e.g:4b8a57e3ebc91b5e9e9f8e8575bb759a.webm
):But I actually want to avoid that, meaning I want to be able to decide for myself the path and name of the video that is being recorded using
page.Video().SaveAs()
method.So can I overwrite the default behaviour and prevent that the video is being autosaved with a generated name or do I have to manually delete that video (how would I obtain the video name in the first place then?)
Is this the expected behaviour?
The text was updated successfully, but these errors were encountered: