Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit acccfc6

Browse files
ankur22Ivan Mirić
andauthored
Fix press in classes to work with combo keys (#522)
* Fix press in classes to work with combo keys ElementHandle, Page, Locator and Frame all have the Press method. In a recent fix (#326) combo keys with the Shift modifier key was fixed for the Keyboard Press method. The Press methods for the other classes should have worked with combo ley presses, but didn't. This fix will ensure that combo key presses work for all of them. Closes: #521 * Apply suggestions from code review Co-authored-by: Ivan Mirić <ivan.miric@grafana.com> Co-authored-by: Ivan Mirić <ivan.miric@grafana.com>
1 parent 96be528 commit acccfc6

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

common/element_handle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func (h *ElementHandle) press(apiCtx context.Context, key string, opts *Keyboard
476476
if err != nil {
477477
return err
478478
}
479-
err = h.frame.page.Keyboard.press(key, opts)
479+
err = h.frame.page.Keyboard.comboPress(key, opts)
480480
if err != nil {
481481
return err
482482
}

tests/element_handle_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,19 @@ func TestElementHandleWaitForSelector(t *testing.T) {
359359

360360
element.Dispose()
361361
}
362+
363+
func TestElementHandlePress(t *testing.T) {
364+
tb := newTestBrowser(t)
365+
366+
p := tb.NewPage(nil)
367+
368+
p.SetContent(`<input>`, nil)
369+
370+
el := p.Query("input")
371+
372+
el.Press("Shift+KeyA", nil)
373+
el.Press("KeyB", nil)
374+
el.Press("Shift+KeyC", nil)
375+
376+
require.Equal(t, "AbC", el.InputValue(nil))
377+
}

tests/frame_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
)
8+
9+
func TestFramePress(t *testing.T) {
10+
tb := newTestBrowser(t)
11+
12+
p := tb.NewPage(nil)
13+
14+
p.SetContent(`<input id="text1">`, nil)
15+
16+
f := p.Frames()[0]
17+
18+
f.Press("#text1", "Shift+KeyA", nil)
19+
f.Press("#text1", "KeyB", nil)
20+
f.Press("#text1", "Shift+KeyC", nil)
21+
22+
require.Equal(t, "AbC", f.InputValue("#text1", nil))
23+
}

tests/locator_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,19 @@ func TestLocatorElementState(t *testing.T) {
370370
})
371371
}
372372
}
373+
374+
func TestLocatorPress(t *testing.T) {
375+
tb := newTestBrowser(t)
376+
377+
p := tb.NewPage(nil)
378+
379+
p.SetContent(`<input id="text1">`, nil)
380+
381+
l := p.Locator("#text1", nil)
382+
383+
l.Press("Shift+KeyA", nil)
384+
l.Press("KeyB", nil)
385+
l.Press("Shift+KeyC", nil)
386+
387+
require.Equal(t, "AbC", l.InputValue(nil))
388+
}

tests/page_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,20 @@ func TestPageWaitForNavigationShouldNotPanic(t *testing.T) {
684684
require.NotPanics(t, func() { p.WaitForNavigation(nil) })
685685
}
686686

687+
func TestPagePress(t *testing.T) {
688+
tb := newTestBrowser(t)
689+
690+
p := tb.NewPage(nil)
691+
692+
p.SetContent(`<input id="text1">`, nil)
693+
694+
p.Press("#text1", "Shift+KeyA", nil)
695+
p.Press("#text1", "KeyB", nil)
696+
p.Press("#text1", "Shift+KeyC", nil)
697+
698+
require.Equal(t, "AbC", p.InputValue("#text1", nil))
699+
}
700+
687701
func assertPanicErrorContains(t *testing.T, err interface{}, expErrMsg string) {
688702
t.Helper()
689703

0 commit comments

Comments
 (0)