Skip to content

Commit

Permalink
feat: support to provide a scope for the XML page source
Browse files Browse the repository at this point in the history
  • Loading branch information
electricbubble committed Feb 19, 2022
1 parent c62f304 commit c1f0275
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
10 changes: 4 additions & 6 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
33 changes: 32 additions & 1 deletion driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions gwda.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c1f0275

Please sign in to comment.