1.    [XCUIElement exists]方法只能确定这个View是否存在,即使不在当前屏幕上也返回True。如果要确定View是否在屏幕可见范围内,可以判断其Frame是否在Window的Frame内。

XCUIElement *window = [app.windows elementBoundByIndex:0];
     if (CGRectContainsRect([window frame], [cell frame])) {
         [cell tap];
     }

2.  等待一个控件出现的方法(登录结果,是否已经跳转到另一个VC)
      

左边的VC点击确定会跳转到右边的VC
    XCUIElement *alertView = app.alerts.collectionViews.buttons[@"确定"];
    if ([alertView exists]) {
        XCTAssertTrue([app.alerts.staticTexts[@"登录成功"] exists]);
        XCUIElement *nextVC = app.staticTexts[@"B"];
       
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"exists == true"];
       
        [self expectationForPredicate:predicate evaluatedWithObject:nextVC handler:nil];
       
        [alertView tap];
       
        [self waitForExpectationsWithTimeout:5 handler:nil];    //最多等待5秒直到B出现
       
        XCTAssertTrue([app.staticTexts[@"B"] exists]);
    }

3.  查看Query的过程
   使用打印方法查看[XCUIElement(Query) debugDescription]。可以从DebugDescription中识别控件的Bounds属性识别控件,如下:

4.  获得TableView的自带控件

XCUIElement *prepareDelete = app.buttons[@"Delete 1"];
   [prepareDelete tap]; //点击左侧编辑按钮
       
   XCUIElement *delete = app.buttons[@"Delete"];
   [delete tap]; //点击左滑出的Delete按钮(可能不叫Delete)

XCUIElement *reorder = app.buttons[@"Reorder 1"];     //第一个Cell的重排按钮(名称为Reorder和具体数据)
   XCUIElement *reorder2 = app.buttons[@"Reorder 2"];     //第二个cell的重排按钮
   [reorder pressForDuration:1 thenDragToElement:reorder2]; //将第一个Cell移动到第二个Cell

5.  如何滑动刷新

滑动刷新的就是实现足够距离的滑动操作。

实现方式主要是两种:

1.从屏幕上取两个点进行滑动

2.调用可滑动页面内的控件的[SwipeUp/Down]方法。

例子:

1. 取点滑动

XCUIElement *cell = [app.tables.cells elementBoundByIndex:0]; //最上方的Cell
   XCUICoordinate *start = [cell coordinateWithNormalizedOffset:CGVectorMake(0, 0)];
   XCUICoordinate *end = [cell coordinateWithNormalizedOffset:CGVectorMake(0, 6)]; //屏幕外一个点,dy=6据说是刷新要求的最小值
   [start pressForDuration:0 thenDragToCoordinate:end];

2. Swipe

XCUIElement *table = [app.tables elementBoundByIndex:0];

[table swipeUp];

PS:对自身不可滑动控件进行Swipe滑动,若控件在可滑动控件内,会导致这个可滑动控件滑动。如上滑TableviewCell会使其Tableview上滑。

6.  按动硬件按钮的方法
    XCUIDevice *device = [XCUIDevice sharedDevice];
    [device pressButton:XCUIDeviceButtonHome]; //枚举只有三个值 Home键,音量Up,音量Down(模拟器只能按Home键)

7.  点击被遮挡控件的方法

XCUIElement *cell = [collectView.cells elementBoundByIndex:i];
    if ([cell isHittable]) {
      [cell tap];
    } else {
      XCUICoordinate *coo = [cell coordinateWithNormalizedOffset:CGVectorMake(0, 0)];
      [coo tap];
    }
  PS:只能用点点击时,若点在屏幕外,目前只会出现滑动操作。

最新文章

  1. Android开发笔记之《知识漏点纪录与学习》
  2. .Net平台下,分布式文件存储的实现
  3. C++ 中 ZeroMemory、memset 危险需慎用
  4. eclipse新建项目,报错“Error: workspace\appcompat_v7\res\values-v21\styles_base.xml No resource found that matches the given name”
  5. struts 标签<s:ierator>的简单使用说明
  6. 一个php类 Autoloader
  7. 【制作镜像Win*】特殊配置
  8. Conversion Between DataTable and List in C#
  9. 使用awrextr.sql导出awr原始数据
  10. XMLHTTP请求的当前状态
  11. FineUIMvc随笔(1)动态创建表格列
  12. 微信小程序跳转小程序
  13. Beta冲刺——第一天
  14. linux基础学习之软件安装以及常用命令
  15. 学习笔记46—如何使Word和EndNote关联
  16. python 优雅地实现插件架构
  17. 超全面的JavaWeb笔记day13<JSTL&自定义标签>
  18. 基于Vue的WebApp项目开发(三)
  19. vue2.0做移动端开发用到的相关插件和经验总结
  20. Android常用传感器用法一览(3)

热门文章

  1. Java类加载器(ClassLoader)
  2. 贞鱼传教&&贞鱼传教(数据加强版)
  3. 关于animate的一些属性
  4. Android设备adb授权的原理【转】
  5. 数据结构之 图论---基于邻接矩阵的广度优先搜索遍历(输出bfs遍历序列)
  6. iOS在一个label中显示不同颜色的字体
  7. wukong引擎源码分析之搜索——docid有序的数组里二分归并求交集,如果用跳表的话,在插入索引时会更快
  8. HBase集群出现NotServingRegionException问题的排查及解决方法
  9. Watir 能够为你做什么?
  10. C++ 下啥时候用struct, 啥时候用class