From c1f0275c320fe842e769f1e759085665c9bf6769 Mon Sep 17 00:00:00 2001 From: electricbubble Date: Sun, 20 Feb 2022 01:15:41 +0800 Subject: [PATCH] feat: support to provide a scope for the XML page source > https://github.com/appium/WebDriverAgent/pull/544 --- driver.go | 10 ++++------ driver_test.go | 33 ++++++++++++++++++++++++++++++++- gwda.go | 10 ++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/driver.go b/driver.go index fcc56b8..1727edf 100644 --- a/driver.go +++ b/driver.go @@ -803,15 +803,13 @@ func (wd *remoteWD) Source(srcOpt ...SourceOption) (source string, err error) { toJsonRaw := false if len(srcOpt) != 0 { q := tmp.Query() - if vFormat, ok := srcOpt[0]["format"]; ok { - q.Set("format", vFormat.(string)) - if vFormat.(string) == "json" { + for k, val := range srcOpt[0] { + v := val.(string) + q.Set(k, v) + if k == "format" && v == "json" { toJsonRaw = true } } - if vAttr, ok := srcOpt[0]["excluded_attributes"]; ok { - q.Set("excluded_attributes", vAttr.(string)) - } tmp.RawQuery = q.Encode() } diff --git a/driver_test.go b/driver_test.go index e3cf8a6..6a234ba 100644 --- a/driver_test.go +++ b/driver_test.go @@ -19,6 +19,28 @@ func setup(t *testing.T) { } } +func TestViaUSB(t *testing.T) { + devices, err := DeviceList() + if err != nil { + t.Fatal(err) + } + + drivers := make([]WebDriver, 0, len(devices)) + + for _, dev := range devices { + d, err := NewUSBDriver(nil, dev) + if err != nil { + t.Errorf("%s: %s", dev.SerialNumber(), err) + continue + } + drivers = append(drivers, d) + } + + for _, d := range drivers { + t.Log(d.Status()) + } +} + func TestNewDriver(t *testing.T) { var err error driver, err = NewDriver(nil, urlPrefix) @@ -144,6 +166,8 @@ func Test_remoteWD_Status(t *testing.T) { func Test_remoteWD_DeviceInfo(t *testing.T) { setup(t) + SetDebug(true) + info, err := driver.DeviceInfo() if err != nil { t.Fatal(err) @@ -668,7 +692,14 @@ func Test_remoteWD_Source(t *testing.T) { var source string var err error - source, err = driver.Source() + SetDebug(true) + + // source, err = driver.Source() + // if err != nil { + // t.Fatal(err) + // } + + source, err = driver.Source(NewSourceOption().WithScope("AppiumAUT")) if err != nil { t.Fatal(err) } diff --git a/gwda.go b/gwda.go index 067a539..9e300c4 100644 --- a/gwda.go +++ b/gwda.go @@ -566,6 +566,16 @@ func (opt SourceOption) WithFormatAsDescription() SourceOption { return opt } +// WithScope Allows to provide XML scope. +// only `xml` is supported. +func (opt SourceOption) WithScope(scope string) SourceOption { + if vFormat, ok := opt["format"]; ok && vFormat != "xml" { + return opt + } + opt["scope"] = scope + return opt +} + // WithExcludedAttributes Excludes the given attribute names. // only `xml` is supported. func (opt SourceOption) WithExcludedAttributes(attributes []string) SourceOption {