gpt4 book ai didi

ios - 在 KIF 3.1.1 中如何比较来自 UI 的文本和从 Web 服务接收的文本?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:34 24 4
gpt4 key购买 nike

我想比较来自 UI 的文本和使用 KIF V3.0 从 WebService 获得的内容。我知道如何在 KIF 1.0 中进行比较,但我不知道如何在 KIF V3.0 中进行比较。

对于V1.0

+(id)stepToverifyOutput:(NSString *) expectedLabel accessibility:(NSString *)mylabel

{

NSString *description = [NSString stringWithFormat:@"Verify label text for %@",expectedLabel];
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
UIAccessibilityElement *element = [[UIApplication sharedApplication] accessibilityElementWithLabel:mylabel];

BOOL isValid;
UINavigationController *navbar;
UILabel *lblName;

if([element isKindOfClass:[UILabel class]]){
isValid=YES;
lblName = (UILabel *)[UIAccessibilityElement viewContainingAccessibilityElement:element];;
if ([expectedLabel isEqualToString:lblName.text]) {
return KIFTestStepResultSuccess;
}
}else{
isValid=NO;
navbar = (UINavigationController *)[UIAccessibilityElement viewContainingAccessibilityElement:element];;
if ([expectedLabel isEqualToString:navbar.title]) {
return KIFTestStepResultSuccess;
}
}
KIFTestCondition(NO, error, @"Failed to compare the label text: expected '%@', actual '%@'", expectedLabel,(isValid)?lblName.text:navbar.title);
}];

请为我做一些需要的事情。我被困在这个地方了。

最佳答案

KIF 的 [tester waitForViewWithAccessibilityLabel:myLabel] 方法返回实际 View 本身,然后您可以使用它来断言。例如:

NSString *accessibilityLabel = @"yourLabel";
NSString *expectedValue = @"whateveryouexpect";

UILabel *label = (UILabel*)[tester waitForViewWithAccessibilityLabel:accessibilityLabel];
XCTAssert([label.text isEqualToString:expectedValue], @"BADONKADONK");

您不需要为此运行整个步骤。这也具有更易读和直接的优势:获取标签,确保其文本值符合预期。如果找不到该值,那么测试自然会失败。

关于ios - 在 KIF 3.1.1 中如何比较来自 UI 的文本和从 Web 服务接收的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27862468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com