From 8bec76b36aa5a7005291865137f8da56923415db Mon Sep 17 00:00:00 2001 From: mtrea <32470080+mtrea@users.noreply.github.com> Date: Mon, 9 Mar 2020 09:56:09 -0700 Subject: [PATCH 1/4] Upgrade debugger to Python 3. (#410) --- testing/web/debugger/debugger.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testing/web/debugger/debugger.py b/testing/web/debugger/debugger.py index 2ce35492..41f0fa0e 100644 --- a/testing/web/debugger/debugger.py +++ b/testing/web/debugger/debugger.py @@ -13,13 +13,16 @@ # limitations under the License. """Web Test Launcher Debugger Front-End.""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function import code import getpass import hashlib import json import socket import sys -import urllib +from six.moves import urllib class Debugger: @@ -135,7 +138,7 @@ def delete_breakpoint(self, breakpoint_id): def collect_analytics(): try: - urllib.urlopen( + urllib.request.urlopen( "http://www.google-analytics.com/collect?v=1&aip=1&tid=UA-52159295-3" "&t=screenview&cd=start&an=WTL+Debugger&uid=" + hashlib.md5(getpass.getuser()).hexdigest()).close From ec4a41098c4b3e529458b65765969f50f97dddff Mon Sep 17 00:00:00 2001 From: GIT Date: Sat, 1 Aug 2020 02:04:40 +0530 Subject: [PATCH 2/4] Use --no-sandbox for chromium-local --- browsers/chromium-local.json | 1 + 1 file changed, 1 insertion(+) diff --git a/browsers/chromium-local.json b/browsers/chromium-local.json index 7fb23d34..9c989df4 100644 --- a/browsers/chromium-local.json +++ b/browsers/chromium-local.json @@ -6,6 +6,7 @@ "binary" : "%FILE:CHROMIUM%", "args" : [ "--headless", + "--no-sandbox", "--use-gl=swiftshader-webgl" ] }, From 83283f5e5b422f5a96b76c5680e17627d1691689 Mon Sep 17 00:00:00 2001 From: GIT Date: Sat, 1 Aug 2020 02:07:22 +0530 Subject: [PATCH 3/4] OlderVersionsAreNotrunningFirefoxTest (#412) * OlderVersionsAreNotrunningFirefoxTest Older version of firefox are failing. * Update browsers-0.3.2.bzl * Update browsers-0.3.2.bzl * Update browsers-0.3.2.bzl Co-authored-by: mtrea <32470080+mtrea@users.noreply.github.com> --- web/versioned/browsers-0.3.2.bzl | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/web/versioned/browsers-0.3.2.bzl b/web/versioned/browsers-0.3.2.bzl index e8b8c723..47f6e884 100644 --- a/web/versioned/browsers-0.3.2.bzl +++ b/web/versioned/browsers-0.3.2.bzl @@ -56,40 +56,39 @@ def org_chromium_chromedriver(): name = "org_chromium_chromedriver", licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT amd64_sha256 = - "0ead02145854b60a3317b59031205b362fb4cfdb680fef20e95c89582e6e38be", + "f6b9852031d185739a2c1816508fe8158eb92782d13e831b8345957ef2506fe8", amd64_urls = [ - "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/664981/chromedriver_linux64.zip", + "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/768968/chromedriver_linux64.zip", ], macos_sha256 = - "8dd159e27b13b16262afa6993b15321e736c3b484da363c0e03bb050d72522c9", + "aa0124085146556d5d32ad172670e5dcef79b7429380112ad02898047ba7a8b7", macos_urls = [ - "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/665002/chromedriver_mac64.zip", + "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/768968/chromedriver_mac64.zip", ], windows_sha256 = - "1cc881364974102182257a5c5c2b9cfed513689dee28924ca44df082bdf9fd60", + "cb19c5b53efc65be6f79421df0c9a226603b09cc959bc47991552c8820516588", windows_urls = [ - "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/664999/chromedriver_win32.zip", + "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/776896/chromedriver_win32.zip", ], ) - def org_chromium_chromium(): platform_http_file( name = "org_chromium_chromium", licenses = ["notice"], # BSD 3-clause (maybe more?) amd64_sha256 = - "b1e30c4dec8a451f8fe10d1f2d3c71e491d0333425f32247fe5c80a0a354303d", + "0e303931d9c3e065a160f5d31f1178c647f0748fb0b58b1945b84b04fe1c1165", amd64_urls = [ - "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/664981/chrome-linux.zip", + "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/768968/chrome-linux.zip", ], macos_sha256 = - "7c0ba93616f44a421330b1c1262e8899fbdf7916bed8b04c775e0426f6f35ec6", + "39118c96db1b3fdb0129f434912a329c5ca07d3a1c6c6cda673d3383d83e2f9a", macos_urls = [ - "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/665002/chrome-mac.zip", + "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/768968/chrome-mac.zip", ], windows_sha256 = - "f2facd0066270078d0e8999e684595274c359cac3946299a1ceedba2a5de1c63", + "08c6b7ec05cd8f172c2fe9d29ce26e3af9fdf4d04f76b5dd53d0236df0396377", windows_urls = [ - "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/664999/chrome-win.zip", + "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/776896/chrome-win.zip", ], ) @@ -119,8 +118,8 @@ def org_mozilla_geckodriver(): "https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz", ], macos_sha256 = - "6553195cd6f449e2b90b0bdfe174c6c3337ed571ac6d57a0db028ac5f306cca9", + "4739ef8f8af5d89bd4a8015788b4dc45c2f5f16b2fdc001254c9a92fe7261947", macos_urls = [ - "https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-macos.tar.gz", + "https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-macos.tar.gz", ], ) From 06023bb308158d88c8a0c4bbdbbb59ab751a35ef Mon Sep 17 00:00:00 2001 From: mtrea <32470080+mtrea@users.noreply.github.com> Date: Thu, 15 Oct 2020 18:17:15 -0700 Subject: [PATCH 4/4] Add new WebDriver methods, better arg merging and error logging (#414) * Add ElementGetText and ElementSendKeys. * Accommodate single-hyphen args, too. args in moz:firefoxOptions use the "-" prefix, compared to args in "goog:chromeOptions" using the "--" prefix. * Detail error origin when launching a driver. --- go/metadata/capabilities/capabilities.go | 7 +++-- go/metadata/capabilities/capabilities_test.go | 29 +++++++++++++++++-- go/webdriver/webdriver.go | 21 ++++++++++++++ go/wsl/hub/hub.go | 4 +-- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/go/metadata/capabilities/capabilities.go b/go/metadata/capabilities/capabilities.go index 63c9d17e..a24d991d 100644 --- a/go/metadata/capabilities/capabilities.go +++ b/go/metadata/capabilities/capabilities.go @@ -720,6 +720,9 @@ func mergeLists(m1, m2 []interface{}) []interface{} { return nl } +// The mergeArgs function merges m1 and m2. For same argument exists in m1 and m2 and has +// prefix "--" or "-", the argument in m2 will override m1; If the same argument does not +// have prefix "--" or "-", then both same arguments in m1 and m2 will remain. func mergeArgs(m1, m2 []interface{}) []interface{} { m2Opts := map[string]bool{} @@ -730,7 +733,7 @@ func mergeArgs(m1, m2 []interface{}) []interface{} { m2Opts[arg[7:]] = true continue // And leave arg out of m2Copy } - if strings.HasPrefix(arg, "--") { + if strings.HasPrefix(arg, "-") { tokens := strings.Split(arg, "=") m2Opts[tokens[0]] = true } @@ -742,7 +745,7 @@ func mergeArgs(m1, m2 []interface{}) []interface{} { for _, a := range m1 { if arg, ok := a.(string); ok { - if strings.HasPrefix(arg, "--") { + if strings.HasPrefix(arg, "-") { tokens := strings.Split(arg, "=") // Skip options from m1 that are redefined in m2 if m2Opts[tokens[0]] { diff --git a/go/metadata/capabilities/capabilities_test.go b/go/metadata/capabilities/capabilities_test.go index 32677a54..e5322153 100644 --- a/go/metadata/capabilities/capabilities_test.go +++ b/go/metadata/capabilities/capabilities_test.go @@ -435,7 +435,6 @@ func TestMerge(t *testing.T) { "an option", "--anOption", "--anOption=true", - "-anotherOption", map[string]interface{}{ "some": "map", }, @@ -450,7 +449,7 @@ func TestMerge(t *testing.T) { }, }, { - name: "args -- redefines", + name: "overrides '--' prefixed args", input1: map[string]interface{}{ "args": []interface{}{ "an option", @@ -531,6 +530,31 @@ func TestMerge(t *testing.T) { }, }, }, + { + name: "overrides '-' prefixed args", + input1: map[string]interface{}{ + "args": []interface{}{ + "option", + "--anOption", + "-width=1024", + }, + }, + input2: map[string]interface{}{ + "args": []interface{}{ + "option", + "--anOption", + "-width=2048", + }, + }, + result: map[string]interface{}{ + "args": []interface{}{ + "option", + "option", + "--anOption", + "-width=2048", + }, + }, + }, { name: "chromeOptions to goog:chromeOptions", input1: map[string]interface{}{ @@ -1600,3 +1624,4 @@ func TestMergeUnder(t *testing.T) { }) } } + diff --git a/go/webdriver/webdriver.go b/go/webdriver/webdriver.go index 0a91cfd4..a1d9be58 100644 --- a/go/webdriver/webdriver.go +++ b/go/webdriver/webdriver.go @@ -72,6 +72,10 @@ type WebDriver interface { Screenshot(context.Context) (image.Image, error) // ElementScreenshot takes a screenshot of the visible region encompassed by the bounding rectangle of element. ElementScreenshot(ctx context.Context, el WebElement) (image.Image, error) + // ElementGetText gets the text of an element. + ElementGetText(ctx context.Context, el WebElement) (string, error) + // ElementSendKeys sends keys to the element. + ElementSendKeys(ctx context.Context, el WebElement, keys string) error // WindowHandles returns a slice of the current window handles. WindowHandles(context.Context) ([]string, error) // CurrentWindowHandle returns the handle of the active window. @@ -393,6 +397,23 @@ func (d *webDriver) ElementScreenshot(ctx context.Context, el WebElement) (image return png.Decode(base64.NewDecoder(base64.StdEncoding, strings.NewReader(value))) } +// ElementGetText gets the text of an element. +func (d *webDriver) ElementGetText(ctx context.Context, el WebElement) (string, error) { + var value string + if err := d.get(ctx, fmt.Sprintf("element/%s/text", el.ID()), &value); err != nil { + return "", err + } + return value, nil +} + +// ElementSendKeys sends keys to an element. +func (d *webDriver) ElementSendKeys(ctx context.Context, el WebElement, keys string) error { + if err := d.post(ctx, fmt.Sprintf("element/%s/value", el.ID()), map[string]string{"text": keys}, nil); err != nil { + return err + } + return nil +} + // WindowHandles returns a slice of the current window handles. func (d *webDriver) WindowHandles(ctx context.Context) ([]string, error) { var value []string diff --git a/go/wsl/hub/hub.go b/go/wsl/hub/hub.go index 55c4f225..1764ec62 100644 --- a/go/wsl/hub/hub.go +++ b/go/wsl/hub/hub.go @@ -155,7 +155,7 @@ func (h *Hub) newSessionFromCaps(ctx context.Context, caps *capabilities.Capabil if err := resolver.RecyclePorts(); err != nil { log.Printf("Error recycling ports: %v", err) } - return "", nil, err + return "", nil, fmt.Errorf("Error launching driver binary: %w", err) } s, err := d.NewSession(ctx, caps, w) @@ -165,7 +165,7 @@ func (h *Hub) newSessionFromCaps(ctx context.Context, caps *capabilities.Capabil if err := d.Shutdown(ctx); err != nil { log.Printf("Error shutting down driver: %v", err) } - return "", nil, err + return "", nil, fmt.Errorf("Error requesting new session: %w", err) } return s, d, nil