简体   繁体   English

XCUITest:知道应用程序/ iPhone的语言

[英]XCUITest : Know language of app/iPhone

I have a scenario where there are different users based on the language. 我有一种情况,其中根据语言有不同的用户。 How do I determine the language of the iPhone/Simulator/App so that I know what login to use. 如何确定iPhone / Simulator / App的语言,以便知道要使用的登录名。

For example 例如

  • if the language is en-us user Eng_User 如果语言是en-us用户Eng_User
  • if language is ru then use Ru_User 如果语言是ru,则使用Ru_User

Is there a way in XCUITest after launching the application that I know the language being user 启动应用程序后,XCUITest中是否有一种方法,我知道该语言为用户

Can I set a property in app delegate and use it later?? 我可以在应用程序委托中设置属性并在以后使用吗? I tried setting app.accessibilityLanguage in appDelegate but couldn't use it in the test as the value returned was nil 我尝试在appDelegate中设置app.accessibilityLanguage,但是由于返回的值为nil,因此无法在测试中使用它

In Xcode 9, you can set the language for an XCUITest suite in 在Xcode 9中,您可以在以下位置设置XCUITest套件的语言:

Scheme -> Edit Scheme -> Test -> Options -> Application Language

Unfortunately I don't see a way to read that back right now. 不幸的是,我现在还没有一种阅读方法。 You could pass in an environment variable, though, that matches the language. 但是,您可以传入与语言匹配的环境变量。 Under

Scheme -> Edit Scheme -> Test -> Arguments -> Environment Variables

set a key / value for your test local and language that matches the setting in Options. 为您的测试语言和语言设置与“选项”中的设置匹配的键/值。 You can read environment variables in your test code with ProcessInfo.processInfo.environment ie 您可以使用ProcessInfo.processInfo.environment读取测试代码中的环境变量,即

let language = ProcessInfo.processInfo.environment["locale"]

More on localization testing in Xcode 9 can be found here: 在Xcode 9中可以找到更多有关本地化测试的信息:

http://www.ibabbleon.com/copywriter-translator/2017/06/whats-new-in-localization-in-xcode-9-ios-11/ http://www.ibabbleon.com/copywriter-translator/2017/06/whats-new-in-localization-in-xcode-9-ios-11/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM