iOSUI自动化测试

564 阅读1分钟
#import <XCTest/XCTest.h>

@interface SunReadingUITests : XCTestCase

@end

@implementation SunReadingUITests

- (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 {
//    
//    XCUIApplication *app = [[XCUIApplication alloc] init];
//    XCUIElementQuery *cellsQuery = app.collectionViews.cells;
//    [[cellsQuery.otherElements containingType:XCUIElementTypeStaticText identifier:@"\U6d4b\U8bd5png"].images[@"MyExperience_Plance"] tap];
//    [app.navigationBars[@"\U56fe\U4e66\U8be6\U60c5"].buttons[@"backbt white"] tap];
//    [[[[cellsQuery.otherElements containingType:XCUIElementTypeStaticText identifier:@"365\U591c\U8d85\U5947\U5999\U4e2d\U56fd\U795e\U8bdd\U6545\U4e8b"] childrenMatchingType:XCUIElementTypeImage] elementBoundByIndex:0] tap];
//    [[[[[[[[[[[[[[[[[app childrenMatchingType:XCUIElementTypeWindow] elementBoundByIndex:0] childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:2] childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther].element tap];
//    
//    XCUIElement *image = [app.scrollViews childrenMatchingType:XCUIElementTypeImage].element;
//    [image tap];
//    [image swipeLeft];
//    
//    XCUIElement *element = [[[app childrenMatchingType:XCUIElementTypeOther].element childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:1];
//    [[[element childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:1] swipeLeft];
//    
//    XCUIElement *alert = app.alerts[@"\U63d0\U793a"];
//    [alert.buttons[@"\U8fd4\U56de\U9996\U9875"] tap];
//    [image swipeRight];
//    [image swipeRight];
//    [image swipeRight];
//    [image swipeLeft];
//    [element swipeLeft];
//    [alert.buttons[@"\U9000\U51fa"] tap];
    
    XCUIApplication *app = [[XCUIApplication alloc] init];
    XCUIElement *button = app.tabBars.buttons[@"我的"];
    [button tap];
    [button tap];
    
    XCUIElementQuery *tablesQuery = app.tables;
    [tablesQuery/*@START_MENU_TOKEN@*/.staticTexts[@"我的阅历"]/*[[".cells.staticTexts[@\"\我\的\阅\历\"]",".staticTexts[@\"\我\的\阅\历\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ tap];
    [tablesQuery/*@START_MENU_TOKEN@*/.staticTexts[@"培养学生爱心的动物故事:拔羽救子"]/*[[".cells.staticTexts[@\"\培\养\学\生\爱\心\的\动\物\故\事\:\拔\羽\救\子\"]",".staticTexts[@\"\培\养\学\生\爱\心\的\动\物\故\事\:\拔\羽\救\子\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ tap];
    [app.navigationBars[@"我的阅历"].buttons[@"backbt white"] tap];
    [[app.tables containingType:XCUIElementTypeStaticText identifier:@"李莎同学"].element tap];

    // 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.
}

@end