diff --git a/tests/locator_test.go b/tests/locator_test.go index b565ba9c7..3d5cca199 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -1,9 +1,6 @@ package tests import ( - "bytes" - "fmt" - "net/http" "testing" "time" @@ -12,10 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/xk6-browser/common" - - "go.k6.io/k6/cmd" - k6tests "go.k6.io/k6/cmd/tests" - k6httpmultibin "go.k6.io/k6/lib/testutils/httpmultibin" ) // Strict mode: @@ -676,85 +669,56 @@ func TestLocatorShadowDOM(t *testing.T) { func TestSelectOption(t *testing.T) { t.Parallel() - tb := k6httpmultibin.NewHTTPMultiBin(t) - ts := k6tests.NewGlobalTestState(t) - tb.Mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, _ *http.Request) { - _, _ = fmt.Fprint(w, "") - }) - tb.Mux.HandleFunc("/selectOption", func(w http.ResponseWriter, _ *http.Request) { - _, err := fmt.Fprint(w, ` - - - - - - `) - assert.NoError(t, err) - }) - - ts.CmdArgs = []string{ - "k6", "run", "-", - } - ts.Stdin = bytes.NewBufferString(tb.Replacer.Replace(` - import { browser } from 'k6/browser'; - - export const options = { - scenarios: { - browser: { - executor: 'shared-iterations', - options: { - browser: { - type: 'chromium', - }, - }, - }, - }, - }; - - export default async function () { - const page = await browser.newPage(); - await page.goto('HTTPBIN_IP_URL/selectOption'); - const options = page.locator('#numbers-options'); - await options.selectOption({label:'Five'}); - let selectedValue = await options.inputValue(); - if (selectedValue !== 'five') { - throw new Error('Expected "five" but got ' + selectedValue); - } - await options.selectOption({index:5}); - selectedValue = await options.inputValue(); - if (selectedValue !== 'five') { - throw new Error('Expected "five" but got ' + selectedValue); - } - await options.selectOption({value:'four'}); - selectedValue = await options.inputValue(); - if (selectedValue !== 'four') { - throw new Error('Expected "four" but got ' + selectedValue); - } - await options.selectOption([{label:'One'}]); - selectedValue = await options.inputValue(); - if (selectedValue !== 'one') { - throw new Error('Expected "one" but got ' + selectedValue); - } - await options.selectOption(['two']); // Value - selectedValue = await options.inputValue(); - if (selectedValue !== 'two') { - throw new Error('Expected "two" but got ' + selectedValue); - } - await options.selectOption('five'); // Value - selectedValue = await options.inputValue(); - if (selectedValue !== 'five') { - throw new Error('Expected "five" but got ' + selectedValue); - } + tb := newTestBrowser(t, + withFileServer(), + ) + defer tb.Browser.Close() + + vu, _, _, cleanUp := startIteration(t) + defer cleanUp() + + got := vu.RunPromise(t, ` + const page = await browser.newPage(); + + await page.goto('%s'); + + const options = page.locator('#numbers-options'); + + await options.selectOption({label:'Five'}); + let selectedValue = await options.inputValue(); + if (selectedValue !== 'five') { + throw new Error('Expected "five" but got ' + selectedValue); + } + + await options.selectOption({index:5}); + selectedValue = await options.inputValue(); + if (selectedValue !== 'five') { + throw new Error('Expected "five" but got ' + selectedValue); + } + + await options.selectOption({value:'four'}); + selectedValue = await options.inputValue(); + if (selectedValue !== 'four') { + throw new Error('Expected "four" but got ' + selectedValue); } - `)) - cmd.ExecuteWithGlobalState(ts.GlobalState) - assert.Empty(t, ts.Stderr.String()) + await options.selectOption([{label:'One'}]); + selectedValue = await options.inputValue(); + if (selectedValue !== 'one') { + throw new Error('Expected "one" but got ' + selectedValue); + } + + await options.selectOption(['two']); // Value + selectedValue = await options.inputValue(); + if (selectedValue !== 'two') { + throw new Error('Expected "two" but got ' + selectedValue); + } + + await options.selectOption('five'); // Value + selectedValue = await options.inputValue(); + if (selectedValue !== 'five') { + throw new Error('Expected "five" but got ' + selectedValue); + } + `, tb.staticURL("select_options.html")) + assert.Equal(t, sobek.Undefined(), got.Result()) } diff --git a/tests/static/select_options.html b/tests/static/select_options.html new file mode 100644 index 000000000..ea854941d --- /dev/null +++ b/tests/static/select_options.html @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file