From 8ca6ebe5357f183b4d0e159196db72b76ba47335 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 16:10:47 +0000 Subject: [PATCH 1/9] Remove timeout parameter for isVisible This removes the need to pass in a 0 value for the timeout from frame and elementHandle. The reason for removing the timeout is that isVisible doesn't wait on an element, so there is no need for a timeout. --- common/element_handle.go | 6 +++--- common/frame.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/element_handle.go b/common/element_handle.go index 1573a33cd..e4c7c9c23 100644 --- a/common/element_handle.go +++ b/common/element_handle.go @@ -386,8 +386,8 @@ func (h *ElementHandle) isHidden(apiCtx context.Context, timeout time.Duration) return h.waitForElementState(apiCtx, []string{"hidden"}, timeout) } -func (h *ElementHandle) isVisible(apiCtx context.Context, timeout time.Duration) (bool, error) { - return h.waitForElementState(apiCtx, []string{"visible"}, timeout) +func (h *ElementHandle) isVisible(apiCtx context.Context) (bool, error) { + return h.waitForElementState(apiCtx, []string{"visible"}, 0) } func (h *ElementHandle) offsetPosition(apiCtx context.Context, offset *Position) (*Position, error) { @@ -958,7 +958,7 @@ func (h *ElementHandle) IsHidden() bool { // IsVisible checks if the element is visible. func (h *ElementHandle) IsVisible() bool { - result, err := h.isVisible(h.ctx, 0) + result, err := h.isVisible(h.ctx) if err != nil && !errors.Is(err, ErrTimedOut) { // We don't care anout timeout errors here! k6ext.Panic(h.ctx, "checking element is visible: %w", err) } diff --git a/common/frame.go b/common/frame.go index efbf056bb..47b67fd2d 100644 --- a/common/frame.go +++ b/common/frame.go @@ -1292,8 +1292,8 @@ func (f *Frame) IsVisible(selector string, opts goja.Value) (bool, error) { func (f *Frame) isVisible(selector string, opts *FrameIsVisibleOptions) (bool, error) { isVisible := func(apiCtx context.Context, handle *ElementHandle) (any, error) { - v, err := handle.isVisible(apiCtx, 0) // Zero timeout when checking state - if errors.Is(err, ErrTimedOut) { // We don't care about timeout errors here! + v, err := handle.isVisible(apiCtx) // Zero timeout when checking state + if errors.Is(err, ErrTimedOut) { // We don't care about timeout errors here! return v, nil } return v, err From 293b879978b51dc136f2e43518410a97fae0e06b Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 16:13:40 +0000 Subject: [PATCH 2/9] Remove timeout parameter for isHidden This removes the need to pass in a 0 value for the timeout from frame and elementHandle. The reason for removing the timeout is that isHidden doesn't wait on an element, so there is no need for a timeout. --- common/element_handle.go | 6 +++--- common/frame.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/element_handle.go b/common/element_handle.go index e4c7c9c23..1c3719770 100644 --- a/common/element_handle.go +++ b/common/element_handle.go @@ -382,8 +382,8 @@ func (h *ElementHandle) isEnabled(apiCtx context.Context, timeout time.Duration) return h.waitForElementState(apiCtx, []string{"enabled"}, timeout) } -func (h *ElementHandle) isHidden(apiCtx context.Context, timeout time.Duration) (bool, error) { - return h.waitForElementState(apiCtx, []string{"hidden"}, timeout) +func (h *ElementHandle) isHidden(apiCtx context.Context) (bool, error) { + return h.waitForElementState(apiCtx, []string{"hidden"}, 0) } func (h *ElementHandle) isVisible(apiCtx context.Context) (bool, error) { @@ -949,7 +949,7 @@ func (h *ElementHandle) IsEnabled() bool { // IsHidden checks if the element is hidden. func (h *ElementHandle) IsHidden() bool { - result, err := h.isHidden(h.ctx, 0) + result, err := h.isHidden(h.ctx) if err != nil && !errors.Is(err, ErrTimedOut) { // We don't care anout timeout errors here! k6ext.Panic(h.ctx, "checking element is hidden: %w", err) } diff --git a/common/frame.go b/common/frame.go index 47b67fd2d..28c573c49 100644 --- a/common/frame.go +++ b/common/frame.go @@ -1259,8 +1259,8 @@ func (f *Frame) IsHidden(selector string, opts goja.Value) (bool, error) { func (f *Frame) isHidden(selector string, opts *FrameIsHiddenOptions) (bool, error) { isHidden := func(apiCtx context.Context, handle *ElementHandle) (any, error) { - v, err := handle.isHidden(apiCtx, 0) // Zero timeout when checking state - if errors.Is(err, ErrTimedOut) { // We don't care about timeout errors here! + v, err := handle.isHidden(apiCtx) // Zero timeout when checking state + if errors.Is(err, ErrTimedOut) { // We don't care about timeout errors here! return v, nil } return v, err From 588415487b16fe074751c4159c9c60a645cf2325 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 16:40:23 +0000 Subject: [PATCH 3/9] Remove the timeout from the isVisible option The timeout is no longer used since isVisible now returns straight away without waiting for an element to match if one doesn't already exist. --- common/frame.go | 2 +- common/frame_options.go | 20 +++++++++++++------- common/locator.go | 2 +- tests/page_test.go | 8 ++------ 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/common/frame.go b/common/frame.go index 28c573c49..85eaa0b8a 100644 --- a/common/frame.go +++ b/common/frame.go @@ -1278,7 +1278,7 @@ func (f *Frame) isHidden(selector string, opts *FrameIsHiddenOptions) (bool, err func (f *Frame) IsVisible(selector string, opts goja.Value) (bool, error) { f.log.Debugf("Frame:IsVisible", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) - popts := NewFrameIsVisibleOptions(f.defaultTimeout()) + popts := NewFrameIsVisibleOptions() if err := popts.Parse(f.ctx, opts); err != nil { return false, fmt.Errorf("parsing is visible options: %w", err) } diff --git a/common/frame_options.go b/common/frame_options.go index 76b762119..98b2cbc40 100644 --- a/common/frame_options.go +++ b/common/frame_options.go @@ -82,7 +82,7 @@ type FrameIsHiddenOptions struct { } type FrameIsVisibleOptions struct { - FrameBaseOptions + Strict bool `json:"strict"` } type FramePressOptions struct { @@ -468,15 +468,21 @@ func (o *FrameIsHiddenOptions) Parse(ctx context.Context, opts goja.Value) error return nil } -func NewFrameIsVisibleOptions(defaultTimeout time.Duration) *FrameIsVisibleOptions { - return &FrameIsVisibleOptions{ - FrameBaseOptions: *NewFrameBaseOptions(defaultTimeout), - } +// NewFrameIsVisibleOptions creates and returns a new instance of FrameIsVisibleOptions. +func NewFrameIsVisibleOptions() *FrameIsVisibleOptions { + return &FrameIsVisibleOptions{} } func (o *FrameIsVisibleOptions) Parse(ctx context.Context, opts goja.Value) error { - if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { - return err + rt := k6ext.Runtime(ctx) + if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + opts := opts.ToObject(rt) + for _, k := range opts.Keys() { + switch k { + case "strict": + o.Strict = opts.Get(k).ToBoolean() + } + } } return nil } diff --git a/common/locator.go b/common/locator.go index b9b22beb2..b46ed79ff 100644 --- a/common/locator.go +++ b/common/locator.go @@ -236,7 +236,7 @@ func (l *Locator) isDisabled(opts *FrameIsDisabledOptions) (bool, error) { func (l *Locator) IsVisible(opts goja.Value) bool { l.log.Debugf("Locator:IsVisible", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) - copts := NewFrameIsVisibleOptions(l.frame.defaultTimeout()) + copts := NewFrameIsVisibleOptions() if err := copts.Parse(l.ctx, opts); err != nil { k6ext.Panic(l.ctx, "parsing is visible options: %w", err) } diff --git a/tests/page_test.go b/tests/page_test.go index 93cbd66fd..3eb9f0282 100644 --- a/tests/page_test.go +++ b/tests/page_test.go @@ -1270,9 +1270,7 @@ func TestPageIsVisible(t *testing.T) { name: "first_div", selector: "div", options: common.FrameIsVisibleOptions{ - FrameBaseOptions: common.FrameBaseOptions{ - Strict: true, - }, + Strict: true, }, wantErr: "error:strictmodeviolation", }, @@ -1337,9 +1335,7 @@ func TestPageIsHidden(t *testing.T) { name: "first_div", selector: "div", options: common.FrameIsVisibleOptions{ - FrameBaseOptions: common.FrameBaseOptions{ - Strict: true, - }, + Strict: true, }, wantErr: "error:strictmodeviolation", }, From 0bb82a766c663492dbab6ce85abbc4d5dcfa0822 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 16:45:12 +0000 Subject: [PATCH 4/9] Remove the options on locator.isVisible It did accepts options which were strict and timeout. Strict is enabled and cannot be changed when working with the locator API. Timeout is no longer useful when working with isVisible. --- common/locator.go | 17 +++-------------- tests/locator_test.go | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/common/locator.go b/common/locator.go index b46ed79ff..c9fc74764 100644 --- a/common/locator.go +++ b/common/locator.go @@ -233,14 +233,10 @@ func (l *Locator) isDisabled(opts *FrameIsDisabledOptions) (bool, error) { // IsVisible returns true if the element matches the locator's // selector and is visible. Otherwise, returns false. -func (l *Locator) IsVisible(opts goja.Value) bool { - l.log.Debugf("Locator:IsVisible", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) +func (l *Locator) IsVisible() bool { + l.log.Debugf("Locator:IsVisible", "fid:%s furl:%q sel:%q", l.frame.ID(), l.frame.URL(), l.selector) - copts := NewFrameIsVisibleOptions() - if err := copts.Parse(l.ctx, opts); err != nil { - k6ext.Panic(l.ctx, "parsing is visible options: %w", err) - } - visible, err := l.isVisible(copts) + visible, err := l.frame.isVisible(l.selector, &FrameIsVisibleOptions{Strict: true}) if err != nil { k6ext.Panic(l.ctx, "checking is %q visible: %w", l.selector, err) } @@ -248,13 +244,6 @@ func (l *Locator) IsVisible(opts goja.Value) bool { return visible } -// isVisible is like IsVisible but takes parsed options and does not -// throw an error. -func (l *Locator) isVisible(opts *FrameIsVisibleOptions) (bool, error) { - opts.Strict = true - return l.frame.isVisible(l.selector, opts) -} - // IsHidden returns true if the element matches the locator's // selector and is hidden. Otherwise, returns false. func (l *Locator) IsHidden(opts goja.Value) (bool, error) { diff --git a/tests/locator_test.go b/tests/locator_test.go index 402bf9dde..19c88f2f0 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -354,7 +354,7 @@ func TestLocatorElementState(t *testing.T) { { "visible", `() => document.getElementById('inputText').style.visibility = 'hidden'`, - func(l *common.Locator) bool { return l.IsVisible(nil) }, + func(l *common.Locator) bool { return l.IsVisible() }, }, } From c38f9b86c64cdc231f0716488ba453a10c81ad60 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 16:49:35 +0000 Subject: [PATCH 5/9] Refactor locator.isVisible to return an error --- common/locator.go | 6 +++--- tests/locator_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/locator.go b/common/locator.go index c9fc74764..d78f16037 100644 --- a/common/locator.go +++ b/common/locator.go @@ -233,15 +233,15 @@ func (l *Locator) isDisabled(opts *FrameIsDisabledOptions) (bool, error) { // IsVisible returns true if the element matches the locator's // selector and is visible. Otherwise, returns false. -func (l *Locator) IsVisible() bool { +func (l *Locator) IsVisible() (bool, error) { l.log.Debugf("Locator:IsVisible", "fid:%s furl:%q sel:%q", l.frame.ID(), l.frame.URL(), l.selector) visible, err := l.frame.isVisible(l.selector, &FrameIsVisibleOptions{Strict: true}) if err != nil { - k6ext.Panic(l.ctx, "checking is %q visible: %w", l.selector, err) + return false, fmt.Errorf("checking is %q visible: %w", l.selector, err) } - return visible + return visible, nil } // IsHidden returns true if the element matches the locator's diff --git a/tests/locator_test.go b/tests/locator_test.go index 19c88f2f0..a5434939d 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -354,7 +354,7 @@ func TestLocatorElementState(t *testing.T) { { "visible", `() => document.getElementById('inputText').style.visibility = 'hidden'`, - func(l *common.Locator) bool { return l.IsVisible() }, + func(l *common.Locator) bool { resp, _ := l.IsVisible(); return resp }, }, } From 300e19b54d6e13186145b2b8e7068c6c0ac6dff4 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 16:54:29 +0000 Subject: [PATCH 6/9] Remove the timeout from the isHidden option The timeout is no longer used since isHidden now returns straight away without waiting for an element to match if one doesn't already exist. --- common/frame.go | 2 +- common/frame_options.go | 20 +++++++++++++------- common/locator.go | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/common/frame.go b/common/frame.go index 85eaa0b8a..725da1946 100644 --- a/common/frame.go +++ b/common/frame.go @@ -1245,7 +1245,7 @@ func (f *Frame) isDisabled(selector string, opts *FrameIsDisabledOptions) (bool, func (f *Frame) IsHidden(selector string, opts goja.Value) (bool, error) { f.log.Debugf("Frame:IsHidden", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector) - popts := NewFrameIsHiddenOptions(f.defaultTimeout()) + popts := NewFrameIsHiddenOptions() if err := popts.Parse(f.ctx, opts); err != nil { return false, fmt.Errorf("parsing is hidden options: %w", err) } diff --git a/common/frame_options.go b/common/frame_options.go index 98b2cbc40..602552907 100644 --- a/common/frame_options.go +++ b/common/frame_options.go @@ -78,7 +78,7 @@ type FrameIsEnabledOptions struct { } type FrameIsHiddenOptions struct { - FrameBaseOptions + Strict bool `json:"strict"` } type FrameIsVisibleOptions struct { @@ -455,15 +455,21 @@ func (o *FrameIsEnabledOptions) Parse(ctx context.Context, opts goja.Value) erro return nil } -func NewFrameIsHiddenOptions(defaultTimeout time.Duration) *FrameIsHiddenOptions { - return &FrameIsHiddenOptions{ - FrameBaseOptions: *NewFrameBaseOptions(defaultTimeout), - } +// NewFrameIsHiddenOptions creates and returns a new instance of FrameIsHiddenOptions. +func NewFrameIsHiddenOptions() *FrameIsHiddenOptions { + return &FrameIsHiddenOptions{} } func (o *FrameIsHiddenOptions) Parse(ctx context.Context, opts goja.Value) error { - if err := o.FrameBaseOptions.Parse(ctx, opts); err != nil { - return err + rt := k6ext.Runtime(ctx) + if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + opts := opts.ToObject(rt) + for _, k := range opts.Keys() { + switch k { + case "strict": + o.Strict = opts.Get(k).ToBoolean() + } + } } return nil } diff --git a/common/locator.go b/common/locator.go index d78f16037..cf6421fa5 100644 --- a/common/locator.go +++ b/common/locator.go @@ -249,7 +249,7 @@ func (l *Locator) IsVisible() (bool, error) { func (l *Locator) IsHidden(opts goja.Value) (bool, error) { l.log.Debugf("Locator:IsHidden", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) - copts := NewFrameIsHiddenOptions(l.frame.defaultTimeout()) + copts := NewFrameIsHiddenOptions() if err := copts.Parse(l.ctx, opts); err != nil { return false, fmt.Errorf("parsing is hidden options: %w", err) } From 5928ccd160056c33bb41dcf86a62e1ebc405452e Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 16:57:55 +0000 Subject: [PATCH 7/9] Remove the options on locator.isHidden It did accepts options which were strict and timeout. Strict is enabled and cannot be changed when working with the locator API. Timeout is no longer useful when working with isHidden. --- common/locator.go | 17 +++-------------- tests/locator_test.go | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/common/locator.go b/common/locator.go index cf6421fa5..1fa1ac769 100644 --- a/common/locator.go +++ b/common/locator.go @@ -246,14 +246,10 @@ func (l *Locator) IsVisible() (bool, error) { // IsHidden returns true if the element matches the locator's // selector and is hidden. Otherwise, returns false. -func (l *Locator) IsHidden(opts goja.Value) (bool, error) { - l.log.Debugf("Locator:IsHidden", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts) +func (l *Locator) IsHidden() (bool, error) { + l.log.Debugf("Locator:IsHidden", "fid:%s furl:%q sel:%q", l.frame.ID(), l.frame.URL(), l.selector) - copts := NewFrameIsHiddenOptions() - if err := copts.Parse(l.ctx, opts); err != nil { - return false, fmt.Errorf("parsing is hidden options: %w", err) - } - hidden, err := l.isHidden(copts) + hidden, err := l.frame.isHidden(l.selector, &FrameIsHiddenOptions{Strict: true}) if err != nil { return false, fmt.Errorf("checking is %q hidden: %w", l.selector, err) } @@ -261,13 +257,6 @@ func (l *Locator) IsHidden(opts goja.Value) (bool, error) { return hidden, nil } -// isHidden is like IsHidden but takes parsed options and does not -// throw an error. -func (l *Locator) isHidden(opts *FrameIsHiddenOptions) (bool, error) { - opts.Strict = true - return l.frame.isHidden(l.selector, opts) -} - // Fill out the element using locator's selector with strict mode on. func (l *Locator) Fill(value string, opts goja.Value) { l.log.Debugf( diff --git a/tests/locator_test.go b/tests/locator_test.go index a5434939d..1c8cb346e 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -344,7 +344,7 @@ func TestLocatorElementState(t *testing.T) { { "hidden", `() => document.getElementById('inputText').style.visibility = 'hidden'`, - func(l *common.Locator) bool { resp, _ := l.IsHidden(nil); return !resp }, + func(l *common.Locator) bool { resp, _ := l.IsHidden(); return !resp }, }, { "readOnly", From 7e4d5ee0d9435678a52fe4d70ab559c838b313df Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 17:11:21 +0000 Subject: [PATCH 8/9] Add common parsing of strict option --- common/frame_options.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/common/frame_options.go b/common/frame_options.go index 602552907..06df9f575 100644 --- a/common/frame_options.go +++ b/common/frame_options.go @@ -773,3 +773,19 @@ func NewFrameDispatchEventOptions(defaultTimeout time.Duration) *FrameDispatchEv FrameBaseOptions: NewFrameBaseOptions(defaultTimeout), } } + +func parseStrict(ctx context.Context, opts goja.Value) bool { + var strict bool + + rt := k6ext.Runtime(ctx) + if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { + opts := opts.ToObject(rt) + for _, k := range opts.Keys() { + if k == "strict" { + strict = opts.Get(k).ToBoolean() + } + } + } + + return strict +} From 08d3dd825e483602fc58cdb51a6abc86f1b47360 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 23 Nov 2023 17:11:45 +0000 Subject: [PATCH 9/9] Refactor option parsing to use parseStrict --- common/frame_options.go | 99 ++++------------------------------------- 1 file changed, 9 insertions(+), 90 deletions(-) diff --git a/common/frame_options.go b/common/frame_options.go index 06df9f575..fb8ce75d1 100644 --- a/common/frame_options.go +++ b/common/frame_options.go @@ -223,19 +223,10 @@ func NewFrameCheckOptions(defaultTimeout time.Duration) *FrameCheckOptions { } func (o *FrameCheckOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil } @@ -247,19 +238,10 @@ func NewFrameClickOptions(defaultTimeout time.Duration) *FrameClickOptions { } func (o *FrameClickOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) if err := o.ElementHandleClickOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil } @@ -271,19 +253,10 @@ func NewFrameDblClickOptions(defaultTimeout time.Duration) *FrameDblclickOptions } func (o *FrameDblclickOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) if err := o.ElementHandleDblclickOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil } @@ -295,19 +268,10 @@ func NewFrameFillOptions(defaultTimeout time.Duration) *FrameFillOptions { } func (o *FrameFillOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) if err := o.ElementHandleBaseOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil } @@ -348,19 +312,10 @@ func NewFrameHoverOptions(defaultTimeout time.Duration) *FrameHoverOptions { } func (o *FrameHoverOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) if err := o.ElementHandleHoverOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil } @@ -461,16 +416,7 @@ func NewFrameIsHiddenOptions() *FrameIsHiddenOptions { } func (o *FrameIsHiddenOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil } @@ -480,16 +426,7 @@ func NewFrameIsVisibleOptions() *FrameIsVisibleOptions { } func (o *FrameIsVisibleOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil } @@ -514,19 +451,10 @@ func NewFrameSelectOptionOptions(defaultTimeout time.Duration) *FrameSelectOptio } func (o *FrameSelectOptionOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) if err := o.ElementHandleBaseOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil } @@ -623,19 +551,10 @@ func NewFrameUncheckOptions(defaultTimeout time.Duration) *FrameUncheckOptions { } func (o *FrameUncheckOptions) Parse(ctx context.Context, opts goja.Value) error { - rt := k6ext.Runtime(ctx) if err := o.ElementHandleBasePointerOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - switch k { - case "strict": - o.Strict = opts.Get(k).ToBoolean() - } - } - } + o.Strict = parseStrict(ctx, opts) return nil }