feat: add AssertForegroundApp for ios

This commit is contained in:
lilong.129
2024-11-23 21:24:33 +08:00
parent ec508012a9
commit 270180603c
4 changed files with 32 additions and 6 deletions

View File

@@ -1 +1 @@
v5.0.0+2411232055
v5.0.0+2411232149

View File

@@ -457,10 +457,11 @@ func (wd *wdaDriver) GetForegroundApp() (appInfo AppInfo, err error) {
}
for _, app := range apps {
if app.CFBundleIdentifier == activeAppInfo.BundleId {
appInfo.BundleId = app.CFBundleIdentifier
appInfo.Name = app.CFBundleDisplayName
appInfo.AppName = app.CFBundleName
appInfo.VersionName = app.CFBundleShortVersionString
appInfo.BundleId = app.CFBundleIdentifier
appInfo.PackageName = app.CFBundleIdentifier
appInfo.VersionName = app.CFBundleShortVersionString
versionCode, err := strconv.Atoi(app.CFBundleVersion)
if err == nil {
appInfo.VersionCode = versionCode
@@ -472,9 +473,25 @@ func (wd *wdaDriver) GetForegroundApp() (appInfo AppInfo, err error) {
}
func (wd *wdaDriver) AssertForegroundApp(bundleId string, viewControllerType ...string) error {
log.Warn().Str("bundleId", bundleId).
log.Debug().Str("bundleId", bundleId).
Strs("viewControllerType", viewControllerType).
Msg("ios view controller assertion not implemented, skip")
Msg("assert ios foreground bundleId")
app, err := wd.GetForegroundApp()
if err != nil {
log.Warn().Err(err).Msg("get foreground app failed, skip bundleId assertion")
return nil // Notice: ignore error when get foreground app failed
}
// assert package
if app.BundleId != bundleId {
log.Error().
Interface("foreground_app", app.AppBaseInfo).
Str("expected_package", bundleId).
Msg("assert package failed")
return errors.Wrap(code.MobileUIAssertForegroundAppError,
"assert foreground package failed")
}
return nil
}

View File

@@ -30,7 +30,7 @@ func newStubIOSDriver(bightInsightAddr, serverAddr string, dev *IOSDevice, readT
driver.serverPrefix = serverAddr
driver.timeout = timeout
driver.Driver.client = &http.Client{
Timeout: time.Second * 20, // 设置超时时间为 10 秒
Timeout: time.Second * 10, // 设置超时时间为 10 秒
}
return driver, nil
}

View File

@@ -435,6 +435,15 @@ func Test_remoteWD_Source(t *testing.T) {
fmt.Println(source)
}
func TestGetForegroundApp(t *testing.T) {
setup(t)
app, err := driver.GetForegroundApp()
if err != nil {
t.Fatal(err)
}
t.Log(app)
}
func Test_remoteWD_AccessibleSource(t *testing.T) {
setup(t)