协议类,XCUIElement遵守的协议
属性
identifier
字符串类型
frame
控件的矩形区域
value
title
标题,String类型
label
标签值,String类型
elementType
控件类型
enabled
是否可见,BOOL类型
horizontalSizeClass
verticalSizeClass
实例
Swift
func testXCUIElementAttributes(){
let app = XCUIApplication()
//id
let id = app.identifier
print(id)
//frame
let frame = app.frame
//value
let value = app.value
//title
let title = app.title
//label
let label = app.label
//elementType
let elementType = app.elementType
//enabled
let enabled = app.enabled
//horizontalSizeClass
let horizontalSizeClass = app.horizontalSizeClass
//verticalSizeClass
let verticalSizeClass = app.verticalSizeClass
}
OC
-(void)testXCUIElementAttributes{
XCUIApplication *app = [[XCUIApplication alloc] init];
//id
NSString *identifier = [app identifier];
//frame
CGRect frame = [app frame];
//value
id value = [app value];
//title
NSString *title = [app title];
//label
NSString *label = [app label];
//elementType
XCUIElementType *elementType = [app elementType];
//enabled
BOOL *isEnabled = [app isEnabled];
//horizontalSizeClass
XCUIUserInterfaceSizeClass *horizontalSizeClass = [app horizontalSizeClass];
//verticalSizeClass
XCUIUserInterfaceSizeClass *verticalSizeClass = [app verticalSizeClass];
}
对比
从OC和Swift的显示的信息中可以看出来,二者的差别还是很大的,有些属性的值在两者的表现上是不同的,不知道这又作何解释呢?所以劝大家还是使用swift版本的为好。
源码
Swift
protocol XCUIElementAttributes {
/*! The accessibility identifier. */
var identifier: String { get }
/*! The frame of the element in the screen coordinate space. */
var frame: CGRect { get }
/*! The raw value attribute of the element. Depending on the element, the actual type can vary. */
var value: AnyObject? { get }
/*! The title attribute of the element. */
var title: String { get }
/*! The label attribute of the element. */
var label: String { get }
/*! The type of the element. /seealso XCUIElementType. */
var elementType: XCUIElementType { get }
/*! Whether or not the element is enabled for user interaction. */
var enabled: Bool { get }
/*! The horizontal size class of the element. */
var horizontalSizeClass: XCUIUserInterfaceSizeClass { get }
/*! The vertical size class of the element. */
var verticalSizeClass: XCUIUserInterfaceSizeClass { get }
}
OC
@protocol XCUIElementAttributes
/*! The accessibility identifier. */
@property (readonly) NSString *identifier;
/*! The frame of the element in the screen coordinate space. */
@property (readonly) CGRect frame;
/*! The raw value attribute of the element. Depending on the element, the actual type can vary. */
@property (readonly, nullable) id value;
/*! The title attribute of the element. */
@property (readonly, copy) NSString *title;
/*! The label attribute of the element. */
@property (readonly, copy) NSString *label;
/*! The type of the element. /seealso XCUIElementType. */
@property (readonly) XCUIElementType elementType;
/*! Whether or not the element is enabled for user interaction. */
@property (readonly, getter = isEnabled) BOOL enabled;
/*! The horizontal size class of the element. */
@property (readonly) XCUIUserInterfaceSizeClass horizontalSizeClass;
/*! The vertical size class of the element. */
@property (readonly) XCUIUserInterfaceSizeClass verticalSizeClass;
@end