I was wondering if there is a way to set dark mode in-code for the XCUIApplication within a swift UITests project.
I have a need to launch the app in light mode and dark mode in the same test. Setting this in the scheme as a hard coded value will not work, or hacking the simulator from the outside will not work either (for performance & maintainability reasons among others).
Currently I set launch arguments like so:
let app = XCUIApplication()
var launchArguments: [AnyHashable] = []
launchArguments.append("-AppleLanguages")
launchArguments.append(langCode)
launchArguments.append("-AppleLocale")
launchArguments.append(localeCode)
app.launchArguments = launchArguments
app.launch()
And it works great.
How do I set Dark Mode for a XCUIApplication instance?
What I've done:
- Extensive search on Apple Development Docs.
- StackOverflow only shows how to hard-code this in the scheme within Xcode, or how to hack the simulator from the outside by killing the simulator, erasing it, and hacking a plist value.
Thanks for any help!