Ios XCTestCase禁用快照可访问性层次结构
我正在使用XCode的XCTestCase进行自动化UI测试,以测量我的应用程序的性能。我目前有一个包含25000个元素的UITable,当我试图运行应该刷这个列表的测试时,它会一直运行,并在完成测试之前崩溃。此时,应用程序的目标CPU使用率为100% 控制台中的最后一个输出是: 的快照可访问性层次结构 当将列表限制为几百个元素(不可接受)时,自动测试至少能够滚动列表,但每次滚动之间的等待时间约为3-4秒 测试场景:Ios XCTestCase禁用快照可访问性层次结构,ios,xcode,xctest,xctestcase,Ios,Xcode,Xctest,Xctestcase,我正在使用XCode的XCTestCase进行自动化UI测试,以测量我的应用程序的性能。我目前有一个包含25000个元素的UITable,当我试图运行应该刷这个列表的测试时,它会一直运行,并在完成测试之前崩溃。此时,应用程序的目标CPU使用率为100% 控制台中的最后一个输出是: 的快照可访问性层次结构 当将列表限制为几百个元素(不可接受)时,自动测试至少能够滚动列表,但每次滚动之间的等待时间约为3-4秒 测试场景: let app = XCUIApplication(); app.button
let app = XCUIApplication();
app.buttons["Long list"].tap();
let table = app.tables.element;
table.swipeUp();
table.swipeUp();
那么有没有办法加快测试速度呢?可能禁用可访问性层次结构(不以任何方式为测试使用可访问性标签)。可能您可以使用api,如
-(double)pressAtPoint:(struct CGPoint)arg1进行持续:(double)arg2 liftAtPoint:(struct CGPoint)arg3速度:(double)arg4方向:(long long)arg5名称:(id)arg6处理程序:(CDUnknownBlockType)arg7代码>
#ifndef XCEventGenerator_h
#define XCEventGenerator_h
typedef void (^CDUnknownBlockType)(void);
@interface XCEventGenerator : NSObject
+ (id)sharedGenerator;
// iOS 10.3 specific
- (double)forcePressAtPoint:(struct CGPoint)arg1 orientation:(long long)arg2 handler:(CDUnknownBlockType)arg3;
- (double)pressAtPoint:(struct CGPoint)arg1 forDuration:(double)arg2 orientation:(long long)arg3 handler:(CDUnknownBlockType)arg4;
- (double)pressAtPoint:(struct CGPoint)arg1 forDuration:(double)arg2 liftAtPoint:(struct CGPoint)arg3 velocity:(double)arg4 orientation:(long long)arg5 name:(id)arg6 handler:(CDUnknownBlockType)arg7;
@end
#endif /* XCEventGenerator_h */
- (void)testExample {
XCUIApplication* app = [[XCUIApplication alloc] init];
XCUICoordinate* start_coord = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.3)];
XCUICoordinate* end_coord = [app coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.7)];
NSLog(@"Start sleeping");
[NSThread sleepForTimeInterval:4];
NSLog(@"end sleeping");
for(int i = 0; i < 100; i++)
{
[[XCEventGenerator sharedGenerator] pressAtPoint:start_coord.screenPoint
forDuration:0
liftAtPoint:end_coord.screenPoint
velocity:1000
orientation:0
name:@"drag"
handler:^{}];
[NSThread sleepForTimeInterval:1];
}
}
#ifndef XCEventGenerator#h
#定义XCEventGenerator\u h
typedef void(^CDUnknownBlockType)(void);
@接口XCEventGenerator:NSObject
+(id)共享发电机;
//iOS 10.3特定
-(双)forcePressAtPoint:(struct CGPoint)arg1方向:(long long)arg2处理程序:(CDUnknownBlockType)arg3;
-(double)pressAtPoint:(struct CGPoint)arg1持续时间:(double)arg2方向:(long-long)arg3处理程序:(CDUnknownBlockType)arg4;
-(双)按压点:(struct CGPoint)arg1持续时间:(双)arg2提升点:(struct CGPoint)arg3速度:(双)arg4方向:(长)arg5名称:(id)arg6处理程序:(CDUnknownBlockType)arg7;
@结束
#endif/*XCEventGenerator\u h*/
-(无效)测试示例{
XCUIApplication*app=[[XCUIApplication alloc]init];
xguicoordinate*start_coord=[app coordinateWithNormalizedOffset:CGVectorMake(0.5,0.3)];
xguicoordinate*end_coord=[app coordinateWithNormalizedOffset:CGVectorMake(0.5,0.7)];
NSLog(@“开始睡眠”);
[NSThread sleepForTimeInterval:4];
NSLog(@“结束睡眠”);
对于(int i=0;i<100;i++)
{
[[XCEventGenerator sharedGenerator]按ATPOINT:start\u coord.screenPoint
持续时间:0
提升点:终点坐标屏幕点
速度:1000
方向:0
名称:@“拖动”
处理程序:^{}];
[NSThread sleepForTimeInterval:1];
}
}