IOS无线客户端自动化测试

发表于:2014-7-02 11:18

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

 作者:邓伟    来源:51Testing软件测试网采编

  做IOS自动化的过程中,会遇到两个问题,需要开发对代码的支持。
  1. 用instruments总是会获取不到一些UI元素
  2. 客户端中没有固定的ID供测试代码来确定页面元素。然后只能通过target.frontMostApp().mainWindow().scrollViews()[0].tableViews()[0].cells()[0].tap(); 这样的方式来定位元素。
  第一个问题产生的原因是在客户端开发的过程,需要自定义大量的UIView来满足需求。这些UI有两种构建方式,
  1. 用原生的UI组件来拼接
  2. 通过一些自己来画
  instruments 是通过元素的isAccessibilityElement属性来判定元素是否可见。
  解决方案:
  1. 原生的UI组件的isAccessibilityElement默认是YES的。自定义的UI组件的isAccessibilityElement属性是NO,当isAccessibilityElement为NO时,instruments将无法捕获。而且苹果的UI还有覆盖性之说,所以这种情况,我们需要将自定义的 UI的子UI的isAccessibilityElement属性置为YES,而不是自定义的UI本身,instruments就能获取到。
  如
@interface SNCommentHeaderView : UIView
{
UIImageView    *headerBgView;
UILabel        *titleLabel;
}
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"SNCommentHeaderView_init");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
headerBgView = [[UIImageView alloc] initWithImage:[UIImage skinImageNamed:@"comment_sectionheader_title_bg.png"]];
CGRect bgFrame = headerBgView.frame;
bgFrame.origin.y = 10;
headerBgView.frame = bgFrame;
headerBgView.isAccessibilityElement = YES;
[self addSubview:headerBgView];
titleLabel = [[UILabel alloc] initWithFrame:UIEdgeInsetsInsetRect(bgFrame, UIEdgeInsetsMake(0, 0, 1.5, 0))];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont fontWithName:BOLD_FONT_NAME size:12];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.textColor = [UIColor skinColorForKey:SNSkinCommentSectionHeaderColor];
titleLabel.isAccessibilityElement = YES;
[self addSubview:titleLabel];
}
return self;
}
  2. 非原生控件成的UI,instruments暂时是不支持获取的。在苹果官方文档中又一套非正式的创建自定义UI的方式。针对这种情况,只能通过去定位他的父节点定位了。如果需要验证的话,可以将自定义UI的内容通过设置accessibilityIdentifier或者accessibilityLabel,然后通过父节点取得值来验证。
  做IOS自动化,只能通过target.frontMostApp().mainWindow().scrollViews()[0].tableViews()[0].cells()[0].tap(); 这样来定位坐标是个很原始的方式,而且需要变化比较快,一旦UI方式改变,case会受到很大的影响。所以假使在源码中通过对一些比较固定或case中功能点的元素设置accessibilityIdentifier,然后脚本可以通过这accessibilityIdentifier来定位元素,可以大大减少自动化脚本的维护成本,也可大大提高开发速度。
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号