Skip to content

Commit

Permalink
Move initBrowserContext to browser map
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed May 3, 2024
1 parent c2f1fbf commit e94b234
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 16 additions & 0 deletions browser/browser_mapping.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package browser

import (
"fmt"

"github.com/dop251/goja"

"github.com/grafana/xk6-browser/common"
Expand Down Expand Up @@ -81,3 +83,17 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop
},
}
}

func initBrowserContext(bctx *common.BrowserContext, testRunID string) error {
// Setting a k6 object which will contain k6 specific metadata
// on the current test run. This allows external applications
// (such as Grafana Faro) to identify that the session is a k6
// automated one and not one driven by a real person.
if err := bctx.AddInitScript(
fmt.Sprintf(`window.k6 = { testRunId: %q }`, testRunID),
); err != nil {
return fmt.Errorf("adding k6 object to new browser context: %w", err)
}

return nil
}
14 changes: 0 additions & 14 deletions browser/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,3 @@ func parseFrameClickOptions(
}
return copts, nil
}

func initBrowserContext(bctx *common.BrowserContext, testRunID string) error {
// Setting a k6 object which will contain k6 specific metadata
// on the current test run. This allows external applications
// (such as Grafana Faro) to identify that the session is a k6
// automated one and not one driven by a real person.
if err := bctx.AddInitScript(
fmt.Sprintf(`window.k6 = { testRunId: %q }`, testRunID),
); err != nil {
return fmt.Errorf("adding k6 object to new browser context: %w", err)
}

return nil
}

0 comments on commit e94b234

Please sign in to comment.