এক্সকোড 9 এক্সসিটিওয়াইটারের
সাথে নতুন কৌশলগুলি প্রবর্তন করেছে
পরীক্ষার কেস স্পষ্টভাবে অপেক্ষা করে
wait(for: [documentExpectation], timeout: 10)
ওয়েটার উদাহরণ পরীক্ষা করার জন্য প্রতিনিধি
XCTWaiter(delegate: self).wait(for: [documentExpectation], timeout: 10)
ওয়েটার ক্লাসের ফলাফল ফলাফল
let result = XCTWaiter.wait(for: [documentExpectation], timeout: 10)
switch(result) {
case .completed:
//all expectations were fulfilled before timeout!
case .timedOut:
//timed out before all of its expectations were fulfilled
case .incorrectOrder:
//expectations were not fulfilled in the required order
case .invertedFulfillment:
//an inverted expectation was fulfilled
case .interrupted:
//waiter was interrupted before completed or timedOut
}
এক্সকোড 9 এর আগে
উদ্দেশ্য গ
- (void)waitForElementToAppear:(XCUIElement *)element withTimeout:(NSTimeInterval)timeout
{
NSUInteger line = __LINE__;
NSString *file = [NSString stringWithUTF8String:__FILE__];
NSPredicate *existsPredicate = [NSPredicate predicateWithFormat:@"exists == true"];
[self expectationForPredicate:existsPredicate evaluatedWithObject:element handler:nil];
[self waitForExpectationsWithTimeout:timeout handler:^(NSError * _Nullable error) {
if (error != nil) {
NSString *message = [NSString stringWithFormat:@"Failed to find %@ after %f seconds",element,timeout];
[self recordFailureWithDescription:message inFile:file atLine:line expected:YES];
}
}];
}
, USAGE
XCUIElement *element = app.staticTexts["Name of your element"];
[self waitForElementToAppear:element withTimeout:5];
দ্রুতগতি
func waitForElementToAppear(element: XCUIElement, timeout: NSTimeInterval = 5, file: String = #file, line: UInt = #line) {
let existsPredicate = NSPredicate(format: "exists == true")
expectationForPredicate(existsPredicate,
evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(timeout) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after \(timeout) seconds."
self.recordFailureWithDescription(message, inFile: file, atLine: line, expected: true)
}
}
}
, USAGE
let element = app.staticTexts["Name of your element"]
self.waitForElementToAppear(element)
অথবা
let element = app.staticTexts["Name of your element"]
self.waitForElementToAppear(element, timeout: 10)
উৎস
NSThread.sleepForTimeInterval(1)
কাজ করা উচিত