为了账号安全,请及时绑定邮箱和手机立即绑定

我的代码,希望老师帮忙看一下


#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];

}


正在回答

2 回答

老师帮我们看看什么问题???

0 回复 有任何疑惑可以回复我~

我和你一样的问题 自己参考老师的来写



XCUIApplication *app = [[XCUIApplication alloc] init];
    XCUIElementQuery *usernameElementsQuery = [app.otherElements containingType:XCUIElementTypeStaticText identifier:@"userName"];
    
    
    XCUIElement *textField = [[usernameElementsQuery childrenMatchingType:XCUIElementTypeTextField] elementBoundByIndex:0];
    [textField tap];
    [textField typeText:@"xiaoming"];
    
    XCUIElement *textField2 = [[usernameElementsQuery childrenMatchingType:XCUIElementTypeTextField] elementBoundByIndex:1];
    
    [textField2 tap];
    [textField2 tap];
    [textField2 typeText:@"123"];///同样是这里出问题
    [app.buttons[@"log"] tap];


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
iOS9新特性之UITesting
  • 参与学习       10940    人
  • 解答问题       12    个

iOS9新特性:不需要我们手指反复点击,完成APP自动化测试

进入课程

我的代码,希望老师帮忙看一下

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号