UITest录制

使用UITest进行录制的时候,会发现,系统的录制工具超级不好用。录制的大部分代码是无法直接运行的。因此,我们需要手动修改。
本文主要说明一些常用的写法。至于API,请参考XCUIElementQuery API

1、模拟UItableViewCell的点击

[[[app.tables childrenMatchingType:XCUIElementTypeCell] elementBoundByIndex:3] tap];

2、获取当前UIViewController的title

NSString *title = app.navigationBars.element.identifier;

3、点击navigationBar上自定义的返回键

XCUIApplication *app = [[XCUIApplication alloc] init];
[[[[app.navigationBars[app.navigationBars.element.identifier] childrenMatchingType:XCUIElementTypeButton] matchingIdentifier:@"返回"] elementBoundByIndex:1] tap];

4、在UIImageView上添加Tap手势,模拟点击事件

对ImgaeView添加两个属性:
imageView.isAccessibilityElement = YES;
imageView.accessibilityIdentifier = @"imageView";
if ([app.images[@"imageView"] exists]){
    [app.images[@"imageView"] tap];
}

5、UICollectionView上视图的模拟点击事件
例如:这里写图片描述
第一种:通过文字:
if ([tablesQuery.staticTexts[@"我的主页"] exists]) {
[tablesQuery.staticTexts[@"我的主页"] tap];
}

第二种:通过图片:

XCUIElementQuery *tablesQuery = app.tables;
if ([tablesQuery.images[@"myTotalImage"] exists]) {
      [tablesQuery.images[@"myTotalImage"] tap];
    }

6、模拟Slider的滑动

if (app.sliders.element.normalizedSliderPosition == 0.5 || app.sliders.element.normalizedSliderPosition == 1.0) {
        [[app.sliders elementBoundByIndex:0] adjustToNormalizedSliderPosition:0.0];
        sleep(1);
    }
    [[app.sliders elementBoundByIndex:0] adjustToNormalizedSliderPosition:0.5];
    sleep(1);
    [[app.sliders elementBoundByIndex:0] adjustToNormalizedSliderPosition:1.0];
    sleep(1);
    [[app.sliders elementBoundByIndex:0] adjustToNormalizedSliderPosition:0.5];
    sleep(1);
    [[app.sliders elementBoundByIndex:0] adjustToNormalizedSliderPosition:0.0];
    sleep(1);

暂时写到这里,后续有新的发现会持续更新。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值