ui-screen-shooter
ui-screen-shooter copied to clipboard
Status bar is not set to the correct locale and region
neither in the included sample project nor in my own project.
Xcode 5.1.1 with current iOS 7.1 SDK
The language and locale are injected into the app when it is launched using the special command line parameters that affect NSUserDefaults
. Apparently, it doesn't alter the simulator as a whole which is why the status bar isn't affected.
Do you have a suggestion for this? I'm inclined to just direct people to use an app like Status Magic (Mac app store link) because it makes it easy to set the status bar in screen shots to anything you want. I go through and change the status bar on screen shots that I use because I want to set the time anyway.
I believe Status Magic has a code snippet on their site somewhere to make the status bar invisible for screenshots. This is vital for cases where there is blurred stuff behind the status bar. They also don’t have support for adding “100%” to the battery indicator, but they told me it will be in the next release.
This also means that target.frontMostApp().preferencesValueForKey("AppleLanguages")[0];
won't return the correct language. Having this is important for navigating through localized content. I work on a podcast app, and want to select different podcasts for each language. The only solution I can think of at the moment is to make separate shoot_the_screens.js
for each language and have the ui-screen-shotter.js
call them.
Ah, @PadraigK, that's an excellent point. Hmm. Well, I could re-introduce the script that hacked the user defaults plist file in the simulator directories. That forces the language at the simulator OS level, but it's a hack that I was never proud of. I'd rather make it an option that you could put in yourself than the default.
Thoughts?
I went ahead with making separate shoot-en_US.js, shoot-fr-FR.js
etc.. files and it works ok. Probably better to go this way and not have to rely on hacking the plist file as before. Maybe someone clever can come up with another way to pull the language from the simulator. We could also file a Radar pointing out that the value of the locale, etc.. are reported incorrectly in this case.
Please confirm still broken in XCode 6
Does UI Screen Shooter work when running on-device? The reason I ask is that in Yosemite, when you enable screen recording on an iOS 8 device through QuickTime Player, it magically turns the status bar into an App Store-perfect status bar, with 9:41 AM and all the rest. If Apple fixes this bug with using AppleScript to set an iOS device as the input source, this could potentially be put into your scripts.
I ended up with a similar workaround to @PadraigK : I have JS files with variable declarations automation-variables-en.js
and cat this file and the actual logic in my config-automation.js
to one JS script before each run, altering _run_automation
like so:
function _run_automation {
# Runs the UI Automation JavaScript file that actually takes the screenshots.
automation_base="$1"
language="$2"
simulator="$3"
automation_script="$UISS_DIR"/automation-full.js
lang_vars="$UISS_DIR"/automation-variables-en.js
if [ -f "$UISS_DIR"/automation-variables-${language}.js ]; then
lang_vars="$UISS_DIR"/automation-variables-${language}.js
fi
cat "$lang_vars" "$automation_base" > "$automation_script"
...
rm "$automation_script"
}
My solution was to export a language environment variable in ui-screen-shooter.sh:
for simulator in "${simulators[@]}"; do
for language in $languages; do
export UISS_LANG="$language"
...
and then pull this into my automation script like this and use it to change units etc. based on the locale:
var result = target.host().performTaskWithPathArgumentsTimeout("/usr/bin/printenv" , ["UISS_LANG"], 5);
var language = result.stdout.substring(0,result.stdout.length-1);
UIALogger.logMessage("language = " + language);
var usa = (language == "en-US");
var uk = (language == "en-GB");
...
I use NSLocaleUsesMetricSystem to successfully get whether I should display US or SI units. The simulator gets and displays correct units per language. But [[NSLocale preferredLanguages] firstObject]
always returns English. Am I doing something wrong or is this related to this issue? It sounds to me that the plist hack is the only solution that will work for my purposes.
Update: Yes, I was doing something wrong. Never mind! It works great!
Yosemite (10.10.1) + Xcode 6.1