xcode UI test with xctest

  1. 在xcode建立UI test的target模块
  2. 然后进行xcode的录制
  3. 对录制的代码进行编辑“\U”改成“\u”
  4. 进行回放
  5. 查看错误信息
//  LoginTest.m
//  ettAiXuePaiNextGen
//
//  Created by mff on 2017/7/10.
//  Copyright © 2017年 Etiantian. All rights reserved.
//

#import <XCTest/XCTest.h>

@interface LoginTest : XCTestCase

@end

@implementation LoginTest

- (void)setUp {
    [super setUp];

    // Put setup code here. This method is called before the invocation of each test method in the class.

    // In UI tests it is usually best to stop immediately when a failure occurs.
    self.continueAfterFailure = NO;
    // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
    [[[XCUIApplication alloc] init] launch];

    // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testExample {
    // Use recording to get started writing UI tests.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
    [XCUIDevice sharedDevice].orientation = UIDeviceOrientationLandscapeLeft;
    [XCUIDevice sharedDevice].orientation = UIDeviceOrientationLandscapeLeft;

    XCUIApplication *app = [[XCUIApplication alloc] init];

    //输入用户名
    XCUIElement *textField = [[XCUIApplication alloc] init].textFields[@"\u8bf7\u8f93\u5165\u7231\u5b66\u6d3e\u8d26\u53f7"];
    [textField tap];
    [textField typeText:@"爱学派MFF"];
    //输入密码
    XCUIElement *element = [[[[[[[app childrenMatchingType:XCUIElementTypeWindow] elementBoundByIndex:0] childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:1];
    [[[element childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:0] tap];

    [[[element childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:1] tap];
    [app typeText:@"1111"];
    [[[element childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:0] tap];
    //点击登录
    [[[XCUIApplication alloc] init].staticTexts[@"登录"] tap];
    //断言是否成功
    XCTAssertTrue(@"请选择上课班级", @"登录失败");
}

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值