如何在快速的UITests中的XCUIApplication中设置暗模式?

问题描述 投票:0回答:1

我想知道是否可以在快速的UITests项目中为XCUIApplication设置暗模式代码内编码。

我需要在同一测试中以亮模式和暗模式启动该应用程序。在方案中将此值设置为硬编码值将不起作用,或者从外部入侵模拟器也将不起作用(出于性能和可维护性等原因)。

目前,我像这样设置启动参数:

    let app = XCUIApplication()
    var launchArguments: [AnyHashable] = []
    launchArguments.append("-AppleLanguages")
    launchArguments.append(langCode)
    launchArguments.append("-AppleLocale")
    launchArguments.append(localeCode)
    app.launchArguments = launchArguments
    app.launch()

而且效果很好。

如何为XCUIApplication实例设置暗模式?

我做了什么:

  • Apple开发文档的广泛搜索。
  • [StackOverflow仅显示如何在Xcode中的方案中对此进行硬编码,或者如何通过杀死模拟器,擦除它并破解plist值来从外部对模拟器进行黑客攻击。

感谢您的帮助!

swift ios-simulator xcuitest
1个回答
0
投票

在macOS中,从Terminal.app,您可以发出此命令

defaults read NSGlobalDomain AppleInterfaceStyle

回复者


在您的XCTestCase中,这应该有效

    func testAppleInterfaceStyleDark() {
        let app = XCUIApplication()
        var launchArguments: [AnyHashable] = []

        launchArguments.append("-AppleInterfaceStyle")
        launchArguments.append("Dark")
        app.launchArguments = launchArguments as! [String]
        app.launch()
    }
© www.soinside.com 2019 - 2024. All rights reserved.