ios - 测试view的前景颜色
问题描述
如何测试foregroundColor
UITest 中的视图?我有一个Text
例子:
Text("this can have different colors").foregroundColor(textColor)
在 UITest 我想知道 Text 有哪种颜色,例如:
XCTAssertEquals(app.staticTexts["..."].color, Color.white)
但是没有字段.color
。
这同样适用于Image
s。
解决方案
这在 UI 测试中是不可能的,它不会真正检查视觉效果,而是使用可访问性标识符与应用程序交互。
如果您想测试视图的颜色,您应该查看快照测试。您可以使用支持 SwiftUI 的 Point-Free 的 SnapshotTesting: https ://github.com/pointfreeco/swift-snapshot-testing
推荐阅读
- git - 使用 WSL2/git 的 Github 问题
- macos - setsockopt 在 MAC 上返回 SOCKET_ERROR
- push-notification - Laravel 通知不会向 Pusher 发送事件
- c++ - 将 int 指针分配给 void* 数组的索引时出现问题
- reactjs - Mapbox 地图图层未找到/着色法国
- php - 存在则更新,不存在则插入
- sql - 需要在oracle db中将源货币转换为美元
- python - TypeError: int() 参数必须是字符串、类似字节的对象或数字,而不是“石头剪刀布”游戏客户端文件中的“NoneType”
- numpy - NumPy 数组中每两个连续点的线方程
- python - python3 requests.delete 为承载令牌提供 401 Unauthorized 但在邮递员中为 keycloak 用户会话删除端点工作正常