[website] internal/screentest: document eval keyword

8 views
Skip to first unread message

Jamal Carvalho (Gerrit)

unread,
Sep 23, 2022, 12:47:07 PM9/23/22
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Hyang-Ah Hana Kim, Gopher Robot, golang-co...@googlegroups.com

Jamal Carvalho submitted this change.

View Change


Approvals: Hyang-Ah Hana Kim: Looks good to me, approved Gopher Robot: TryBots succeeded Jamal Carvalho: Run TryBots
internal/screentest: update package docs

Documentated eval keyword which allows for running arbitrary JavaScript
snippets in the context of the page. Unexported response struct, not
intended for use outside of the package.

Change-Id: I34b570ad997f253b1a262836dd3f240e15366465
Reviewed-on: https://go-review.googlesource.com/c/website/+/432878
Reviewed-by: Hyang-Ah Hana Kim <hya...@gmail.com>
TryBot-Result: Gopher Robot <go...@golang.org>
Run-TryBot: Jamal Carvalho <ja...@golang.org>
---
M internal/screentest/screentest.go
1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/internal/screentest/screentest.go b/internal/screentest/screentest.go
index 868bcb5..0b0d4e9 100644
--- a/internal/screentest/screentest.go
+++ b/internal/screentest/screentest.go
@@ -88,6 +88,12 @@
//
// capture element header
//
+// Evaluate JavaScript snippets to hide elements or prepare the page in
+// some other way.
+//
+// eval 'document.querySelector(".selector").remove();'
+// eval 'window.scrollTo({top: 0});'
+//
// Chain capture commands to create multiple testcases for a single page.
//
// windowsize 1536x960
@@ -751,7 +757,7 @@
return &img, nil
}

-type Response struct {
+type response struct {
Status int
}

@@ -770,7 +776,7 @@
if tc.blockedURLs != nil {
tasks = append(tasks, network.SetBlockedURLS(tc.blockedURLs))
}
- var res Response
+ var res response
tasks = append(tasks,
getResponse(url, &res),
chromedp.EmulateViewport(int64(tc.viewportWidth), int64(tc.viewportHeight)),
@@ -886,7 +892,7 @@
}
}

-func getResponse(u string, res *Response) chromedp.ActionFunc {
+func getResponse(u string, res *response) chromedp.ActionFunc {
return func(ctx context.Context) error {
chromedp.ListenTarget(ctx, func(ev interface{}) {
// URL fragments are dropped in request targets so we must strip the fragment
@@ -909,7 +915,7 @@
}
}

-func checkResponse(tc *testcase, res *Response) chromedp.ActionFunc {
+func checkResponse(tc *testcase, res *response) chromedp.ActionFunc {
return func(context.Context) error {
if res.Status != tc.status {
fmt.Fprintf(&tc.output, "\nFAIL http status mismatch: got %d; want %d", res.Status, tc.status)

To view, visit change 432878. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: website
Gerrit-Branch: master
Gerrit-Change-Id: I34b570ad997f253b1a262836dd3f240e15366465
Gerrit-Change-Number: 432878
Gerrit-PatchSet: 4
Gerrit-Owner: Jamal Carvalho <ja...@golang.org>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Reviewer: Jamal Carvalho <ja...@golang.org>
Gerrit-MessageType: merged
Reply all
Reply to author
Forward
0 new messages