如何使用 XCUITEST 定位应用内购买抽屉元素?
我正在尝试使用沙箱帐户为我们应用程序的 IAP 编写 UI 测试。但是,当尝试点击此购买按钮时,测试无法找到此元素:应用内屏幕截图-购买提示
我尝试通过按钮名称和标签名称来定位此元素,但没有成功。在 UI 录制期间,当点击此按钮时,Xcode 完全冻结,我被迫关闭 Xcode。我还尝试在此步骤进行调试,当我在控制台中打印出“app.debugDescription”时,会返回此按钮或此购买抽屉中的任何其他元素。
失败的代码行: app.buttons["Purchase"].tap()
错误消息: 未找到匹配谓词“Purchase”IN 标识符'的元素
Xcode 版本:13.2.1 测试的 iOS 版本(真实 iPhone 设备):15.3.1
I am trying to write a UI test for our app's IAP using a sandbox account. However, when trying to tap this purchase button, the test is unable to find this element:screenshot of in-app-purchase prompt
I've tried targeting this element by its button name and label name with no success. During the UI recording, when tapping this button, Xcode freezes completely and I am forced to shut Xcode down. I've also tried debugging at this step and when I print out "app.debugDescription" in the console, this button nor any of the other elements in this purchase drawer is returned.
Failing line of code:app.buttons["Purchase"].tap()
Error message:No matches found for Elements matching predicate '"Purchase" IN identifiers'
Xcode Version: 13.2.1
iOS Version tested (real iPhone device): 15.3.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此前,Apple 根本不允许对 IAP 进行任何测试。 最近他们引入了对 StoreKit 框架的测试,但它位于单元测试级别;如果他们出于安全原因以编程方式阻止对自动化的访问,我不会感到惊讶。
如果这要工作,您需要找到正在“运行”的应用程序(StoreKit 窗口)的包标识符并与之交互。不幸的是,我没有可用的应用程序(可以购买的应用程序)来让我为您研究这个问题。
强制点击坐标(为了可靠性,我总是在 x 和 y 上添加一些像素)应该可以工作。从来不理想,但可能是你唯一的希望。
另一种选择是设置自动接受警报功能?它可能有效。
capability.SetCapability("autoDismissAlerts", true)
Previously, Apple has not permitted any testing of IAP at all. Recently they introduced testing to the StoreKit framework, but it's at the unit testing level; I wouldn't be surprised if they're programmatically blocking access to automation for security reasons.
If this were to work you'd need to find the bundle identifier of the application that's "running" (the StoreKit window) and interact with that. I unfortunately don't have an application available (one with a purchase available) to allow me to look into this for you.
A forced tap on the coordinates (I always add a few pixels to the x and y for reliability) should work. Never ideal, but might be your only hope.
Another option would be to set the auto-accept alerts capability? It might work.
capabilities.SetCapability("autoDismissAlerts", true)
通过反复试验,我发现您可以通过 SpringBoard 定位购买按钮。
Through trial and error, I've discovered that you can target the purchase button through the SpringBoard.