UI Automation

268 阅读1分钟

4个新的classes:XCUIApplication,XCUIElement,XCUIElementQuery,XCUIDevice

(1)XCUIApplication:启动app,并为每个测试用例提供一个干净的状态;

启动app,开始testing;如果调用改方法之前,app已经处理运行状态,该方法会先调用-(void)terminate方法以确保干净的工作环境; -(void)launch;

停止app中所有正在运行的工作; -(void)terminate;

(2)XCUIElement:页面控件元素

//是否存在 @property (readonly) BOOL exists; //是否可点击 @property (readonly, getter = isHittable) BOOL hittable; //通过控件的类型,返回该类控件查询组 -(XCUIElementQuery *)descendantsMatchingType:(XCUIElementType) type; //通过控件的类型,返回改类控件的所有子控件; -(XCUIElementQuery*)childrenMatchingType:(XCUIElementType) type;

(3)XCUIElementQuery:元素查询结果,提供符合条件的元素

//查询结果中唯一的元素 @property (readonly) XCUIElement *element; //查询结果中符合匹配的元素个数 @property (readonly) NSUInteger count; //返回查询结果中不是通过accessibility而是通过位置来定位的元素 - (XCUIElement *)elementBoundByIndex:(NSUInteger)index;

(4)XCUIDevice:物理设备

//设备显示方向 @property (nonatomic) UIDeviceOrientation orientation; //物理按键,音量/home建 - (void)pressButton:(XCUIDeviceButton)button;