Skip to content

Commit

Permalink
Add video record on new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Dec 9, 2024
1 parent b60e79a commit 91f1d98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions browser/browser_context_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package browser
import (
"errors"
"fmt"
"path/filepath"
"reflect"
"time"

Expand Down Expand Up @@ -134,6 +135,11 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
"waitForEvent": func(event string, optsOrPredicate sobek.Value) (*sobek.Promise, error) {
pauseOnBreakpoint(vu.breakpointRegistry, vu.Runtime())

pos := getCurrentLineNumber(vu.Runtime())
fileNameWithExt := filepath.Base(pos.Filename)
fileExt := filepath.Ext(pos.Filename)
fileNameWithoutExt := fileNameWithExt[:len(fileNameWithExt)-len(fileExt)]

popts, err := parseWaitForEventOptions(vu.Runtime(), optsOrPredicate, bc.Timeout())
if err != nil {
return nil, fmt.Errorf("parsing wait for event options: %w", err)
Expand Down Expand Up @@ -180,6 +186,11 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
panicIfFatalError(ctx, fmt.Errorf("response object is not a page: %w", k6error.ErrFatal))
}

tq := vu.taskQueueRegistry.get(vu.Context(), p.TargetID())
p.SetScreenshotPersister(vu.filePersister)
p.SetScriptName(fileNameWithoutExt)
p.SetTaskQueue(tq)

return mapPage(vu, p), nil
}), nil
},
Expand Down
2 changes: 1 addition & 1 deletion common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (p *Page) SetScriptName(scriptName string) {

if p.browserCtx.browser.browserOpts.CaptureVideo {
o := NewVideoCaptureOptions()
o.Path = fmt.Sprintf("%s_screen_recording.webm", p.scriptName)
o.Path = fmt.Sprintf("%s_page_%d_screen_recording.webm", p.scriptName, len(p.browserCtx.Pages()))
p.CaptureVideo(o)
go func() {
<-p.ctx.Done()
Expand Down

0 comments on commit 91f1d98

Please sign in to comment.