iOS UI 自动化 - iOS UIAutomation:切换应用程序



我正在尝试使用 UI 自动化来测试切换应用程序时从UIPasteboard写入和读取。但是,切换到第二个应用后脚本挂起。我正在尝试使测试进入睡眠状态以防止它挂起。我尝试使用 waitForInvalidpushTimeout/popTimeout和两种方法似乎都不起作用,并且在第二个应用程序中logElementTree之前测试仍然挂起。

这是我使用 waitForInvalid 的 UI 自动化脚本。("粘贴板共享"按钮是启动第二个应用程序的地方):

var target = UIATarget.localTarget();
target.frontMostApp().mainWindow().segmentedControls()[0].buttons()["1MB"].tap();
target.frontMostApp().mainWindow().buttons()["Pasteboard Sharing"].tap();
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Paste & Go"]
    .tap();
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Paste & Go"]
    .waitForInvalid();
target.frontMostApp().mainWindow().logElementTree();

这是使用 pushTimeout/popTimeout 的脚本:

var target = UIATarget.localTarget();
target.frontMostApp().mainWindow().segmentedControls()[0].buttons()["1MB"].tap();
target.frontMostApp().mainWindow().buttons()["Pasteboard Sharing"].tap();
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Paste & Go"]
    .tap();
UIATarget.localTarget().pushTimeout(10);
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Check Pasteboard"]
    .withValueForKey(1, "isVisible");
UIATarget.localTarget().popTimeout();
target.frontMostApp().mainWindow().logElementTree();

如果我理解正确,您希望使用相同的脚本来测试两个应用程序。但是,如果您只使用 UIA,这是不可能的。使用 UIAutomation,您只能将一个应用作为目标。因此,切换到另一个应用程序只会"挂起",因为目标应用程序在后台。我在某处读到您可以使用 Appium https://github.com/appium/appium 在两个应用程序之间进行交互,但我自己还没有使用它。

相关内容

最新更新