在UI测试中无法访问字符串本地化(Xcode 7) [英] Can't get access to string localizations in UI Test (Xcode 7)

查看:118
本文介绍了在UI测试中无法访问字符串本地化(Xcode 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一种情况,我有一些经验证的textFields。我正在尝试运行UI测试,当他们失败时,他们会收到警告,弹出错误消息(可能是不同的消息,具体取决于哪些字段无效以及以何种方式)。

So I have a situation in which I have a few textFields that are validated. I'm trying to run a UI test, and when they fail they will get an alert to pop up with an error message (potentially a different message depending on what fields are invalid and in what way).

我想测试一下,不仅会出现警报,还会显示正确的消息。我遇到的问题是我需要获取本地化的文本进行比较(如果我用英语以外的其他语言运行测试),但是当我在UITest中调用NSLocalizedString时,它无法收集正确的本地化字符串(只是返回键[默认])

I'd like to test that not only that an alert appeared, but that the correct message is displayed. The problem I'm having is that I need to get the localized text for comparison (if I run tests in another language other than english), but when I call NSLocalizedString in the UITest it can't gather the correct localized string (just returns the key [default])

我尝试将 localizeable.strings 文件添加到UITest目标,但是无济于事。有没有人知道这是否可行?

I've tried adding the localizeable.strings files to the UITest target, but to no avail. Does anyone know if this is possible?

编辑旁注:我还尝试在 UIAlertView 但是当我查询该可访问性标识符时它不存在,我只能使用看起来倒退的警报标题来查询它。

edit as a side note: I also tried setting an accessibility identifier on the UIAlertView but when I query with that accessibility identifier it doesn't exist, I can only query it using the title of the alert which seems backwards.

推荐答案

在UI测试中,主包似乎是一个随机启动器应用程序。这就是.strings文件没有出现的原因:即使你将它添加到测试包中,NSLocalizedString也会检查错误的包。要解决这个问题,你需要这样的调用:

In the UI tests, the main bundle seems to be a random launcher app. That's why the .strings file doesn't appear: even though you added it to your test bundle, NSLocalizedString is checking the wrong bundle. To get around this, you need an invocation like this:

NSLocalizedString("LOCALIZATION_KEY", bundle: NSBundle(forClass: AClassInYourUITests.self), comment: "")

您可能希望将其纳入辅助方法。

Which you might want to pull into a helper method.

这篇关于在UI测试中无法访问字符串本地化(Xcode 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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