Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser: Fix ElemenHandle.SelectOption sobek #4574

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -194,8 +194,12 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping { //nolint:
if err != nil {
return nil, fmt.Errorf("parsing select options values: %w", err)
}
popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout())
if err := popts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing selectOption options: %w", err)
}
return k6ext.Promise(vu.Context(), func() (any, error) {
return eh.SelectOption(convValues, opts) //nolint:wrapcheck
return eh.SelectOption(convValues, popts) //nolint:wrapcheck
}), nil
},
"selectText": func(opts sobek.Value) (*sobek.Promise, error) {
11 changes: 3 additions & 8 deletions internal/js/modules/k6/browser/common/element_handle.go
Original file line number Diff line number Diff line change
@@ -1306,19 +1306,14 @@ func (h *ElementHandle) ScrollIntoViewIfNeeded(opts *ElementHandleBaseOptions) e
}

// SelectOption selects the options matching the given values.
func (h *ElementHandle) SelectOption(values []any, opts sobek.Value) ([]string, error) {
aopts := NewElementHandleBaseOptions(h.DefaultTimeout())
if err := aopts.Parse(h.ctx, opts); err != nil {
return nil, fmt.Errorf("parsing selectOption options: %w", err)
}

func (h *ElementHandle) SelectOption(values []any, opts *ElementHandleBaseOptions) ([]string, error) {
selectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
return handle.selectOption(apiCtx, values)
}
selectOptionAction := h.newAction(
[]string{}, selectOption, aopts.Force, aopts.NoWaitAfter, aopts.Timeout,
[]string{}, selectOption, opts.Force, opts.NoWaitAfter, opts.Timeout,
)
selectedOptions, err := call(h.ctx, selectOptionAction, aopts.Timeout)
selectedOptions, err := call(h.ctx, selectOptionAction, opts.Timeout)
if err != nil {
return nil, fmt.Errorf("selecting options: %w", err)
}