我正在使用 Appium 进行 IOS 测试。 (java) 我希望能够检查应用程序的当前事件。从某种意义上说,当一个应用程序从可点击切换到另一个应用程序时(比如我关闭应用程序或切换到另一个应用程序或打开通知滚动。我希望能够检测页面名称。要获取当前事件名称,我使用驱动程序。 currentActivity(); 包含在 AndroidDriver 类中。
但是在ios中没有直接调用当前包,但是很多建议可以通过调用driver.getPageSource()查看设备屏幕中现有元素的属性来找出;我如何使用 driver.getPageSource 实现此目的,或者是否有任何其他方法可以做到这一点?对此的任何建议都会有所帮助。
最佳答案
你可以查询当前的应用状态,如果你有应用的bundleId那么你可以 如果它在后台或前台运行,请查询它的状态并解决您的问题。
Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.myapp");
final int state = (Integer)js.executeScript("mobile: queryAppState", params);
根据文档,可以有 5 种可能的状态。
0: The current application state cannot be determined/is unknown
1: The application is not running
2: The application is running in the background and is suspended
3: The application is running in the background and is not suspended
4: The application is running in the foreground
关于appium-ios - 如何在 ios 中查找应用程序的当前事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45048597/