fix: resolution calculation for iOS

This commit is contained in:
buyuxiang
2023-08-28 16:18:07 +08:00
parent c611a84aaa
commit afe304f58c
4 changed files with 14 additions and 13 deletions

View File

@@ -201,6 +201,12 @@ func (wd *wdaDriver) WindowSize() (size Size, err error) {
return Size{}, err
}
size = reply.Value.Size
scale, err := wd.Scale()
if err != nil {
return Size{}, errors.Wrap(err, "get window size failed when obtaining scale")
}
size.Height = size.Height * int(scale)
size.Width = size.Width * int(scale)
return
}

View File

@@ -357,8 +357,12 @@ type IImageService interface {
// GetScreenResult takes a screenshot, returns the image recognization result
func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *ScreenResult, err error) {
startTime := time.Now()
fileName := builtin.GenNameWithTimestamp("%d_screenshot")
actionOptions := NewActionOptions(options...)
fileName := builtin.GenNameWithTimestamp("%d_" + strings.Join(actionOptions.screenshotActions(), "_"))
screenshotActions := actionOptions.screenshotActions()
if len(screenshotActions) != 0 {
fileName = builtin.GenNameWithTimestamp("%d_" + strings.Join(screenshotActions, "_"))
}
bufSource, imagePath, err := dExt.takeScreenShot(fileName)
if err != nil {
return

View File

@@ -102,22 +102,17 @@ func TestClosePopup(t *testing.T) {
setupAndroid(t)
screenResult, err := driverExt.GetScreenResult(
WithScreenShotClose(true), WithScreenShotUpload(true))
WithScreenShotClosePopups(true), WithScreenShotUpload(true))
if err != nil {
t.Logf("get screen result failed for popup handler: %v", err)
return
}
t.Logf("screen result: %v", screenResult)
// 1. there are no popups here (fast return normally)
// 2. failed to close popup maybe tap error, return error
// 3. successful to close popup (sleep and wait for next retry if existed)
if screenResult.Popup == nil {
t.Log("there are no popups here")
return
}
t.Logf("popup info: %v", screenResult.Popup)
if err = driverExt.tapPopupHandler(screenResult.Popup); err != nil {

View File

@@ -15,12 +15,8 @@ func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error {
return fmt.Errorf("x, y percentage should be <= 1, got x=%v, y=%v", x, y)
}
scale, err := dExt.Driver.Scale()
if err != nil {
return fmt.Errorf("failed to get scale: %v", err)
}
x = x * float64(dExt.windowSize.Width) * scale
y = y * float64(dExt.windowSize.Height) * scale
x = x * float64(dExt.windowSize.Width)
y = y * float64(dExt.windowSize.Height)
return dExt.TapAbsXY(x, y, options...)
}