0
私はUIControlのサブクラスを作成しました。これはUIButtonと同様に動作するはずです。UIControlをXCUITestのボタンとして表示させるにはどうすればよいですか?
XCUITestを使用してUIテストを実行すると、ボタンはXCUIApplication().buttons
ではなくXCUIApplication().staticTexts
に表示されます。
私はUIControlのサブクラスを作成しました。これはUIButtonと同様に動作するはずです。UIControlをXCUITestのボタンとして表示させるにはどうすればよいですか?
XCUITestを使用してUIテストを実行すると、ボタンはXCUIApplication().buttons
ではなくXCUIApplication().staticTexts
に表示されます。
私は周りを狩りをした後、私はアクセシビリティの特性が設定されていないことに気づいた。たとえば、私は次のクラスを持っています。
class ActivityButton: UIControl {
private let activityIndicator: UIActivityIndicatorView = {
let activityIndicator = UIActivityIndicatorView()
activityIndicator.hidesWhenStopped = true
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
return activityIndicator
}()
let titleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.translatesAutoresizingMaskIntoConstraints = false
return titleLabel
}()
override public init(frame: CGRect) {
super.init(frame: frame)
// This is the required call to make the control appear
// as a button in ui tests
accessibilityTraits = UIAccessibilityTraitButton
addSubview(activityIndicator)
addSubview(titleLabel)
createConstraints()
}
}