Skip to content
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

Fix NPD when using goto on a second page #1301

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions browser/browser_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop
rt := vu.Runtime()
return mapping{
"context": func() (*common.BrowserContext, error) {
"context": func() (mapping, error) {
b, err := vu.browser()
if err != nil {
return nil, err
}
return b.Context(), nil
return mapBrowserContext(vu, b.Context()), nil
},
"closeContext": func() error {
b, err := vu.browser()
Expand Down
35 changes: 35 additions & 0 deletions tests/browser_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

Expand Down Expand Up @@ -677,6 +679,39 @@ func TestK6Object(t *testing.T) {
}
}

// This test ensures that when opening a new tab, this it is possible to navigate
// to the url. If the mapping layer is not setup correctly we can end up with a
// NPD.
func TestNewTab(t *testing.T) {
t.Parallel()

// Start a server that will return static html files.
mux := http.NewServeMux()
s := httptest.NewServer(mux)
t.Cleanup(s.Close)

const (
slash = string(os.PathSeparator)
path = slash + testBrowserStaticDir + slash
)
fs := http.FileServer(http.Dir(testBrowserStaticDir))
mux.Handle(path, http.StripPrefix(path, fs))

// Start the iteration
_, rt, _, cleanUp := startIteration(t, env.ConstLookup(env.K6TestRunID, "12345"))
defer cleanUp()

// Run the test script
_, err := rt.RunString(fmt.Sprintf(`
const p = browser.newPage()
p.goto("%s/%s/ping.html")

const p2 = browser.context().newPage()
p2.goto("%s/%s/ping.html")
`, s.URL, testBrowserStaticDir, s.URL, testBrowserStaticDir))
require.NoError(t, err)
}

func TestBrowserContextTimeout(t *testing.T) {
t.Parallel()

Expand Down
Loading