我的代码,希望老师帮忙看一下
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameTextF;
@property (weak, nonatomic) IBOutlet UITextField *pwdTextF;
@end
@implementation ViewController
- (IBAction)loginBtn:(id)sender {
[self cheakLogin];
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)cheakLogin
{
if ([self.nameTextF.text isEqualToString:@"xiaoming"]&&[self.pwdTextF.text isEqualToString:@"abc"]) {
UIViewController *VC = [[UIViewController alloc]init];
[self presentViewController:VC animated:YES completion:nil];
}else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"tip" message:@"Login faid" delegate:nil cancelButtonTitle:@"cancle" otherButtonTitles:@"sure", nil];
[alert show];
}
}
@end
#pragma clang diagnostic pop
- (void)testExample {
[self customTest];
}
/**
* 自己写的崩溃在55行,怀疑是键盘中,无法输入123,但是测试换成abc还是不行
*/
- (void)customTest
{
// 创建一个app
XCUIApplication *app = [[XCUIApplication alloc] init];
//在页面中查找带测试的元素
XCUIElementQuery *nameElementsQuery = [app.otherElements containingType:XCUIElementTypeStaticText identifier:@"name:"];
//给元素设定输入
XCUIElement *textField = [[nameElementsQuery childrenMatchingType:XCUIElementTypeTextField] elementBoundByIndex:0];
[textField tap];
[textField typeText:@"xiaoming"];
XCUIElement *textField2 = [[nameElementsQuery childrenMatchingType:XCUIElementTypeTextField] elementBoundByIndex:1];
[textField2 tap];
[textField2 tap];
[textField2 typeText:@"abc"];
[app.buttons[@"login"] tap];
XCTAssertEqual(app.alerts.count,0);
}
/**
* 系统自动录制出来的,基本无发使用~~~
*/
- (void)sysRecodeTest{
// XCUIApplication *app = [[XCUIApplication alloc] init];
// XCUIElementQuery *nameElementsQuery = [app.otherElements containingType:XCUIElementTypeStaticText identifier:@"name:"];
// [[[nameElementsQuery childrenMatchingType:XCUIElementTypeTextField] elementBoundByIndex:0] tap];
// [[nameElementsQuery childrenMatchingType:XCUIElementTypeTextField] elementBoundByIndex:0]
// [app.otherElements[@"\U201cxiaoming\U201d"] tap];
//
// XCUIElement *textField = [[nameElementsQuery childrenMatchingType:XCUIElementTypeTextField] elementBoundByIndex:1];
// [textField tap];
// [textField tap];
//
// XCUIElement *moreNumbersKey = app.keys[@"more, numbers"];
// [moreNumbersKey tap];
// [moreNumbersKey tap];
// [[nameElementsQuery childrenMatchingType:XCUIElementTypeTextField] elementBoundByIndex:1]
// [app.buttons[@"login"] tap];
// [textField tap];
// [[[[app childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:1] tap];
// [app.alerts[@"tip"].collectionViews.buttons[@"cancle"] tap];
}