如何使用appium查找哪个应用程序在前台

How to find which app is in foreground with appium

我正在使用 python 和 appium 自动化移动应用程序,我们必须在其中启动地图应用程序(Google 地图和 Apple 地图)。

有什么方法可以通过 Appium 知道前台当前活动的应用程序是什么?

我可以使用 Android 的 shell 命令来完成。但是,如何验证 Apple 地图是否已启动?

我找到了 android here

的答案
self.driver.current_activity

对于 iOS,我最终对在我的被测应用程序 (AUT) 中查找元素进行了否定验证。因此,我要确保我的 AUT 中的某些独特元素在屏幕上不可见。

对于iOS,您可以使用self.driver.session['CFBundleIdentifier']:

def close_and_open_app(self):
    package_name = self.driver.session['CFBundleIdentifier']
    self.driver.terminate_app(package_name)
    self.driver.activate_app(package_name)