From dcf7d6f39dfaff2c6bf30caff646c7553078a645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:17:56 +0300 Subject: [PATCH 01/48] Async page.bringToFront --- browser/page_mapping.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 9c2ff633c..b457d495f 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -17,8 +17,12 @@ import ( func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop rt := vu.Runtime() maps := mapping{ - "bringToFront": p.BringToFront, - "check": p.Check, + "bringToFront": func() *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.BringToFront() //nolint:wrapcheck + }) + }, + "check": p.Check, "click": func(selector string, opts goja.Value) (*goja.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, p.Timeout()) if err != nil { From e80f9988eb0db688f113a230adb3266556ae47f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:20:07 +0300 Subject: [PATCH 02/48] Async page.check --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index b457d495f..ae2a4c082 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -22,7 +22,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.BringToFront() //nolint:wrapcheck }) }, - "check": p.Check, + "check": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Check(selector, opts) //nolint:wrapcheck + }) + }, "click": func(selector string, opts goja.Value) (*goja.Promise, error) { popts, err := parseFrameClickOptions(vu.Context(), opts, p.Timeout()) if err != nil { From 53b7e9901cd87ccff0ae88656c25d5a509249cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:25:27 +0300 Subject: [PATCH 03/48] Async page.close --- browser/page_mapping.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index ae2a4c082..9ee8a5037 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -38,10 +38,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, err //nolint:wrapcheck }), nil }, - "close": func(opts goja.Value) error { - vu.taskQueueRegistry.close(p.TargetID()) - - return p.Close(opts) //nolint:wrapcheck + "close": func(opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + vu.taskQueueRegistry.close(p.TargetID()) + return nil, p.Close(opts) //nolint:wrapcheck + }) }, "content": p.Content, "context": func() mapping { From fe04161a634c669f57611d0654c56ffc61392d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:26:47 +0300 Subject: [PATCH 04/48] Async page.content --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 9ee8a5037..344079ac1 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -44,7 +44,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Close(opts) //nolint:wrapcheck }) }, - "content": p.Content, + "content": func() *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.Content() //nolint:wrapcheck + }) + }, "context": func() mapping { return mapBrowserContext(vu, p.Context()) }, From 90a70efe66e5ba091a09bbaa0ec4f2d7e3549058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:27:36 +0300 Subject: [PATCH 05/48] Async page.dblclick --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 344079ac1..e43b8f49d 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -52,7 +52,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop "context": func() mapping { return mapBrowserContext(vu, p.Context()) }, - "dblclick": p.Dblclick, + "dblclick": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Dblclick(selector, opts) //nolint:wrapcheck + }) + }, "dispatchEvent": func(selector, typ string, eventInit, opts goja.Value) error { popts := common.NewFrameDispatchEventOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { From f50a512712939b74c2c6656d4dbc63fdd3e5cc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:29:31 +0300 Subject: [PATCH 06/48] Async page.dispatchEvent --- browser/page_mapping.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index e43b8f49d..4af724745 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -57,12 +57,14 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Dblclick(selector, opts) //nolint:wrapcheck }) }, - "dispatchEvent": func(selector, typ string, eventInit, opts goja.Value) error { + "dispatchEvent": func(selector, typ string, eventInit, opts goja.Value) (*goja.Promise, error) { popts := common.NewFrameDispatchEventOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { - return fmt.Errorf("parsing page dispatch event options: %w", err) + return nil, fmt.Errorf("parsing page dispatch event options: %w", err) } - return p.DispatchEvent(selector, typ, exportArg(eventInit), popts) //nolint:wrapcheck + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.DispatchEvent(selector, typ, exportArg(eventInit), popts) //nolint:wrapcheck + }), nil }, "emulateMedia": p.EmulateMedia, "emulateVisionDeficiency": p.EmulateVisionDeficiency, From 38936d7726bf93fa61e6b387d45d3be8e42d791d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:28:10 +0300 Subject: [PATCH 07/48] Async page.emulateMedia --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 4af724745..4ca67dbb1 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -66,7 +66,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.DispatchEvent(selector, typ, exportArg(eventInit), popts) //nolint:wrapcheck }), nil }, - "emulateMedia": p.EmulateMedia, + "emulateMedia": func(opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.EmulateMedia(opts) //nolint:wrapcheck + }) + }, "emulateVisionDeficiency": p.EmulateVisionDeficiency, "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) (any, error) { return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck From ad52c713b78498d30bf123e98ce74c9b4f6261ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:28:35 +0300 Subject: [PATCH 08/48] Async page.emulateVisionDeficiency --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 4ca67dbb1..31ede3e30 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -71,7 +71,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.EmulateMedia(opts) //nolint:wrapcheck }) }, - "emulateVisionDeficiency": p.EmulateVisionDeficiency, + "emulateVisionDeficiency": func(typ string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.EmulateVisionDeficiency(typ) //nolint:wrapcheck + }) + }, "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) (any, error) { return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck }, From d97b286618a93091871c42b469d1970c6477b757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 13:35:12 +0300 Subject: [PATCH 09/48] Async page.evaluate --- browser/page_mapping.go | 6 ++++-- tests/browser_context_test.go | 4 ++-- tests/page_test.go | 26 +++++++++++--------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 31ede3e30..7f533c904 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -76,8 +76,10 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.EmulateVisionDeficiency(typ) //nolint:wrapcheck }) }, - "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) (any, error) { - return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck + "evaluate": func(pageFunction goja.Value, gargs ...goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck + }) }, "evaluateHandle": func(pageFunc goja.Value, gargs ...goja.Value) (mapping, error) { jsh, err := p.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) diff --git a/tests/browser_context_test.go b/tests/browser_context_test.go index 696bbcd5c..13cd437f3 100644 --- a/tests/browser_context_test.go +++ b/tests/browser_context_test.go @@ -659,7 +659,7 @@ func TestK6Object(t *testing.T) { got := vu.RunPromise(t, ` const p = await browser.newPage(); await p.goto("about:blank"); - const o = p.evaluate(() => window.k6); + const o = await p.evaluate(() => window.k6); return JSON.stringify(o); `) assert.Equal(t, tt.want, got.Result().String()) @@ -670,7 +670,7 @@ func TestK6Object(t *testing.T) { const c = await browser.newContext(); const p2 = await c.newPage(); await p2.goto("about:blank"); - const o2 = p2.evaluate(() => window.k6); + const o2 = await p2.evaluate(() => window.k6); return JSON.stringify(o2); `) assert.Equal(t, tt.want, got.Result().String()) diff --git a/tests/page_test.go b/tests/page_test.go index 557768059..b83d1115b 100644 --- a/tests/page_test.go +++ b/tests/page_test.go @@ -229,13 +229,13 @@ func TestPageEvaluateMapping(t *testing.T) { vu.SetVar(t, "p", &goja.Object{}) got := vu.RunPromise(t, ` p = await browser.newPage() - return p.evaluate(%s) + return await p.evaluate(%s) `, tt.script) assert.Equal(t, vu.ToGojaValue(tt.want), got.Result()) // Test script as string input got = vu.RunPromise(t, - `return p.evaluate("%s")`, + `return await p.evaluate("%s")`, tt.script, ) assert.Equal(t, vu.ToGojaValue(tt.want), got.Result()) @@ -722,7 +722,7 @@ func TestPageWaitForFunction(t *testing.T) { t.Run("ok_func_raf_default_arg", func(t *testing.T) { t.Parallel() - vu, rt, log, cleanUp := startIteration(t) + vu, _, log, cleanUp := startIteration(t) defer cleanUp() _, err := vu.RunOnEventLoop(t, `fn = arg => { @@ -735,12 +735,9 @@ func TestPageWaitForFunction(t *testing.T) { require.NoError(t, err) assert.Contains(t, *log, "ok: null") - argEval, err := vu.RunOnEventLoop(t, `page.evaluate(() => window._arg);`) - require.NoError(t, err) - - var gotArg string - _ = rt.ExportTo(argEval, &gotArg) - assert.Equal(t, "raf_arg", gotArg) + p := vu.RunPromise(t, `return await page.evaluate(() => window._arg);`) + require.Equal(t, p.State(), goja.PromiseStateFulfilled) + assert.Equal(t, "raf_arg", p.Result().String()) }) t.Run("ok_func_raf_default_args", func(t *testing.T) { @@ -763,11 +760,10 @@ func TestPageWaitForFunction(t *testing.T) { require.NoError(t, err) assert.Contains(t, *log, "ok: null") - argEval, err := vu.RunOnEventLoop(t, `page.evaluate(() => window._args);`) - require.NoError(t, err) - + p := vu.RunPromise(t, `return await page.evaluate(() => window._args);`) + require.Equal(t, p.State(), goja.PromiseStateFulfilled) var gotArgs []int - _ = rt.ExportTo(argEval, &gotArgs) + _ = rt.ExportTo(p.Result(), &gotArgs) assert.Equal(t, args, gotArgs) }) @@ -803,7 +799,7 @@ func TestPageWaitForFunction(t *testing.T) { vu.SetVar(t, "page", &goja.Object{}) _, err := vu.RunAsync(t, ` page = await browser.newPage(); - page.evaluate(() => { + await page.evaluate(() => { setTimeout(() => { const el = document.createElement('h1'); el.innerHTML = 'Hello'; @@ -836,7 +832,7 @@ func TestPageWaitForFunction(t *testing.T) { fn = () => document.querySelector('h1') !== null page = await browser.newPage(); - page.evaluate(() => { + await page.evaluate(() => { console.log('calling setTimeout...'); setTimeout(() => { console.log('creating element...'); From fe90e269d7d50bdc2dfbbd7756e7a005d6dc6259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:09:27 +0300 Subject: [PATCH 10/48] Async page.evaluateHandle --- browser/page_mapping.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 7f533c904..9a85d2fd5 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -81,12 +81,14 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.Evaluate(pageFunction.String(), exportArgs(gargs)...) //nolint:wrapcheck }) }, - "evaluateHandle": func(pageFunc goja.Value, gargs ...goja.Value) (mapping, error) { - jsh, err := p.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) - if err != nil { - return nil, err //nolint:wrapcheck - } - return mapJSHandle(vu, jsh), nil + "evaluateHandle": func(pageFunc goja.Value, gargs ...goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + jsh, err := p.EvaluateHandle(pageFunc.String(), exportArgs(gargs)...) + if err != nil { + return nil, err //nolint:wrapcheck + } + return mapJSHandle(vu, jsh), nil + }) }, "fill": p.Fill, "focus": p.Focus, From 3c93ad5c988b34719602216c9d73fd4c0704a456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:12:29 +0300 Subject: [PATCH 11/48] Async page.fill --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 9a85d2fd5..f8a831710 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -90,7 +90,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapJSHandle(vu, jsh), nil }) }, - "fill": p.Fill, + "fill": func(selector string, value string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Fill(selector, value, opts) //nolint:wrapcheck + }) + }, "focus": p.Focus, "frames": func() *goja.Object { var ( From c2cb3b316b376060a6500cd1fc4d344bcb3f6e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:12:51 +0300 Subject: [PATCH 12/48] Async page.focus --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index f8a831710..2ba7aff5e 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -95,7 +95,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Fill(selector, value, opts) //nolint:wrapcheck }) }, - "focus": p.Focus, + "focus": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Focus(selector, opts) //nolint:wrapcheck + }) + }, "frames": func() *goja.Object { var ( mfrs []mapping From 237185eb9a54f5eb7c2749da4429c28fd8dee7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:14:09 +0300 Subject: [PATCH 13/48] Async page.getAttribute --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 2ba7aff5e..773c2de3f 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -110,7 +110,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop } return rt.ToValue(mfrs).ToObject(rt) }, - "getAttribute": p.GetAttribute, + "getAttribute": func(selector string, name string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.GetAttribute(selector, name, opts) //nolint:wrapcheck + }) + }, "goto": func(url string, opts goja.Value) (*goja.Promise, error) { gopts := common.NewFrameGotoOptions( p.Referrer(), From af519d026d9f174be869b316898b5139f45d8c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:14:39 +0300 Subject: [PATCH 14/48] Async page.hover --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 773c2de3f..a700b11f0 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -132,7 +132,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapResponse(vu, resp), nil }), nil }, - "hover": p.Hover, + "hover": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Hover(selector, opts) //nolint:wrapcheck + }) + }, "innerHTML": p.InnerHTML, "innerText": p.InnerText, "inputValue": p.InputValue, From b6f4320057c364218b855415e3ece53733ea50f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:15:11 +0300 Subject: [PATCH 15/48] Async page.innerHTML --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index a700b11f0..e3cfee680 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -137,7 +137,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Hover(selector, opts) //nolint:wrapcheck }) }, - "innerHTML": p.InnerHTML, + "innerHTML": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.InnerHTML(selector, opts) //nolint:wrapcheck + }) + }, "innerText": p.InnerText, "inputValue": p.InputValue, "isChecked": p.IsChecked, From 6838228e39422341b040e2fdf588f5cc4eb8240f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:15:31 +0300 Subject: [PATCH 16/48] Async page.innerText --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index e3cfee680..32322c4a0 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -142,7 +142,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.InnerHTML(selector, opts) //nolint:wrapcheck }) }, - "innerText": p.InnerText, + "innerText": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.InnerText(selector, opts) //nolint:wrapcheck + }) + }, "inputValue": p.InputValue, "isChecked": p.IsChecked, "isClosed": p.IsClosed, From 671a5b8d953df1e83f24a2053b313f4d1acc4330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:15:52 +0300 Subject: [PATCH 17/48] Async page.inputValue --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 32322c4a0..f427f1822 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -147,7 +147,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.InnerText(selector, opts) //nolint:wrapcheck }) }, - "inputValue": p.InputValue, + "inputValue": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.InputValue(selector, opts) //nolint:wrapcheck + }) + }, "isChecked": p.IsChecked, "isClosed": p.IsClosed, "isDisabled": p.IsDisabled, From 1e4e1affa6df993b0aabf3e1ffb75cb745733d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:16:29 +0300 Subject: [PATCH 18/48] Async page.isChecked --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index f427f1822..5b9c642a9 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -152,7 +152,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.InputValue(selector, opts) //nolint:wrapcheck }) }, - "isChecked": p.IsChecked, + "isChecked": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.IsChecked(selector, opts) //nolint:wrapcheck + }) + }, "isClosed": p.IsClosed, "isDisabled": p.IsDisabled, "isEditable": p.IsEditable, From c0a163b94b92e874b6fc5e14a5748ab86f2a550f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:16:51 +0300 Subject: [PATCH 19/48] Async page.isDisabled --- browser/page_mapping.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 5b9c642a9..ca83ef204 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -157,8 +157,12 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.IsChecked(selector, opts) //nolint:wrapcheck }) }, - "isClosed": p.IsClosed, - "isDisabled": p.IsDisabled, + "isClosed": p.IsClosed, + "isDisabled": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.IsDisabled(selector, opts) //nolint:wrapcheck + }) + }, "isEditable": p.IsEditable, "isEnabled": p.IsEnabled, "isHidden": p.IsHidden, From 316ab0a4fb6a1c7be04303a90e9746ac979cc75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:17:08 +0300 Subject: [PATCH 20/48] Async page.isEditable --- browser/page_mapping.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index ca83ef204..d06f69a4b 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -163,11 +163,15 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.IsDisabled(selector, opts) //nolint:wrapcheck }) }, - "isEditable": p.IsEditable, - "isEnabled": p.IsEnabled, - "isHidden": p.IsHidden, - "isVisible": p.IsVisible, - "keyboard": mapKeyboard(vu, p.GetKeyboard()), + "isEditable": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.IsEditable(selector, opts) //nolint:wrapcheck + }) + }, + "isEnabled": p.IsEnabled, + "isHidden": p.IsHidden, + "isVisible": p.IsVisible, + "keyboard": mapKeyboard(vu, p.GetKeyboard()), "locator": func(selector string, opts goja.Value) *goja.Object { ml := mapLocator(vu, p.Locator(selector, opts)) return rt.ToValue(ml).ToObject(rt) From 7b8768f87480fa5a4238a31129ce32323a6ecfd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:17:18 +0300 Subject: [PATCH 21/48] Async page.isEnabled --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index d06f69a4b..f6482cc03 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -168,7 +168,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.IsEditable(selector, opts) //nolint:wrapcheck }) }, - "isEnabled": p.IsEnabled, + "isEnabled": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.IsEnabled(selector, opts) //nolint:wrapcheck + }) + }, "isHidden": p.IsHidden, "isVisible": p.IsVisible, "keyboard": mapKeyboard(vu, p.GetKeyboard()), From 3f513b50ea148db9e9047c93880e03b985a197fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:17:26 +0300 Subject: [PATCH 22/48] Async page.isHidden --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index f6482cc03..17a921959 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -173,7 +173,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.IsEnabled(selector, opts) //nolint:wrapcheck }) }, - "isHidden": p.IsHidden, + "isHidden": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.IsHidden(selector, opts) //nolint:wrapcheck + }) + }, "isVisible": p.IsVisible, "keyboard": mapKeyboard(vu, p.GetKeyboard()), "locator": func(selector string, opts goja.Value) *goja.Object { From 97556a57195cf13f140c5442e9ba42cc0bbe2eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:17:34 +0300 Subject: [PATCH 23/48] Async page.isVisible --- browser/page_mapping.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 17a921959..993d07b39 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -178,8 +178,12 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.IsHidden(selector, opts) //nolint:wrapcheck }) }, - "isVisible": p.IsVisible, - "keyboard": mapKeyboard(vu, p.GetKeyboard()), + "isVisible": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.IsVisible(selector, opts) //nolint:wrapcheck + }) + }, + "keyboard": mapKeyboard(vu, p.GetKeyboard()), "locator": func(selector string, opts goja.Value) *goja.Object { ml := mapLocator(vu, p.Locator(selector, opts)) return rt.ToValue(ml).ToObject(rt) From 20edcf721ed04cb45dccb7afdd49103fa5218fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:21:51 +0300 Subject: [PATCH 24/48] Async page.opener --- browser/page_mapping.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 993d07b39..6cc368083 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -212,8 +212,12 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.On(event, runInTaskQueue) //nolint:wrapcheck }, - "opener": p.Opener, - "press": p.Press, + "opener": func() *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.Opener(), nil + }) + }, + "press": p.Press, "reload": func(opts goja.Value) (*goja.Object, error) { resp, err := p.Reload(opts) if err != nil { From 216f06fa4288c2a8caf068f90eea3bf9537e9c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:22:18 +0300 Subject: [PATCH 25/48] Async page.press --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 6cc368083..11b7b5292 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -217,7 +217,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.Opener(), nil }) }, - "press": p.Press, + "press": func(selector string, key string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Press(selector, key, opts) //nolint:wrapcheck + }) + }, "reload": func(opts goja.Value) (*goja.Object, error) { resp, err := p.Reload(opts) if err != nil { From 83666073bdbe61dea7f54b310420bdd5fa58cf04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:22:55 +0300 Subject: [PATCH 26/48] Async page.reload --- browser/page_mapping.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 11b7b5292..d05255004 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -222,15 +222,17 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Press(selector, key, opts) //nolint:wrapcheck }) }, - "reload": func(opts goja.Value) (*goja.Object, error) { - resp, err := p.Reload(opts) - if err != nil { - return nil, err //nolint:wrapcheck - } + "reload": func(opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + resp, err := p.Reload(opts) + if err != nil { + return nil, err //nolint:wrapcheck + } - r := mapResponse(vu, resp) + r := mapResponse(vu, resp) - return rt.ToValue(r).ToObject(rt), nil + return rt.ToValue(r).ToObject(rt), nil + }) }, "screenshot": func(opts goja.Value) (*goja.ArrayBuffer, error) { popts := common.NewPageScreenshotOptions() From 5bdd8f138544254050db9c88af22087310b2d3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:23:28 +0300 Subject: [PATCH 27/48] Async page.screenshot --- browser/page_mapping.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index d05255004..b229a71de 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -234,20 +234,22 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return rt.ToValue(r).ToObject(rt), nil }) }, - "screenshot": func(opts goja.Value) (*goja.ArrayBuffer, error) { + "screenshot": func(opts goja.Value) (*goja.Promise, error) { popts := common.NewPageScreenshotOptions() if err := popts.Parse(vu.Context(), opts); err != nil { return nil, fmt.Errorf("parsing page screenshot options: %w", err) } - bb, err := p.Screenshot(popts, vu.filePersister) - if err != nil { - return nil, err //nolint:wrapcheck - } + return k6ext.Promise(vu.Context(), func() (any, error) { + bb, err := p.Screenshot(popts, vu.filePersister) + if err != nil { + return nil, err //nolint:wrapcheck + } - ab := rt.NewArrayBuffer(bb) + ab := rt.NewArrayBuffer(bb) - return &ab, nil + return &ab, nil + }), nil }, "selectOption": p.SelectOption, "setContent": p.SetContent, From c3ff184c927207517f670e4dc6d5d64dd6d4d932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:24:12 +0300 Subject: [PATCH 28/48] Async page.selectOption --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index b229a71de..e49e6390f 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -251,7 +251,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return &ab, nil }), nil }, - "selectOption": p.SelectOption, + "selectOption": func(selector string, values goja.Value, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.SelectOption(selector, values, opts) //nolint:wrapcheck + }) + }, "setContent": p.SetContent, "setDefaultNavigationTimeout": p.SetDefaultNavigationTimeout, "setDefaultTimeout": p.SetDefaultTimeout, From c38f6032b8c6defb4e665bf80f89e89008c3bc43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:24:37 +0300 Subject: [PATCH 29/48] Async page.setContent --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index e49e6390f..e83d8df37 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -256,7 +256,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.SelectOption(selector, values, opts) //nolint:wrapcheck }) }, - "setContent": p.SetContent, + "setContent": func(html string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.SetContent(html, opts) //nolint:wrapcheck + }) + }, "setDefaultNavigationTimeout": p.SetDefaultNavigationTimeout, "setDefaultTimeout": p.SetDefaultTimeout, "setExtraHTTPHeaders": p.SetExtraHTTPHeaders, From 34ba3338bbb822ff92299f37c024a8bc93fb0ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:25:01 +0300 Subject: [PATCH 30/48] Async page.setExtraHTTPHeaders --- browser/page_mapping.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index e83d8df37..ee6190cd8 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -263,9 +263,13 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop }, "setDefaultNavigationTimeout": p.SetDefaultNavigationTimeout, "setDefaultTimeout": p.SetDefaultTimeout, - "setExtraHTTPHeaders": p.SetExtraHTTPHeaders, - "setInputFiles": p.SetInputFiles, - "setViewportSize": p.SetViewportSize, + "setExtraHTTPHeaders": func(headers map[string]string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.SetExtraHTTPHeaders(headers) //nolint:wrapcheck + }) + }, + "setInputFiles": p.SetInputFiles, + "setViewportSize": p.SetViewportSize, "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { popts := common.NewFrameTapOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { From 6b4da9aad98cac4615759922d4de6a326966bd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:25:24 +0300 Subject: [PATCH 31/48] Async page.setInputFiles --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index ee6190cd8..a810775a5 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -268,7 +268,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.SetExtraHTTPHeaders(headers) //nolint:wrapcheck }) }, - "setInputFiles": p.SetInputFiles, + "setInputFiles": func(selector string, files goja.Value, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.SetInputFiles(selector, files, opts) //nolint:wrapcheck + }) + }, "setViewportSize": p.SetViewportSize, "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { popts := common.NewFrameTapOptions(p.Timeout()) From 62461eb0b0c2eaadfb878414c422474ffa8d81dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:25:55 +0300 Subject: [PATCH 32/48] Async page.setViewportSize --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index a810775a5..62ace9bd5 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -273,7 +273,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.SetInputFiles(selector, files, opts) //nolint:wrapcheck }) }, - "setViewportSize": p.SetViewportSize, + "setViewportSize": func(viewportSize goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.SetViewportSize(viewportSize) //nolint:wrapcheck + }) + }, "tap": func(selector string, opts goja.Value) (*goja.Promise, error) { popts := common.NewFrameTapOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { From 814884531f70e023f1804afa8fc6553b2e69ce4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:26:18 +0300 Subject: [PATCH 33/48] Async page.textContent --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 62ace9bd5..9e00cbf85 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -287,7 +287,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Tap(selector, popts) //nolint:wrapcheck }), nil }, - "textContent": p.TextContent, + "textContent": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.TextContent(selector, opts) //nolint:wrapcheck + }) + }, "throttleCPU": p.ThrottleCPU, "throttleNetwork": p.ThrottleNetwork, "title": p.Title, From 895c3679feb07720edee71f5a2314aad3aeb0f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:27:22 +0300 Subject: [PATCH 34/48] Async page.throttleCPU --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 9e00cbf85..f5df1fac0 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -292,7 +292,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.TextContent(selector, opts) //nolint:wrapcheck }) }, - "throttleCPU": p.ThrottleCPU, + "throttleCPU": func(cpuProfile common.CPUProfile) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.ThrottleCPU(cpuProfile) //nolint:wrapcheck + }) + }, "throttleNetwork": p.ThrottleNetwork, "title": p.Title, "touchscreen": mapTouchscreen(vu, p.GetTouchscreen()), From 78b8119e4afec324c852aad73042218c48a50693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:27:54 +0300 Subject: [PATCH 35/48] Async page.throttleNetwork --- browser/page_mapping.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index f5df1fac0..bc2a82564 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -297,13 +297,17 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.ThrottleCPU(cpuProfile) //nolint:wrapcheck }) }, - "throttleNetwork": p.ThrottleNetwork, - "title": p.Title, - "touchscreen": mapTouchscreen(vu, p.GetTouchscreen()), - "type": p.Type, - "uncheck": p.Uncheck, - "url": p.URL, - "viewportSize": p.ViewportSize, + "throttleNetwork": func(networkProfile common.NetworkProfile) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.ThrottleNetwork(networkProfile) //nolint:wrapcheck + }) + }, + "title": p.Title, + "touchscreen": mapTouchscreen(vu, p.GetTouchscreen()), + "type": p.Type, + "uncheck": p.Uncheck, + "url": p.URL, + "viewportSize": p.ViewportSize, "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), p.Timeout(), pageFunc, opts, args..., From 6d9134d6ee3a51147741030cd7446ae371bc9247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:28:21 +0300 Subject: [PATCH 36/48] Async page.title --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index bc2a82564..272e2f569 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -302,7 +302,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.ThrottleNetwork(networkProfile) //nolint:wrapcheck }) }, - "title": p.Title, + "title": func() *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.Title() //nolint:wrapcheck + }) + }, "touchscreen": mapTouchscreen(vu, p.GetTouchscreen()), "type": p.Type, "uncheck": p.Uncheck, From abb570af9ce2bf9e284daf448230a3560b60bd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:28:49 +0300 Subject: [PATCH 37/48] Async page.type --- browser/page_mapping.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 272e2f569..0d7dbf36a 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -307,8 +307,12 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.Title() //nolint:wrapcheck }) }, - "touchscreen": mapTouchscreen(vu, p.GetTouchscreen()), - "type": p.Type, + "touchscreen": mapTouchscreen(vu, p.GetTouchscreen()), + "type": func(selector string, text string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Type(selector, text, opts) //nolint:wrapcheck + }) + }, "uncheck": p.Uncheck, "url": p.URL, "viewportSize": p.ViewportSize, From ee81639cc14c67cf9514d52bc52925e2a76c4d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:29:05 +0300 Subject: [PATCH 38/48] Async page.uncheck --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 0d7dbf36a..d79959c3d 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -313,7 +313,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Type(selector, text, opts) //nolint:wrapcheck }) }, - "uncheck": p.Uncheck, + "uncheck": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.Uncheck(selector, opts) //nolint:wrapcheck + }) + }, "url": p.URL, "viewportSize": p.ViewportSize, "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { From adc3814d8ae82bfd2884f51f38766c6d6a77d871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:29:32 +0300 Subject: [PATCH 39/48] Async page.viewportSize --- browser/page_mapping.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index d79959c3d..bf99879bb 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -318,8 +318,12 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Uncheck(selector, opts) //nolint:wrapcheck }) }, - "url": p.URL, - "viewportSize": p.ViewportSize, + "url": p.URL, + "viewportSize": func() *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return p.ViewportSize(), nil + }) + }, "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), p.Timeout(), pageFunc, opts, args..., From adbd3f2ac89c93fe6938a290feb7e72401c591d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:30:10 +0300 Subject: [PATCH 40/48] Async page.waitForLoadState --- browser/page_mapping.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index bf99879bb..4ac0a3bc9 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -336,7 +336,11 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return p.WaitForFunction(js, popts, pargs...) //nolint:wrapcheck }), nil }, - "waitForLoadState": p.WaitForLoadState, + "waitForLoadState": func(state string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + return nil, p.WaitForLoadState(state, opts) //nolint:wrapcheck + }) + }, "waitForNavigation": func(opts goja.Value) (*goja.Promise, error) { popts := common.NewFrameWaitForNavigationOptions(p.Timeout()) if err := popts.Parse(vu.Context(), opts); err != nil { From 1ee0f7b2bdcd62a582a3d323643fea3a7993172f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:31:11 +0300 Subject: [PATCH 41/48] Async page.waitForSelector --- browser/page_mapping.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 4ac0a3bc9..5ead9e5b4 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -355,12 +355,14 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapResponse(vu, resp), nil }), nil }, - "waitForSelector": func(selector string, opts goja.Value) (mapping, error) { - eh, err := p.WaitForSelector(selector, opts) - if err != nil { - return nil, err //nolint:wrapcheck - } - return mapElementHandle(vu, eh), nil + "waitForSelector": func(selector string, opts goja.Value) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + eh, err := p.WaitForSelector(selector, opts) + if err != nil { + return nil, err //nolint:wrapcheck + } + return mapElementHandle(vu, eh), nil + }) }, "waitForTimeout": p.WaitForTimeout, "workers": func() *goja.Object { From 2d617a6f98518408db527cce9080fc653e40c791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:32:04 +0300 Subject: [PATCH 42/48] Async page.waitForTimeout --- browser/page_mapping.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 5ead9e5b4..02b144e2e 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -364,7 +364,12 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return mapElementHandle(vu, eh), nil }) }, - "waitForTimeout": p.WaitForTimeout, + "waitForTimeout": func(timeout int64) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + p.WaitForTimeout(timeout) + return nil, nil + }) + }, "workers": func() *goja.Object { var mws []mapping for _, w := range p.Workers() { From 67b755b269d73b89deba3d7c20af73fea07a6ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:32:37 +0300 Subject: [PATCH 43/48] Async page.query --- browser/page_mapping.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 02b144e2e..986f6de69 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -379,20 +379,22 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return rt.ToValue(mws).ToObject(rt) }, } - maps["$"] = func(selector string) (mapping, error) { - eh, err := p.Query(selector) - if err != nil { - return nil, err //nolint:wrapcheck - } - // ElementHandle can be null when the selector does not match any elements. - // We do not want to map nil elementHandles since the expectation is a - // null result in the test script for this case. - if eh == nil { - return nil, nil //nolint:nilnil - } - ehm := mapElementHandle(vu, eh) + maps["$"] = func(selector string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + eh, err := p.Query(selector) + if err != nil { + return nil, err //nolint:wrapcheck + } + // ElementHandle can be null when the selector does not match any elements. + // We do not want to map nil elementHandles since the expectation is a + // null result in the test script for this case. + if eh == nil { + return nil, nil + } + ehm := mapElementHandle(vu, eh) - return ehm, nil + return ehm, nil + }) } maps["$$"] = func(selector string) ([]mapping, error) { ehs, err := p.QueryAll(selector) From 8852b68131eba1ac88a88fd20564a1e04eed24b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:33:03 +0300 Subject: [PATCH 44/48] Async page.queryAll --- browser/page_mapping.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 986f6de69..9f865a593 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -396,17 +396,19 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return ehm, nil }) } - maps["$$"] = func(selector string) ([]mapping, error) { - ehs, err := p.QueryAll(selector) - if err != nil { - return nil, err //nolint:wrapcheck - } - var mehs []mapping - for _, eh := range ehs { - ehm := mapElementHandle(vu, eh) - mehs = append(mehs, ehm) - } - return mehs, nil + maps["$$"] = func(selector string) *goja.Promise { + return k6ext.Promise(vu.Context(), func() (any, error) { + ehs, err := p.QueryAll(selector) + if err != nil { + return nil, err //nolint:wrapcheck + } + var mehs []mapping + for _, eh := range ehs { + ehm := mapElementHandle(vu, eh) + mehs = append(mehs, ehm) + } + return mehs, nil + }) } return maps From eb01583b9b44cac9df9d27461e1405ea2f5e56ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 14:38:26 +0300 Subject: [PATCH 45/48] Update async page tests --- tests/browser_test.go | 2 +- tests/browser_type_test.go | 2 +- tests/page_test.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/browser_test.go b/tests/browser_test.go index ac372d037..1cc3e9831 100644 --- a/tests/browser_test.go +++ b/tests/browser_test.go @@ -233,7 +233,7 @@ func TestBrowserCrashErr(t *testing.T) { vu.SetVar(t, "browser", jsMod.Browser) _, err := vu.RunAsync(t, ` const p = await browser.newPage(); - p.close(); + await p.close(); `) assert.ErrorContains(t, err, "launching browser: Invalid devtools server port") } diff --git a/tests/browser_type_test.go b/tests/browser_type_test.go index 1a7080fc9..b803c7256 100644 --- a/tests/browser_type_test.go +++ b/tests/browser_type_test.go @@ -52,7 +52,7 @@ func TestBrowserTypeLaunchToConnect(t *testing.T) { vu.SetVar(t, "browser", jsMod.Browser) _, err := vu.RunAsync(t, ` const p = await browser.newPage(); - p.close(); + await p.close(); `) require.NoError(t, err) diff --git a/tests/page_test.go b/tests/page_test.go index b83d1115b..e89756051 100644 --- a/tests/page_test.go +++ b/tests/page_test.go @@ -275,13 +275,13 @@ func TestPageEvaluateMappingError(t *testing.T) { vu.SetVar(t, "p", &goja.Object{}) _, err := vu.RunAsync(t, ` p = await browser.newPage() - p.evaluate(%s) + await p.evaluate(%s) `, tt.script) assert.ErrorContains(t, err, tt.wantErr) // Test script as string input _, err = vu.RunAsync(t, ` - p.evaluate("%s") + await p.evaluate("%s") `, tt.script) assert.ErrorContains(t, err, tt.wantErr) }) @@ -1731,7 +1731,7 @@ func TestShadowDOMAndDocumentFragment(t *testing.T) { got := vu.RunPromise(t, ` const p = await browser.newPage() - p.goto("%s/%s/shadow_and_doc_frag.html") + await p.goto("%s/%s/shadow_and_doc_frag.html") const s = p.locator('%s') await s.waitFor({ From 0d9211790ff5d037d8858c929f526bec5d2c1ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 28 May 2024 15:00:10 +0300 Subject: [PATCH 46/48] Update JS examples for async page --- examples/colorscheme.js | 4 ++-- examples/cookies.js | 2 +- examples/device_emulation.js | 4 ++-- examples/dispatch.js | 2 +- examples/elementstate.js | 32 +++++++++++++++++++++++--------- examples/evaluate.js | 6 +++--- examples/fillform.js | 2 +- examples/getattribute.js | 4 ++-- examples/grant_permission.js | 4 ++-- examples/hosts.js | 2 +- examples/keyboard.js | 2 +- examples/locator.js | 2 +- examples/locator_pom.js | 2 +- examples/multiple-scenario.js | 4 ++-- examples/pageon.js | 4 ++-- examples/querying.js | 2 +- examples/screenshot.js | 4 ++-- examples/shadowdom.js | 8 ++++++-- examples/throttle.js | 10 +++++----- examples/touchscreen.js | 2 +- examples/waitForEvent.js | 4 ++-- examples/waitforfunction.js | 4 ++-- 22 files changed, 64 insertions(+), 46 deletions(-) diff --git a/examples/colorscheme.js b/examples/colorscheme.js index 6fdce9996..101f8a159 100644 --- a/examples/colorscheme.js +++ b/examples/colorscheme.js @@ -31,7 +31,7 @@ export default async function() { 'https://googlechromelabs.github.io/dark-mode-toggle/demo/', { waitUntil: 'load' }, ) - const colorScheme = page.evaluate(() => { + const colorScheme = await page.evaluate(() => { return { isDarkColorScheme: window.matchMedia('(prefers-color-scheme: dark)').matches }; @@ -40,6 +40,6 @@ export default async function() { 'isDarkColorScheme': cs => cs.isDarkColorScheme }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/cookies.js b/examples/cookies.js index 45076fab8..1f31ccef3 100644 --- a/examples/cookies.js +++ b/examples/cookies.js @@ -122,6 +122,6 @@ export default async function () { 'number of cookies should be zero': n => n === 0, }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/device_emulation.js b/examples/device_emulation.js index 94c3b3602..4a730e1f3 100644 --- a/examples/device_emulation.js +++ b/examples/device_emulation.js @@ -28,7 +28,7 @@ export default async function() { try { await page.goto('https://k6.io/', { waitUntil: 'networkidle' }); - const dimensions = page.evaluate(() => { + const dimensions = await page.evaluate(() => { return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, @@ -46,6 +46,6 @@ export default async function() { sleep(10); } } finally { - page.close(); + await page.close(); } } diff --git a/examples/dispatch.js b/examples/dispatch.js index 8c4defec9..01f0935ad 100644 --- a/examples/dispatch.js +++ b/examples/dispatch.js @@ -31,6 +31,6 @@ export default async function() { const ok = await h3.textContent() == "Contact us"; check(ok, { "header": ok }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/elementstate.js b/examples/elementstate.js index 3932b2316..2b2e10635 100644 --- a/examples/elementstate.js +++ b/examples/elementstate.js @@ -22,7 +22,7 @@ export default async function() { const page = await context.newPage(); // Inject page content - page.setContent(` + await page.setContent(`
Hello world
Edit me
@@ -33,13 +33,27 @@ export default async function() { `); // Check state - const isVisible = await page.$('.visible').isVisible(); - const isHidden = await page.$('.hidden').isHidden(); - const isEditable = await page.$('.editable').isEditable(); - const isEnabled = await page.$('.enabled').isEnabled(); - const isDisabled = await page.$('.disabled').isDisabled(); - const isChecked = await page.$('.checked').isChecked(); - const isUnchecked = await page.$('.unchecked').isChecked() === false; + let el = await page.$('.visible'); + const isVisible = await el.isVisible(); + + el = await page.$('.hidden'); + const isHidden = await el.isHidden(); + + el = await page.$('.editable'); + const isEditable = await el.isEditable(); + + el = await page.$('.enabled'); + const isEnabled = await el.isEnabled(); + + el = await page.$('.disabled'); + const isDisabled = await el.isDisabled(); + + el = await page.$('.checked'); + const isChecked = await el.isChecked(); + + el = await page.$('.unchecked'); + const isUnchecked = await el.isChecked() === false; + check(page, { 'visible': isVisible, 'hidden': isHidden, @@ -50,5 +64,5 @@ export default async function() { 'unchecked': isUnchecked, }); - page.close(); + await page.close(); } diff --git a/examples/evaluate.js b/examples/evaluate.js index 1e8a75e46..182f846e5 100644 --- a/examples/evaluate.js +++ b/examples/evaluate.js @@ -25,7 +25,7 @@ export default async function() { await page.goto("https://test.k6.io/", { waitUntil: "load" }); // calling evaluate without arguments - let result = page.evaluate(() => { + let result = await page.evaluate(() => { return Promise.resolve(5 * 42); }); check(result, { @@ -33,7 +33,7 @@ export default async function() { }); // calling evaluate with arguments - result = page.evaluate(([x, y]) => { + result = await page.evaluate(([x, y]) => { return Promise.resolve(x * y); }, [5, 5] ); @@ -41,6 +41,6 @@ export default async function() { "result should be 25": (result) => result == 25, }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/fillform.js b/examples/fillform.js index 5887735e5..f3bef2957 100644 --- a/examples/fillform.js +++ b/examples/fillform.js @@ -53,6 +53,6 @@ export default async function() { } }) } finally { - page.close(); + await page.close(); } } diff --git a/examples/getattribute.js b/examples/getattribute.js index 60291cad0..587e2e9dd 100644 --- a/examples/getattribute.js +++ b/examples/getattribute.js @@ -25,12 +25,12 @@ export default async function() { await page.goto('https://googlechromelabs.github.io/dark-mode-toggle/demo/', { waitUntil: 'load', }); - let el = page.$('#dark-mode-toggle-3'); + let el = await page.$('#dark-mode-toggle-3'); const mode = await el.getAttribute('mode'); check(mode, { "GetAttribute('mode')": mode === 'light', }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/grant_permission.js b/examples/grant_permission.js index 108473a73..714438690 100644 --- a/examples/grant_permission.js +++ b/examples/grant_permission.js @@ -27,9 +27,9 @@ export default async function() { try { await page.goto('https://test.k6.io/'); - page.screenshot({ path: `example-chromium.png` }); + await page.screenshot({ path: `example-chromium.png` }); await context.clearPermissions(); } finally { - page.close(); + await page.close(); } } diff --git a/examples/hosts.js b/examples/hosts.js index d4159623f..4458f104f 100644 --- a/examples/hosts.js +++ b/examples/hosts.js @@ -28,6 +28,6 @@ export default async function() { 'null response': r => r === null, }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/keyboard.js b/examples/keyboard.js index ff369da9e..5513d50c4 100644 --- a/examples/keyboard.js +++ b/examples/keyboard.js @@ -29,5 +29,5 @@ export default async function () { await page.keyboard.press('Enter'); // submit await page.waitForNavigation(); - page.close(); + await page.close(); } diff --git a/examples/locator.js b/examples/locator.js index e4f4d7dbe..da03f02da 100644 --- a/examples/locator.js +++ b/examples/locator.js @@ -69,6 +69,6 @@ export default async function() { ]); console.log(await currentBet.innerText()); } finally { - page.close(); + await page.close(); } } diff --git a/examples/locator_pom.js b/examples/locator_pom.js index 7958413b8..99b029b41 100644 --- a/examples/locator_pom.js +++ b/examples/locator_pom.js @@ -72,6 +72,6 @@ export default async function() { await bet.heads(); console.log("Current bet:", await bet.current()); } finally { - page.close(); + await page.close(); } } diff --git a/examples/multiple-scenario.js b/examples/multiple-scenario.js index 24828c526..35b792eea 100644 --- a/examples/multiple-scenario.js +++ b/examples/multiple-scenario.js @@ -38,7 +38,7 @@ export async function messages() { try { await page.goto('https://test.k6.io/my_messages.php', { waitUntil: 'networkidle' }); } finally { - page.close(); + await page.close(); } } @@ -48,6 +48,6 @@ export async function news() { try { await page.goto('https://test.k6.io/news.php', { waitUntil: 'networkidle' }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/pageon.js b/examples/pageon.js index 12254dd79..50185e849 100644 --- a/examples/pageon.js +++ b/examples/pageon.js @@ -32,8 +32,8 @@ export default async function() { }); }); - page.evaluate(() => console.log('this is a console.log message', 42)); + await page.evaluate(() => console.log('this is a console.log message', 42)); } finally { - page.close(); + await page.close(); } } diff --git a/examples/querying.js b/examples/querying.js index 570d40af1..ea410de3f 100644 --- a/examples/querying.js +++ b/examples/querying.js @@ -32,6 +32,6 @@ export default async function() { 'Title with XPath selector': titleWithXPath == 'test.k6.io', }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/screenshot.js b/examples/screenshot.js index a84b4397e..6faa143e9 100644 --- a/examples/screenshot.js +++ b/examples/screenshot.js @@ -22,10 +22,10 @@ export default async function() { try { await page.goto('https://test.k6.io/'); - page.screenshot({ path: 'screenshot.png' }); + await page.screenshot({ path: 'screenshot.png' }); // TODO: Assert this somehow. Upload as CI artifact or just an external `ls`? // Maybe even do a fuzzy image comparison against a preset known good screenshot? } finally { - page.close(); + await page.close(); } } diff --git a/examples/shadowdom.js b/examples/shadowdom.js index 0a6c7d520..70812ae0c 100644 --- a/examples/shadowdom.js +++ b/examples/shadowdom.js @@ -19,7 +19,9 @@ export const options = { export default async function() { const page = await browser.newPage(); - page.setContent("hello!") + + await page.setContent("hello!") + await page.evaluate(() => { const shadowRoot = document.createElement('div'); shadowRoot.id = 'shadow-root'; @@ -27,11 +29,13 @@ export default async function() { shadowRoot.shadowRoot.innerHTML = '

Shadow DOM

'; document.body.appendChild(shadowRoot); }); + const shadowEl = page.locator("#find"); const ok = await shadowEl.innerText() === "Shadow DOM"; check(shadowEl, { "shadow element exists": (e) => e !== null, "shadow element text is correct": () => ok, }); - page.close(); + + await page.close(); } diff --git a/examples/throttle.js b/examples/throttle.js index 6fd36c39c..3c661ae8a 100644 --- a/examples/throttle.js +++ b/examples/throttle.js @@ -45,7 +45,7 @@ export async function normal() { try { await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); } finally { - page.close(); + await page.close(); } } @@ -54,11 +54,11 @@ export async function networkThrottled() { const page = await context.newPage(); try { - page.throttleNetwork(networkProfiles['Slow 3G']); + await page.throttleNetwork(networkProfiles["Slow 3G"]); await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); } finally { - page.close(); + await page.close(); } } @@ -67,10 +67,10 @@ export async function cpuThrottled() { const page = await context.newPage(); try { - page.throttleCPU({ rate: 4 }); + await page.throttleCPU({ rate: 4 }); await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); } finally { - page.close(); + await page.close(); } } diff --git a/examples/touchscreen.js b/examples/touchscreen.js index 937843e58..61c4b4574 100644 --- a/examples/touchscreen.js +++ b/examples/touchscreen.js @@ -30,5 +30,5 @@ export default async function () { page.touchscreen.tap(newsLinkBox.x + newsLinkBox.width / 2, newsLinkBox.y), ]); - page.close(); + await page.close(); } diff --git a/examples/waitForEvent.js b/examples/waitForEvent.js index 0d5180465..d905debc6 100644 --- a/examples/waitForEvent.js +++ b/examples/waitForEvent.js @@ -34,6 +34,6 @@ export default async function() { await promise console.log('predicate passed') - page.close() - page2.close() + await page.close() + await page2.close(); }; diff --git a/examples/waitforfunction.js b/examples/waitforfunction.js index de57e4b86..d6c774cdb 100644 --- a/examples/waitforfunction.js +++ b/examples/waitforfunction.js @@ -22,7 +22,7 @@ export default async function() { const page = await context.newPage(); try { - page.evaluate(() => { + await page.evaluate(() => { setTimeout(() => { const el = document.createElement('h1'); el.innerHTML = 'Hello'; @@ -36,6 +36,6 @@ export default async function() { }); check(ok, { 'waitForFunction successfully resolved': ok.innerHTML() == 'Hello' }); } finally { - page.close(); + await page.close(); } } From ad9e5b591ee58336d529572636f1471f63aa1655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 29 May 2024 15:09:06 +0300 Subject: [PATCH 47/48] Add forgetten page err checks in tests This is happened after rebasing main. --- tests/launch_options_slowmo_test.go | 3 ++- tests/lifecycle_wait_test.go | 3 ++- tests/page_test.go | 9 ++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/launch_options_slowmo_test.go b/tests/launch_options_slowmo_test.go index 0866468c6..889b2205a 100644 --- a/tests/launch_options_slowmo_test.go +++ b/tests/launch_options_slowmo_test.go @@ -128,7 +128,8 @@ func TestBrowserOptionsSlowMo(t *testing.T) { t.Parallel() tb := newTestBrowser(t, withFileServer()) testPageSlowMoImpl(t, tb, func(_ *testBrowser, p *common.Page) { - p.Reload(nil) + _, err := p.Reload(nil) + require.NoError(t, err) }) }) t.Run("setContent", func(t *testing.T) { diff --git a/tests/lifecycle_wait_test.go b/tests/lifecycle_wait_test.go index be762732a..2431ff340 100644 --- a/tests/lifecycle_wait_test.go +++ b/tests/lifecycle_wait_test.go @@ -416,7 +416,8 @@ func TestLifecycleReload(t *testing.T) { WaitUntil: tt.waitUntil, Timeout: 30 * time.Second, }) - p.Reload(opts) + _, err = p.Reload(opts) + require.NoError(t, err) result, err = p.TextContent("#pingRequestText", nil) if err != nil { diff --git a/tests/page_test.go b/tests/page_test.go index e89756051..188e56efd 100644 --- a/tests/page_test.go +++ b/tests/page_test.go @@ -666,7 +666,8 @@ func TestPageSetExtraHTTPHeaders(t *testing.T) { headers := map[string]string{ "Some-Header": "Some-Value", } - p.SetExtraHTTPHeaders(headers) + err := p.SetExtraHTTPHeaders(headers) + require.NoError(t, err) opts := &common.FrameGotoOptions{ Timeout: common.DefaultTimeout, @@ -1790,13 +1791,15 @@ func TestPageTargetBlank(t *testing.T) { p2, ok := obj.(*common.Page) require.True(t, ok, "return from WaitForEvent is not a Page") - p2.WaitForLoadState(common.LifecycleEventLoad.String(), nil) + err = p2.WaitForLoadState(common.LifecycleEventLoad.String(), nil) + require.NoError(t, err) // Now there should be 2 pages. pp = p.Context().Pages() assert.Equal(t, 2, len(pp)) // Make sure the new page contains the correct page. - got := p2.InnerHTML("h1", nil) + got, err := p2.InnerHTML("h1", nil) + require.NoError(t, err) assert.Equal(t, "you clicked!", got) } From 7608b48cc090c346a36fde1b42819ea76a45d15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 30 May 2024 12:36:31 +0300 Subject: [PATCH 48/48] Revert "Async page.viewportSize" This reverts commit adc3814d8ae82bfd2884f51f38766c6d6a77d871. --- browser/page_mapping.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/browser/page_mapping.go b/browser/page_mapping.go index 9f865a593..28be0e234 100644 --- a/browser/page_mapping.go +++ b/browser/page_mapping.go @@ -318,12 +318,8 @@ func mapPage(vu moduleVU, p *common.Page) mapping { //nolint:gocognit,cyclop return nil, p.Uncheck(selector, opts) //nolint:wrapcheck }) }, - "url": p.URL, - "viewportSize": func() *goja.Promise { - return k6ext.Promise(vu.Context(), func() (any, error) { - return p.ViewportSize(), nil - }) - }, + "url": p.URL, + "viewportSize": p.ViewportSize, "waitForFunction": func(pageFunc, opts goja.Value, args ...goja.Value) (*goja.Promise, error) { js, popts, pargs, err := parseWaitForFunctionArgs( vu.Context(), p.Timeout(), pageFunc, opts, args...,