mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
feat: add AssertForegroundApp for ios
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0+2411232055
|
v5.0.0+2411232149
|
||||||
|
|||||||
@@ -457,10 +457,11 @@ func (wd *wdaDriver) GetForegroundApp() (appInfo AppInfo, err error) {
|
|||||||
}
|
}
|
||||||
for _, app := range apps {
|
for _, app := range apps {
|
||||||
if app.CFBundleIdentifier == activeAppInfo.BundleId {
|
if app.CFBundleIdentifier == activeAppInfo.BundleId {
|
||||||
appInfo.BundleId = app.CFBundleIdentifier
|
appInfo.Name = app.CFBundleDisplayName
|
||||||
appInfo.AppName = app.CFBundleName
|
appInfo.AppName = app.CFBundleName
|
||||||
appInfo.VersionName = app.CFBundleShortVersionString
|
appInfo.BundleId = app.CFBundleIdentifier
|
||||||
appInfo.PackageName = app.CFBundleIdentifier
|
appInfo.PackageName = app.CFBundleIdentifier
|
||||||
|
appInfo.VersionName = app.CFBundleShortVersionString
|
||||||
versionCode, err := strconv.Atoi(app.CFBundleVersion)
|
versionCode, err := strconv.Atoi(app.CFBundleVersion)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
appInfo.VersionCode = versionCode
|
appInfo.VersionCode = versionCode
|
||||||
@@ -472,9 +473,25 @@ func (wd *wdaDriver) GetForegroundApp() (appInfo AppInfo, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) AssertForegroundApp(bundleId string, viewControllerType ...string) error {
|
func (wd *wdaDriver) AssertForegroundApp(bundleId string, viewControllerType ...string) error {
|
||||||
log.Warn().Str("bundleId", bundleId).
|
log.Debug().Str("bundleId", bundleId).
|
||||||
Strs("viewControllerType", viewControllerType).
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func newStubIOSDriver(bightInsightAddr, serverAddr string, dev *IOSDevice, readT
|
|||||||
driver.serverPrefix = serverAddr
|
driver.serverPrefix = serverAddr
|
||||||
driver.timeout = timeout
|
driver.timeout = timeout
|
||||||
driver.Driver.client = &http.Client{
|
driver.Driver.client = &http.Client{
|
||||||
Timeout: time.Second * 20, // 设置超时时间为 10 秒
|
Timeout: time.Second * 10, // 设置超时时间为 10 秒
|
||||||
}
|
}
|
||||||
return driver, nil
|
return driver, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -435,6 +435,15 @@ func Test_remoteWD_Source(t *testing.T) {
|
|||||||
fmt.Println(source)
|
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) {
|
func Test_remoteWD_AccessibleSource(t *testing.T) {
|
||||||
setup(t)
|
setup(t)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user