Macos 如何在Xcode 7中的UITest期间获取文本字段的值?

Macos 如何在Xcode 7中的UITest期间获取文本字段的值?,macos,xcode7,xcode-ui-testing,Macos,Xcode7,Xcode Ui Testing,我想在Mac电脑上测试一个简单的摄氏-华氏转换器。我正在运行macOS Sierra和Xcode 7.2.1 当我运行以下测试时 - (void)testExample2 { XCUIApplication *app = [[XCUIApplication alloc] init]; XCUIElement *cfWindow = app.windows[@"Celsius Fahrenheit Converter"]; XCUIElement *textField1

我想在Mac电脑上测试一个简单的摄氏-华氏转换器。我正在运行macOS Sierra和Xcode 7.2.1

当我运行以下测试时

- (void)testExample2 {
    XCUIApplication *app = [[XCUIApplication alloc] init];
    XCUIElement *cfWindow = app.windows[@"Celsius Fahrenheit Converter"];

    XCUIElement *textField1 = [[cfWindow childrenMatchingType:XCUIElementTypeTextField]elementBoundByIndex:0];

    XCUIElement *textField2 = app.textFields[@"fahrField"];

    [textField1 typeText:@"21\r"];

    NSString *str = (NSString *) textField2.value;

    XCTAssertEqual(str, @"69.8");
}
我基本上是在“摄氏度”字段中输入值21,并期望在“华氏度”字段中得到值69.8。但是我得到了错误信息

测试失败:-[CFConverterUITests testExample2]失败:((str)等于(@“69.8”))失败:(“”)不等于(“”


有人知道哪里出了问题,该怎么办吗?

xctasertequal对对象不起作用。您的断言应该是
xctasert([str isEqualToString:@“69.8]”)

xctasertequal对对象不起作用。您的断言应该是
xctasert([str isEqualToString:@“69.8]”)