diff --git a/browser/mapping_test.go b/browser/mapping_test.go index 12a65d317..86443e84a 100644 --- a/browser/mapping_test.go +++ b/browser/mapping_test.go @@ -509,7 +509,7 @@ type locatorAPI interface { IsDisabled(opts goja.Value) (bool, error) IsVisible(opts goja.Value) (bool, error) IsHidden(opts goja.Value) (bool, error) - Fill(value string, opts goja.Value) + Fill(value string, opts goja.Value) error Focus(opts goja.Value) GetAttribute(name string, opts goja.Value) goja.Value InnerHTML(opts goja.Value) string diff --git a/common/locator.go b/common/locator.go index 0a54188cf..646f24497 100644 --- a/common/locator.go +++ b/common/locator.go @@ -276,24 +276,23 @@ func (l *Locator) IsHidden() (bool, error) { } // Fill out the element using locator's selector with strict mode on. -func (l *Locator) Fill(value string, opts goja.Value) { +func (l *Locator) Fill(value string, opts goja.Value) error { l.log.Debugf( "Locator:Fill", "fid:%s furl:%q sel:%q val:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, value, opts, ) - var err error - defer func() { panicOrSlowMo(l.ctx, err) }() - copts := NewFrameFillOptions(l.frame.defaultTimeout()) - if err = copts.Parse(l.ctx, opts); err != nil { - err = fmt.Errorf("parsing fill options: %w", err) - return + if err := copts.Parse(l.ctx, opts); err != nil { + return fmt.Errorf("parsing fill options: %w", err) } - if err = l.fill(value, copts); err != nil { - err = fmt.Errorf("filling %q with %q: %w", l.selector, value, err) - return + if err := l.fill(value, copts); err != nil { + return fmt.Errorf("filling %q with %q: %w", l.selector, value, err) } + + applySlowMo(l.ctx) + + return nil } func (l *Locator) fill(value string, opts *FrameFillOptions) error { diff --git a/tests/locator_test.go b/tests/locator_test.go index efd95b9eb..663e7c60d 100644 --- a/tests/locator_test.go +++ b/tests/locator_test.go @@ -60,11 +60,11 @@ func TestLocator(t *testing.T) { }, }, { - "Clear", func(tb *testBrowser, p *common.Page) { + "Clear", func(_ *testBrowser, p *common.Page) { const value = "fill me up" l := p.Locator("#inputText", nil) - l.Fill(value, nil) + require.NoError(t, l.Fill(value, nil)) require.Equal(t, value, p.InputValue("#inputText", nil)) err := l.Clear(common.NewFrameFillOptions(l.Timeout())) @@ -104,26 +104,29 @@ func TestLocator(t *testing.T) { }, }, { - "Fill", func(tb *testBrowser, p *common.Page) { + "Fill", func(_ *testBrowser, p *common.Page) { const value = "fill me up" - p.Locator("#inputText", nil).Fill(value, nil) + lo := p.Locator("#inputText", nil) + require.NoError(t, lo.Fill(value, nil)) require.Equal(t, value, p.InputValue("#inputText", nil)) }, }, { - "FillTextarea", func(tb *testBrowser, p *common.Page) { + "FillTextarea", func(_ *testBrowser, p *common.Page) { const value = "fill me up" - p.Locator("textarea", nil).Fill(value, nil) + lo := p.Locator("textarea", nil) + require.NoError(t, lo.Fill(value, nil)) require.Equal(t, value, p.InputValue("textarea", nil)) }, }, { - "FillParagraph", func(tb *testBrowser, p *common.Page) { + "FillParagraph", func(_ *testBrowser, p *common.Page) { const value = "fill me up" - p.Locator("#firstParagraph", nil).Fill(value, nil) + lo := p.Locator("#firstParagraph", nil) + require.NoError(t, lo.Fill(value, nil)) require.Equal(t, value, p.TextContent("#firstParagraph", nil)) - l := p.Locator("#secondParagraph", nil) - assert.Panics(t, func() { l.Fill(value, nil) }, "should panic") + lo = p.Locator("#secondParagraph", nil) + require.Error(t, lo.Fill(value, nil)) }, }, { @@ -327,7 +330,12 @@ func TestLocator(t *testing.T) { "Focus", func(l *common.Locator, tb *testBrowser) { l.Focus(timeout(tb)) }, }, { - "Fill", func(l *common.Locator, tb *testBrowser) { l.Fill("fill me up", timeout(tb)) }, + "Fill", func(l *common.Locator, tb *testBrowser) { + if err := l.Fill("fill me up", timeout(tb)); err != nil { + // TODO: remove panic and update tests when all locator methods return error. + panic(err) + } + }, }, { "GetAttribute", func(l *common.Locator, tb *testBrowser) { l.GetAttribute("value", timeout(tb)) },