【问题标题】:XCTestCase disable Snapshot accessibility hierarchyXCTestCase 禁用快照可访问性层次结构
【发布时间】:2017-10-10 16:31:33
【问题描述】:

我正在使用 XCode 的 XCTestCase 进行自动化 UI 测试,以测量我的应用程序的性能。我目前有一个包含 25 000 个元素的 UITable,当尝试运行应该刷这个列表的测试时,它需要永远并且在完成测试之前崩溃。此时应用的目标 CPU 使用率为 100%。

控制台最后的输出是:

的快照可访问性层次结构

当将列表限制为几百个元素(不可接受)时,自动化测试至少能够滚动列表,但每次滚动之间需要等待大约 3-4 秒。

测试场景:

let app = XCUIApplication();
app.buttons["Long list"].tap();

let table = app.tables.element;
table.swipeUp();
table.swipeUp();

那么有什么方法可以加快测试速度吗?也许禁用可访问性层次结构(不以任何方式使用可访问性标签进行测试)。

【问题讨论】:

    标签: ios xcode xctest xctestcase


    【解决方案1】:

    也许你可以使用像- (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;这样的api

    #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];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 2019-03-04
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多