xcode UI test with xctest

xiaoxiao2021-02-28  85

在xcode建立UI test的target模块然后进行xcode的录制对录制的代码进行编辑“\U”改成“\u”进行回放查看错误信息 // 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
转载请注明原文地址: https://www.6miu.com/read-29259.html

最新回复(0)