Files
httprunner/hrp/pkg/uixt/android_layout.go
余泓铮 3b4367cac4 Feat/yuhongzheng/pre auto install
* fix: fix rotate tap swipe error
* fix: default input frequency from 60 to 10
* fix: error getting window size during screen rotation
* fix: kuake input unicode error
* feat: android input by appium ime
* feat: android swipe and tap with duration
* fix: format import file
* fix: format import file
* feat: 新增按控件点击,获取设备应用,修改日志获取
* feat: 新增ui2控件点击
* fix: format file
* fix: format file
* Merge branch 'video-release' into 'feat/yuhongzheng/pre_auto_install'
* merge
* Merge branch 'feat/yuhongzheng/pre_auto_install' of…
* fix: close reader
* Merge branch 'video-release' into 'feat/yuhongzheng/pre_auto_install'
* fix: format code
* Merge branch 'feat/yuhongzheng/pre_auto_install' of…
* fix: test send key

https://code.byted.org/iesqa/httprunner/merge_requests/34
2024-05-10 07:02:41 +00:00

63 lines
1.6 KiB
Go

package uixt
import (
"encoding/xml"
"fmt"
"regexp"
"strconv"
)
type Attributes struct {
Index int `xml:"index,attr"`
Package string `xml:"package,attr"`
Class string `xml:"class,attr"`
Text string `xml:"text,attr"`
ResourceId string `xml:"resource-id,attr"`
Checkable bool `xml:"checkable,attr"`
Checked bool `xml:"checked,attr"`
Clickable bool `xml:"clickable,attr"`
Enabled bool `xml:"enabled,attr"`
Focusable bool `xml:"focusable,attr"`
Focused bool `xml:"focused,attr"`
LongClickable bool `xml:"long-clickable,attr"`
Password bool `xml:"password,attr"`
Scrollable bool `xml:"scrollable,attr"`
Selected bool `xml:"selected,attr"`
Bounds *Bounds `xml:"bounds,attr"`
Displayed bool `xml:"displayed,attr"`
}
type Hierarchy struct {
XMLName xml.Name `xml:"hierarchy"`
Attributes
Layout []Layout `xml:",any"`
}
type Layout struct {
Attributes
Layout []Layout `xml:",any"`
}
type Bounds struct {
X1, Y1, X2, Y2 int
}
func (b *Bounds) Center() (float64, float64) {
return float64(b.X1+b.X2) / 2, float64(b.Y1+b.Y2) / 2
}
func (b *Bounds) UnmarshalXMLAttr(attr xml.Attr) error {
// 正则表达式用于解析格式为"[x1,y1][x2,y2]"
re := regexp.MustCompile(`\[(\d+),(\d+)]\[(\d+),(\d+)]`)
matches := re.FindStringSubmatch(attr.Value)
if matches == nil {
return fmt.Errorf("bounds format is incorrect")
}
// 转换字符串为整数
b.X1, _ = strconv.Atoi(matches[1])
b.Y1, _ = strconv.Atoi(matches[2])
b.X2, _ = strconv.Atoi(matches[3])
b.Y2, _ = strconv.Atoi(matches[4])
return nil
}