Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -357,7 +357,7 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping {
},

"pressSequentially": func(text string, opts sobek.Value) (*sobek.Promise, error) {
copts := common.NewFramePressOptions(lo.Timeout())
copts := common.NewFrameTypeOptions(lo.Timeout())
if err := copts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing locator press sequentially options: %w", err)
}
Expand Down
43 changes: 4 additions & 39 deletions internal/js/modules/k6/browser/common/locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,46 +534,11 @@ func (l *Locator) Press(key string, opts *FramePressOptions) error {

// PressSequentially focuses on the element and sequentially sends a keydown,
// keypress, and keyup events for each character in the provided string.
// For handling special keys, use the Locator.Press method.
func (l *Locator) PressSequentially(text string, opts *FramePressOptions) error {
l.log.Debugf(
"Locator:PressSequentially", "fid:%s furl:%q sel:%q text:%q opts:%+v",
l.frame.ID(), l.frame.URL(), l.selector, text, opts,
)
_, span := TraceAPICall(l.ctx, l.frame.page.targetID.String(), "locator.pressSequentially")
defer span.End()

opts.Strict = true

focusOpts := NewFrameBaseOptions(l.frame.defaultTimeout())
if opts.Timeout != 0 {
focusOpts.Timeout = opts.Timeout
}

if err := l.Focus(focusOpts); err != nil {
err := fmt.Errorf("focusing before typing: %w", err)
spanRecordError(span, err)
return err
}

for i, char := range text {
select {
case <-l.ctx.Done():
err := fmt.Errorf("cancelled at char %d/%d: %w", i+1, len(text), l.ctx.Err())
spanRecordError(span, err)
return err
default:
}

if err := l.frame.press(l.selector, string(char), opts); err != nil {
err := fmt.Errorf("pressing %q at %d/%d: %w", char, i+1, len(text), err)
spanRecordError(span, err)
return err
}

applySlowMo(l.ctx)
// For handling special keys, use the [Locator.Press] method.
func (l *Locator) PressSequentially(text string, opts *FrameTypeOptions) error {
if err := l.Type(text, opts); err != nil {
return fmt.Errorf("pressing sequentially %q on %q: %w", text, l.selector, err)
}
time.Sleep(200 * time.Millisecond)
return nil
}

Expand Down
11 changes: 4 additions & 7 deletions internal/js/modules/k6/browser/tests/locator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ func TestLocator(t *testing.T) {
lo := p.Locator("#inputText", nil)
require.NoError(t, lo.Clear(common.NewFrameFillOptions(lo.Timeout())))

opts := common.NewFramePressOptions(lo.Timeout())
require.NoError(t, lo.PressSequentially("hello", opts))
require.NoError(t, lo.PressSequentially("hello", common.NewFrameTypeOptions(lo.Timeout())))

value, err := p.InputValue("#inputText", common.NewFrameInputValueOptions(p.MainFrame().Timeout()))
require.NoError(t, err)
Expand All @@ -311,7 +310,7 @@ func TestLocator(t *testing.T) {
lo := p.Locator("#inputText", nil)
require.NoError(t, lo.Clear(common.NewFrameFillOptions(lo.Timeout())))

opts := common.NewFramePressOptions(lo.Timeout())
opts := common.NewFrameTypeOptions(lo.Timeout())
opts.Delay = 100

require.NoError(t, lo.PressSequentially("text", opts))
Expand All @@ -326,8 +325,7 @@ func TestLocator(t *testing.T) {
lo := p.Locator("textarea", nil)
require.NoError(t, lo.Clear(common.NewFrameFillOptions(lo.Timeout())))

opts := common.NewFramePressOptions(lo.Timeout())
require.NoError(t, lo.PressSequentially("some text", opts))
require.NoError(t, lo.PressSequentially("some text", common.NewFrameTypeOptions(lo.Timeout())))

value, err := lo.InputValue(common.NewFrameInputValueOptions(lo.Timeout()))
require.NoError(t, err)
Expand Down Expand Up @@ -511,8 +509,7 @@ func TestLocator(t *testing.T) {
},
{
"PressSequentially", func(l *common.Locator, tb *testBrowser) error {
opts := common.NewFramePressOptions(100 * time.Millisecond)
return l.PressSequentially("text", opts)
return l.PressSequentially("text", common.NewFrameTypeOptions(100*time.Millisecond))
},
},
{
Expand Down
Loading