如何使用UIAutomation进行iOS自动化测试(Part II)

发表于:2013-4-03 10:26

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:知平软件    来源:51Testing软件测试网采编

分享:

  多任务

  测试你的应用程序的多任务是非常容易的事:假设你想测试每次启动一个疯狂的后台进程,将程序放到后台执行,并进入(void)applicationWillEnterForeground:(UIApplication *)application选择器代码段,你可以通过下面的代码来将它推至后台,然后等待10秒后自动返回活动状态。.

  UIATarget.localTarget().deactivateAppForDuration(10);

  deactivateAppForDuration(duration) 方法会暂停测试脚本的执行,模拟用户点击Home按钮,(即将程序放到后台),等待,然后为你重新激活程序和测试脚本,就这么一行代码而已!

  屏幕方向

  最后,你可以模拟你的iPhone的旋转方向。也是很直观很简单:

var target = UIATarget.localTarget();
var app = target.frontMostApp();
// set landscape left
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT);
UIALogger.logMessage("Current orientation is " + app.interfaceOrientation());
// portrait
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);
UIALogger.logMessage("Current orientation is " + app.interfaceOrientation());

  5、总结

  有用的链接

  这篇文章有点儿长,但我希望你们能见识到UIAutomation是很强大的,且你的应用程序是可以得到质量的保障的。网上没有太多的UIAutomation的资料,但我还是列出了很多链接,也许能帮到你。

  ● http://cocoamanifest.net/articles/2011/05/uiautomation-an-introduction.html,http://cocoamanifest.net/articles/2011/07/ui-automation-part-2-assertions-and-imports.html 和 http://cocoamanifest.net/articles/2011/11/changes-to-ui-automation-in-ios-5.html: 非常好的UIAutomation系列的文章

  ● http://mobilecoder.wordpress.com/2010/11/08/iphoneipodipad-automation-basics: 非常不错的UIAutomation教程,值得阅读!

  ● http://www.juddsolutions.com/downloads/UnitAndFunctionalTestingForiOSPlatform.pdf: 很高深的单元测试和UI自动化测试的介绍。第70页里提到的“当遇到问题时,加上UIATarget.delay(1);!”会让你收获很大的。

  ● http://guerratopia.com/en/introduction-to-automating-ui-testing-in-ios: 非常好的介绍教程

  ● http://jojitsoriano.wordpress.com/2011/06/03/references-on-unit-testing-ui-automation-for-ios-applications: 很多关于单元测试和UI自动化测试的链接

  当然还有:

  ● Apple documentation on UIAutomation

  ● UIAutomation in Apple Instruments documentation

  ● WWDC 2010 - Session 306 - Automating User Interface Testing with Instruments

  你需要一个免费的开发者账号去访问这些资源。

44/4<1234
100家互联网大公司java笔试题汇总,填问卷领取~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号