我编写了5个UITests,每个UITests都与应用程序中的不同部分进行交互。其中3人点按了UIButton
的标题标题中的UITableView
。第一部分是第一部分的标题,第二部分是第二部分,依此类推。当我单独运行它们时,它们会通过。当我运行所有测试时,它们会失败。
- (void)testFirst {
XCUIElement *table = self.app.tables.allElementsBoundByIndex[0];
[[[self.app.tables.otherElements containingType:XCUIElementTypeStaticText identifier:@"Table"] childrenMatchingType:XCUIElementTypeButton].element tap];
sleep(3);
XCUIElement *titleField = self.app.textFields[@"Name"];
[UIPasteboard generalPasteboard].string = @"testName";
[titleField doubleTap];
[self.app.menuItems[@"Paste"] tap];
}
- (void)testSecond {
XCUIElement *table = self.app.tables.allElementsBoundByIndex[0];
[[[self.app.tables.otherElements containingType:XCUIElementTypeStaticText identifier:@"Chair"] childrenMatchingType:XCUIElementTypeButton].element tap];
sleep(3);
XCUIElement *titleField = self.app.textFields[@"Name"];
[UIPasteboard generalPasteboard].string = @"testName";
[titleField doubleTap];
[self.app.menuItems[@"Paste"] tap];
}
- (void)testThird {
XCUIElement *table = self.app.tables.allElementsBoundByIndex[0];
[[[self.app.tables.otherElements containingType:XCUIElementTypeStaticText identifier:@"Guy"] childrenMatchingType:XCUIElementTypeButton].element tap];
sleep(3);
XCUIElement *titleField = self.app.textFields[@"Name"];
[UIPasteboard generalPasteboard].string = @"testName";
[titleField doubleTap];
[self.app.menuItems[@"Paste"] tap];
}
正如我所说,当我单独运行其中一个时,它们会通过。但是当我全部运行它们时,其中2个或全部3个将在[self.app.menuItems[@"Paste"] tap];
或[titleField doubleTap];
上失败。我几个小时都在沉溺于此。关于导致这种情况的任何想法?
编辑:我添加了setUp
和tearDown
方法。
- (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.
// 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.
self.app = [[XCUIApplication alloc] init];
self.snapshot = [[SnapshotHelper alloc] init];
[self.snapshot setupSnapshot:self.app];
[self.app launch];
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}