为MKMapView对象分配辅助功能标识符

时间:2016-06-13 16:25:02

标签: swift xctest xcode-ui-testing

我正在尝试为我正在使用的应用配置快照,它已经在英文版本中运行,但在本地化版本中,我不知道如何为一个可访问性标识符分配在MKMapView的Map中固定,有人知道如何做到这一点吗?

感谢。

1 个答案:

答案 0 :(得分:5)

辅助功能标识符是将应用程序语言与Xcode UI测试分开的好方法。标识符来自UIView NSObject已符合的标识符。但是,MKAnnotationclass Annotation: NSObject, MKAnnotation, UIAccessibilityIdentification { let coordinate: CLLocationCoordinate2D let title: String? var accessibilityIdentifier: String? init(title: String?, coordinate: CLLocationCoordinate2D) { self.title = title self.coordinate = coordinate } } let coordinate = CLLocationCoordinate2DMake(40.703490, -73.987770) let annotation = Annotation(title: "BeerMenus HQ", coordinate: coordinate) annotation.accessibilityIdentifier = "Custom Identifier" let mapView = MKMapView() mapView.addAnnotation(annotation) 都不符合协议。所以你必须自己设定一致性。

otherElements

然后在测试中,您可以通过let app = XCUIApplication() let annotation = app.maps.element.otherElements["Custom Identifier"] annotation.tap() 引用注释。

->add('datefield', DateType::class, array(
    'data'          => new \DateTime(),
    'format'            => 'dd MMMM yyyy',
    'required'      => false,
    'placeholder'   => array(
        'month' => null,
        'year'  => null,
    ),
))
相关问题