gpt4 book ai didi

ios - XCTest 中的屏幕比例因子

转载 作者:行者123 更新时间:2023-11-28 23:57:28 24 4
gpt4 key购买 nike

我正在运行 UITest,其中获取屏幕比例因子至关重要。通常我使用 UIScreen.main.scalem 但 XCUIScreen.main 似乎没有 scale 属性。是否可以在 UITests 中访问设备比例因子?

最佳答案

我通过将 AccessibilityIdentifier 添加到包含所需信息的 AppDelegate 窗口来管理它:

int scaleFactor = [[NSNumber numberWithDouble:[UIScreen mainScreen].scale] intValue];
self.window.accessibilityIdentifier = [NSString stringWithFormat:@"windowScale:%d", scaleFactor];

然后访问它并在我的测试中解析:

var windowsScaleFactor: Int {
let scaleFactorString = self.windows.firstMatch.identifier
guard let scaleFactor = Int(scaleFactorString.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")) else {
fatalError("Could not determine window scale factor")
}
return scaleFactor
}

关于ios - XCTest 中的屏幕比例因子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50812396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com