- 在xcode建立UI test的target模块
- 然后进行xcode的录制
- 对录制的代码进行编辑“\U”改成“\u”
- 进行回放
- 查看错误信息
#import <XCTest/XCTest.h>
@interface LoginTest : XCTestCase
@end
@implementation LoginTest
- (void)setUp {
[super setUp];
self.continueAfterFailure = NO;
[[[XCUIApplication alloc] init] launch];
}
- (void)tearDown {
[super tearDown];
}
- (void)testExample {
[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