Skip to content

Commit

Permalink
Fix NPD when using goto on a second page
Browse files Browse the repository at this point in the history
This fixes an issue when working with a second tab (i.e. opening a new
page in the same existing browserContext), and navigating to a url. In
fact this issue would arise as soon as any API is used from the new
page instance. This was occurring due to the unmapped browserContext
when getting it from the browser.
  • Loading branch information
ankur22 committed May 3, 2024
1 parent f99418b commit 4de7b9c
Showing 1 changed file with 35 additions and 0 deletions.
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

0 comments on commit 4de7b9c

Please sign in to comment.