美文网首页iOS测试知识
UITest - Wait for app to idle

UITest - Wait for app to idle

作者: 双手插兜Jeff | 来源:发表于2016-11-09 15:02 被阅读374次

  最近在做真机UITest,趟了几个坑。这儿简单总结一下。
  首先,你要参考这篇文章,让你的代码可以UITest。
  http://www.jianshu.com/p/f4ba532caed0


  注意当你在已有项目里添加uitest target的时候,Podfile要记得添加target,并更新。
  今天的主角是!!!

t =    18.54s         Wait for app to idle

  进入我项目里的某个页面的时候,原先指定的点击事件不走了,并且停在打印完Wait for app to idle后就不走了。
  一网页里看到。
Perhaps you have some animation or some other background (or foreground) activity that updates your UI on the main thread frequently. This causes the app to never be "quiesce" - at least on this tab. In our application we had UIView animation with option Repeat. CPU usage was fine and it wasn't a battery drain, but it made the test fail every time. Disabling the animation fixed the issue. I couldn't find a way to force the test not to wait to be idle, so we ended up disabling the animation using #ifdef for the UI test target using runtime arguments as described here:
对照我的项目.知道原因了
  UITest 只会在 app 为 idle 的时候去走点击事件,但如果当前页面有其他动画(占据主线程),会导致 app 无法quiesce。点击事件就不会走,程序就一直在那里 Wait for app to idle。
  然后找了各种方法,都不能强制的去终止Wait for app to idle,比如Wait for app to idle持续5秒后强制走点击事件。无奈只能让动画停止,不去占据主线程了。如果一个 app 里只有一个动画,那还算好办,如果是多个那岂不是非常麻烦。
  其实在app开启的时候使所有的Animation失效就行了。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [UIView setAnimationsEnabled:NO];  //HERE
    return YES;
}

  问题算是解决了,但每次真实运行 app 都去注释掉这行,不是很麻烦?
  其实可以在程序启动前添加几个参数。这样,只有遇到testUI的时候,动画才会暂停。正常 app 运行的时候,动画并不会暂停。

- (void)testUI{
    XCUIApplication *app = [[XCUIApplication alloc]init];
    app.launchArguments = @[@"ResetDefaults", @"NoAnimations", @"UserHasRegistered"];
    [app launch];//程序启动
    
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    NSArray *arrayAPP = [[NSProcessInfo processInfo] arguments];
    //默认arguments就一个。当大于1,就说明该程序是通过testUI启动的。
    if (arrayAPP.count > 1) {
        [UIView setAnimationsEnabled:NO];
    }   
    return YES;
}

传送门:
http://stackoverflow.com/questions/33624650/xctestcase-wait-for-app-to-idle
http://stackoverflow.com/questions/32667201/accessing-the-host-app-code-from-the-xcode-7-ui-test-target/33466038#33466038
http://stackoverflow.com/questions/33624650/xctestcase-wait-for-app-to-idle

相关文章

  • UITest - Wait for app to idle

      最近在做真机UITest,趟了几个坑。这儿简单总结一下。  首先,你要参考这篇文章,让你的代码可以UITest...

  • UITest-wait app for idle

    UITest(XCUITest for iOS技术) 测试过程中会遇到wait for 【bundleID】to ...

  • JavaWeb之四——IO调优

    磁盘IO调优 网络I/O调优 磁盘IO调优 性能检测 注: IO wait= (cpu idle time)/(a...

  • iOS UITest记录一下

    对于UITest,相信能看到这篇文章的都已经知道UITest是做什么的了。但是我在网上找的有关UITest的文章,...

  • iOS 使用UnitTest和UITest进行自我测试

    1.添加UnitTest,UITest Xcode7开始,引进了包含UITest UnitTest的工具,你可以在...

  • 项目优化

    1. UITest & UnitTest 当开发完新需求的时候,在提测之前我们最好编写下UITest和UnitTe...

  • iOS中的UITest(界面测试)学习

    UITest是界面测试,主要用于测试界面。UITest是Xcode7.0之后苹果推出的,在此之前的测试主要是通过使...

  • Python3 运行方法和编辑器

    运行.py文件 运行环境:Mac软件:IDLE 方法/步骤 直接使用IDLE 可以直接在IDLE shell中编...

  • IDLE

    LDIE,通过键入文本与程序交互的途径。 可能你刚看到这个名词的时候会一脸懵逼,其实它就是被应用在程序...

  • 学唱歌学语音学表达-2月晨读笔记

    Day1 wait wait wait 1、all I do is(to) wait wait wait.属于断裂...

网友评论

  • LeepengX:加了这一行代码,使得几个第三方UI库(比如消息滚动条等频繁刷新的UI库)出现使用问题,因为动画没有成功回调吧,CPU从5%飙升到110%且高居不下。唉。

本文标题:UITest - Wait for app to idle

本文链接:https://www.haomeiwen.com/subject/wfzauttx.html