cmd/gogio: add clicks to the e2e tests

The test app now responds to mouse clicks; clicking on one of the four
sections of the app flips it to red color until clicked again.

Add a Click method to the TestDriver interface, and implement it in both
of the current drivers. Unfortunately, I failed at implementing it in
X11 with the xdg library, after a few wasted hours. Instead, start
relying on more external tools which are simple to use and not heavy to
install.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
Daniel Martí
2019-11-01 20:57:34 +00:00
committed by Elias Naur
parent 5b948ceece
commit 41402ce524
4 changed files with 153 additions and 71 deletions
+13
View File
@@ -15,6 +15,7 @@ import (
"os/exec"
"strings"
"testing"
"time"
"github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp"
@@ -118,6 +119,8 @@ func (d *JSTestDriver) Start(t_ *testing.T, path string, width, height int) (cle
); err != nil {
d.t.Fatal(err)
}
// TODO(mvdan): synchronize with the app instead
time.Sleep(200 * time.Millisecond)
return cleanups
}
@@ -136,6 +139,16 @@ func (d *JSTestDriver) Screenshot() image.Image {
return img
}
func (d *JSTestDriver) Click(x, y int) {
if err := chromedp.Run(d.ctx,
chromedp.MouseClickXY(float64(x), float64(y)),
); err != nil {
d.t.Fatal(err)
}
// TODO(mvdan): synchronize with the app instead
time.Sleep(200 * time.Millisecond)
}
func TestJS(t *testing.T) {
t.Parallel()