p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #78492a }
span.s1 { }
Test Like a User!
- 演示自动化UI测试样例
演示秒到版,全流程一条线测试下来,注册--登录--实名认证--信用卡认证--添加收款器--刷卡收款
- 介绍KIF
KIF的全称是Keep it functional。它是一个建立在XCTest的UI测试框架,通过accessibility来定位具体的控件,来操作UI。
- 导入KIF
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #272ad8 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008400 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000 }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #ba2da2 }
span.s1 { color: #000000 }
span.s2 { }
span.s3 { font: 14.0px "PingFang SC" }
span.s4 { color: #ba2da2 }
span.s5 { color: #272ad8 }
target ‘会员宝秒到版Tests‘ do
# 3.5.2
pod ‘KIF‘, :configurations => [‘Debug‘]
end
- 写测试用例和讲解常用方法
UI组件给自己的accessibilityLabel属性赋值,例如:self.nameTextF.accessibilityLabel = @"nameTextF";
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #31595d }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000; min-height: 16.0px }
span.s1 { color: #000000 }
span.s2 { color: #78492a }
span.s3 { }
span.s4 { color: #d12f1b }
[tester tapViewWithAccessibilityLabel:@"liJiZhuCeBtn"];
[tester enterText:@"19902030220" intoViewWithAccessibilityLabel:@"phoneNumField"];
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #31595d }
span.s1 { color: #000000 }
span.s2 { color: #78492a }
span.s3 { }
span.s4 { color: #d12f1b }
span.s5 { font: 14.0px "PingFang SC"; color: #d12f1b }
[tester clearTextFromAndThenEnterText:@"邓超界" intoViewWithAccessibilityLabel:@"jieSuanZhangHuText"];
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #31595d }
span.s1 { color: #000000 }
span.s2 { color: #78492a }
span.s3 { }
span.s4 { color: #272ad8 }
span.s5 { color: #008400 }
span.s6 { font: 14.0px "PingFang SC"; color: #008400 }
[tester waitForTimeInterval:15];// 手动输入验证码
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #31595d }
span.s1 { color: #000000 }
span.s2 { color: #78492a }
span.s3 { }
span.s4 { color: #d12f1b }
[tester waitForViewWithAccessibilityLabel:@"dengLuVC"];
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #31595d }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000 }
span.s1 { color: #000000 }
span.s2 { color: #ba2da2 }
span.s3 { color: #78492a }
span.s4 { }
span.s5 { color: #d12f1b }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #31595d }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000 }
span.s1 { color: #000000 }
span.s2 { color: #ba2da2 }
span.s3 { color: #78492a }
span.s4 { }
span.s5 { color: #d12f1b }
if ([tester tryFindingTappableViewWithAccessibilityLabel:@"jumpButton" error:nil]) {
[tester tapViewWithAccessibilityLabel:@"jumpButton"];
}
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #31595d }
span.s1 { color: #000000 }
span.s2 { color: #78492a }
span.s3 { }
span.s4 { color: #d12f1b }
span.s5 { color: #703daa }
[tester enterText:@"0119" intoViewWithAccessibilityLabel:@"carddateField" traits:UIAccessibilityTraitNone expectedResult:@"01/19"];
- Tips
按钮的title、类的title,可以直接做为访问标签;textField的placeholder,可以做为访问标签,但不能改变值;
在屏幕是可以看到的,才可以访问。例如:注册按钮。
滚动视图,在屏幕不可视范围,可以响应点击。举例:实名认证中的提交审核按钮;
- 遇到的坑
pod ‘KIF‘, :configurations => [‘Debug‘]
pod ‘KIF/IdentifierTests‘#此处错误;
造成Target Support Files和Headers文件夹内文件丢失;
- 参考网址
http://www.cocoachina.com/ios/20170401/18995.html
http://www.oschina.net/translate/ios-ui-testing-with-kif
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #703daa }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #703daa }
span.s1 { color: #ba2da2 }
span.s2 { color: #000000 }
span.s3 { color: #4f8187 }
span.s4 { }
span.s5 { color: #d12f1b }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #703daa }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #703daa }
span.s1 { }