XCTestHTMLReport icon indicating copy to clipboard operation
XCTestHTMLReport copied to clipboard

Display phone language on the device list

Open kenji21 opened this issue 7 years ago • 2 comments

First, thank to all contributors of this nice tool

The "issue" is that we can't determine in which language the device was set (we use this with screenshot attachments to "preview" screens in different languages)

screen shot

Just like Model / Identifier, I'll like to see language displayed here, but no idea where to find it in each TestResults folder. The screen shot shows that it is the same simulator being used and language is "injected" with the -testLanguage argument of xcodebuild , which makes app process receive arguments:

  8570 08:16:24.454 TestLang[24983:27390888] Process arguments: (
  8571     "/Users/kenji/Library/Developer/CoreSimulator/Devices/818388E6-1E26-4107-BBAC-5A88135BE5B4/data/Containers/Bundle/Application/20DC2079-24D0-4C2C-81EC-5021D2D5EB67/TestLang.app/TestLang",
  8572     "-AppleLanguages",
  8573     "(fr)",
  8574     "-AppleTextDirection",
  8575     NO,
  8576     "-AppleLocale",
  8577     fr,
  8578     "-NSTreatUnknownArgumentsAsOpen",
  8579     NO,
  8580     "-ApplePersistenceIgnoreState",
  8581     YES
  8582 )

So I look to AppleLanguages in the TestResults_fr folder:

grep -R AppleLanguages TestResults_fr/
Binary file TestResults_fr//1_Test/Diagnostics/TestLangTests-9A99736B-9B11-44E2-A21C-A245ECE58812/LaunchSessions/8D4BD3B8-F826-414D-B355-2EAA198601E6/remote-container/tmp/TestLangTests-8D4BD3B8-F826-414D-B355-2EAA198601E6.xctestconfiguration matches
TestResults_fr//1_Test/Diagnostics/TestLangTests-9A99736B-9B11-44E2-A21C-A245ECE58812/Session-TestLangTests-2018-07-06_081603-WdmePD.log:        "-AppleLanguages",
TestResults_fr//1_Test/Diagnostics/TestLangTests-9A99736B-9B11-44E2-A21C-A245ECE58812/Session-TestLangTests-2018-07-06_081603-WdmePD.log:    "-AppleLanguages",

So the "Apple binary property list" xctestconfiguration file contain this information.

Steps to reproduce:

  • create a single view Xcode project "TestLang"
  • run xcodebuild test -scheme TestLang -destination name="iPhone 8" -resultBundlePath TestResults_fr -testLanguage fr | xcpretty
  • then in another language:xcodebuild test -scheme TestLang -destination name="iPhone 8" -resultBundlePath TestResults_en -testLanguage en | xcpretty
  • xchtmlreport -r TestResults_fr -r TestResults_en
  • open TestResults_fr/index.html

kenji21 avatar Jul 06 '18 06:07 kenji21

Hi @kenji21

Thanks for the report. I do see the need for this kind of feature but looking at the complexity of how to get this information I'm not going to have time in the near future. I'd be happy to review the pull request if you try to take a crack at it.

Cheers

TitouanVanBelle avatar Aug 29 '18 19:08 TitouanVanBelle

Just wrote a single script to gather these values:

require 'cfpropertylist'

plist = CFPropertyList::List.new(:file => ARGV[0])
result = CFPropertyList.native_types(plist.value)

objects = result['$objects']

locale = ""
language = ""

languagesIndex = objects.index('-AppleLanguages')
if languagesIndex 
  language = objects[languagesIndex + 1]
end

localeIndex = objects.index('-AppleLocale')
if localeIndex
  locale = objects[localeIndex + 1]
end

print "#{ARGV[0]}: #{language} #{locale}\n"

using this shell command:

find TestResults_* -name *.xctestconfiguration -exec ruby test.rb {} \;

which give this output:

TestResults_en/1_Test/Diagnostics/TestLangTests-06225C84-F6C4-4C5F-BF80-E88E7438AB8A/LaunchSessions/7F35A49B-C466-495B-A0F6-F5605C043102/remote-container/tmp/TestLangTests-7F35A49B-C466-495B-A0F6-F5605C043102.xctestconfiguration: (en) en
TestResults_fr/1_Test/Diagnostics/TestLangTests-6E5AF9F0-51AA-4553-ABCB-676B7693ADF2/LaunchSessions/D76D6CCF-1B13-4458-A817-D963357FDD50/remote-container/tmp/TestLangTests-D76D6CCF-1B13-4458-A817-D963357FDD50.xctestconfiguration: (fr) fr

kenji21 avatar Sep 10 '18 13:09 kenji21