如何在XCode7上对系统按钮进行自动UI测试? [英] How to do automated UI testing for system button on XCode7?

查看:90
本文介绍了如何在XCode7上对系统按钮进行自动UI测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的故事板只有一个用户界面,它有一个带有系统项目:添加的UIBarButtonItem的导航栏。它还有另一个信息UIButton。
用英语进行UI测试时,一切都很好,没有任何问题。但是如果你将语言切换到另一种语言,它总是失败的。以下是测试代码段:

My Storyboard has only one UI, and it has navigation bar with one UIBarButtonItem with System Item: Add. It also has another info UIButton. When doing UI testing in English everything works good without any problem. But if you switch the language to another one, it is always failed. Here is the testing code snippet:

app.navigationBars["My Product"].buttons["Add"].tap()
app.buttons["More Info"].tap()

根据错误日志,Xcode用另一种语言找到它。这是:

According to the error log, Xcode find it in another language. Here it is:


断言失败:UI测试失败 - 未找到更多信息按钮匹配

Assertion Failure: UI Testing Failure - No matches found for "More Info" Button

查询输入

Button 0x7fa4ca65a1d0: traits: 8724152321, {{8.0, 31.5}, {21.0, 21.0}}, label: '戻る',
Button 0x7fa4ca657700: traits: 8589934593, {{330.5, 26.0}, {40.0, 30.0}}, label: '追加',
Button 0x7fa4ca4658d0: traits: 8589934593, {{312.0, 605.0}, {22.0, 22.0}}, label: '詳細情報'


但是,我没有为它创建任何本地化字符串,因为它只是iOS系统创建的图像。有谁知道如何修理它?
非常感谢。

However, I haven't created any localized string for it since it's just an image created by iOS system. Does anyone know how to fix it? Thanks so much.

推荐答案

选项1:设置默认语言



为UI测试创建一个新方案并设置默认的应用程序语言。这会将应用程序锁定到一个本地化文件中,以便您可以编写该语言的所有测试。

Option 1: Set a Default Language

Create a new scheme for UI Testing and set the default Application Language. This will lock the app into one localized file so you can write all of your tests for that language.

从Product - > Scheme - > Manage Schemes或<设置选项KBD>⌘⇧,。然后选择选项选项卡并设置语言。

Set the option from Product -> Scheme -> Manage Schemes or ⌘⇧,. Then select the Options tab and set the language.

优点:简单,一次性更改。

Pros: Simple, one-time change.

缺点:无法用于创建使用快照(通过UI测试运行应用程序并在此过程中生成App Store屏幕截图的工具)进行本地化截屏)。

Cons: Cannot be used to create localized screenshots with snapshot (a tool that runs your app via UI Testing and generates App Store screenshots along the way).

使用 accessibilityIdentifier ,而不是通过显示的文本或值访问项目。这是由UI测试框架读取的,但从未向用户显示或读取(即使打开了辅助功能)。在旧的UIAutomation文档中,Apple提到将此用于开发人员功能,这就像一个很好的用例。

Instead of accessing items via their displayed text or value, use accessibilityIdentifier. This is read by the UI Testing framework but never shown or read to users (even with accessibility turned on). In the old UIAutomation docs Apple mentions using this for developer functionality, which this seams like a good use case.

然后你可以继续设置 accessibilityLabel accessibilityValue 与正常情况一样,具有本地化版本。

You can then continue to set accessibilityLabel and accessibilityValue like normal, with the localized versions.

优点:可用于更通用的解决方案,例如拍摄自动截图。

Pros: Can be used for more generic solutions, such as taking automated screenshots.

缺点:可能需要更多工作来更改每个标签需要非本地化进行测试。

Cons: Might require more work changing each label you need "unlocalized" for testing.

这篇关于如何在XCode7上对系统按钮进行自动UI测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆