是否有针对可访问性标识符的既定命名约定(与 Xcode UI 测试记录相关)?
我正在研究可访问性和 UI 测试。我使用了 Xcode 7 中的新记录功能。在记录 UI 操作时,我注意到:
当我有一个标有“a”的按钮并记录点击两次时,我得到以下代码:
XCUIElement *aButton = [[XCUIApplication alloc] init].buttons[@"a"];
[aButton tap];
[aButton tap];
Run Code Online (Sandbox Code Playgroud)
当我将其accessibilityIdentifier 设置为“a”并重复录制时,我得到相同的代码。
本地化标签会干扰辅助功能标识符吗?(如果在某些语言中,按钮 X 突然将“a”作为标签,而按钮 Y 将“a”作为可访问性标识符 - 这是否会产生歧义/冲突?)
我的第一个想法是为可访问性标识符设置一个唯一的前缀 - 比如“@”。所以我尝试了“@a”、“@1”等。
然而,使用“@1”记录会导致以下代码:
XCUIElement *1Button = [[XCUIApplication alloc] init].buttons[@"@1"];
[1Button tap];
[1Button tap];
Run Code Online (Sandbox Code Playgroud)
这会产生编译器错误,因为1Button不是有效的标识符。显然,可访问性标识符被添加到按钮的变量名称前面,并删除了一些字符。
使用“1”记录会导致以下代码:
XCUIElement *button = [[XCUIApplication alloc] init].buttons[@"1"];
[button tap];
[button tap];
Run Code Online (Sandbox Code Playgroud)
这引出了另一个问题:
我可以影响 Xcode 在记录期间派生变量名称的方式吗?
我知道,我可以手动进行记录和清理变量名。然而,如果可以在某个地方轻松配置它,那就太愚蠢了。
如果测试通过,我需要更新一些日志,如果测试通过,我需要更新一些不同的日志。如何确定tearDown() 方法中的测试是通过还是失败?
override func tearDown() {
super.tearDown()
// Would like an if statement here to update my logs but not sure how to detect the state
if fail {
log.update("failed")
} else if !fail {
log.update("success")
}
}
Run Code Online (Sandbox Code Playgroud) 我想为我的 iOS 应用程序编写一个测试,以验证从自定义注册的 URL 方案启动应用程序时显示正确的屏幕内容。
例如,用户收到一封电子邮件,其中包含 的链接myapp://action1/1234。当他们点击此链接时,我的应用程序将启动并且屏幕显示“1234”。
在didFinishLaunchingWithOptions我的 AppDelegate 中检查是否launchOptions?[UIApplicationLaunchOptionsURLKey]存在并采取适当的操作。
如何编写 UI 测试,以便应用程序启动时应用程序 launchOptions 字典包含预期的 URL?
我想使用 UI 测试自动(验证)iOS 中 GoogleMapView 的 zoomIn - zoomOut。
使用以下代码,我可以放大(并且可以正常工作):
mapView.pinch(withScale: 1.8, velocity: 1)
但我无法缩小,我尝试了以下选项:
mapView.pinch(withScale: 1.2, velocity: 1)(我以为这会缩小,因为以前的比例是1.8,但不是)
也尝试使用 (0,1) ~ 之间的值,但这只是移动地图(不是放大)
mapView.pinch(withScale: 0.7, velocity: -1)
mapView.pinch(withScale: 0.9, velocity: -0.9)
我想测试登录单击是否在仪表板屏幕上正确导航。
有没有办法做到这一点?
我目前的测试代码就像
func testExample() {
let usernameTextField = app.textFields["Username"]
usernameTextField.tap()
usernameTextField.typeText("abc@gmail.com")
let passwordTextField = app.textFields["Password"]
passwordTextField.tap()
passwordTextField.typeText("abc123")
app.buttons["Login" ].tap()
//let loginButton = app.staticTexts["Login"]
//XCTAssertEqual(loginButton.exists, true)
app.navigationBars["UIView"].buttons["Back"].tap()
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 XCTest 中的功能截图来捕获屏幕,但我无法理解如何将此屏幕截图保存到模拟器设备或物理设备上
https://developer.apple.com/documentation/xctest/xcuiscreenshot
我正在尝试在这里自动化 UI 测试,并且需要捕获大量屏幕截图以供审核。
我正在尝试使我的测试自动化一点。我编写了一个简单的测试来截取我的应用程序的屏幕截图
func testiPhoneVariants() {
let screenshot = XCUIScreen.main.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
attachment.lifetime = .keepAlways
add(attachment)
}
Run Code Online (Sandbox Code Playgroud)
现在我想在多个模拟器上测试它,所以我做了命令行:
xcodebuild -workspace MyProject.xcworkspace -scheme MyProjectUITests \
-destination 'platform=iOS Simulator,name=iPhone SE' \
-destination 'platform=iOS Simulator,name=iPhone 7' \
-destination 'platform=iOS Simulator,name=iPhone 7 Plus' \
-destination 'platform=iOS Simulator,name=iPhone X' \
test
Run Code Online (Sandbox Code Playgroud)
测试已经通过了,但是在哪里可以找到屏幕截图呢?
谢谢 - 约瑟夫
假设我有一个包含三个图像的表,它们accessiblityIdentifier设置为“fooImage”。
XCTAssertTrue(table["tableName"].images.count == 3)会起作用,但这很糟糕——如果有人添加了另一种图像类型怎么办?我想要标识符==“fooImage”的所有图像的计数。
XCUIApplication().images["fooImage"].count是一个编译失败Value of type 'XCUIElement' has no member 'count'。
我试图在 UITesting 中获取我的应用程序名称。我试过下面的代码:
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
Run Code Online (Sandbox Code Playgroud)
但它给了我零值结果。
目前我们的测试失败了,因为当授予位置权限时,我们永远不会进入下一个屏幕,因为位置更新永远不会发生。
这是因为使用 Fastlane 设置的新模拟器实例不会设置位置。app 目标方案指定了默认位置,UI 测试目标也是如此;两者都没有受到尊重。当从 Xcode 运行测试时,位置确实会得到尊重,而不是当模拟器从命令行激活时,因为模拟器应用程序从未真正打开过,只是存在,由终端拥有但不可见。测试套件上的位置也已设置。
当模拟器以不可见的方式运行时,如何在脚本中设置模拟器的位置?
我发现了这个:https : //github.com/lyft/set-simulator-location
它需要这个脚本:
# download set-simulator-location
brew install lyft/formulae/set-simulator-location
# run simulator
export IOS_SIMULATOR_UDID=`instruments -s devices | grep "iPhone 6 (10.3) \[" | awk -F '[ ]' '{print $4}' | awk -F '[\[]' '{print $2}' | sed 's/.$//'`
echo $IOS_SIMULATOR_UDID
open -a "simulator" --args -CurrentDeviceUDID $IOS_SIMULATOR_UDID
# wait simulator to start fully
sleep 15
# set location
set-simulator-location -q London
Run Code Online (Sandbox Code Playgroud)
但它看起来很笨重,需要硬编码特定的模拟器然后打开它,等待 15 秒,然后在上面设置位置。我觉得一定有更好的方法。
xcode-ui-testing ×10
ios ×6
swift ×5
xcode ×5
circleci ×1
fastlane ×1
iphone ×1
screenshot ×1
testing ×1
ui-testing ×1
uitest ×1
xcode9 ×1
xctest ×1
xcuitest ×1