นี่คือสิ่งที่ฉันมีจนถึงตอนนี้ และฉันแค่พยายามรับผลลัพธ์ที่ส่งออกในป้ายกำกับ และทดสอบกับผลลัพธ์ที่ตั้งไว้:
func testExample() {
let app = XCUIApplication()
let enterRomanNumeralsHereTextField = app.textFields["Enter roman numerals here"]
enterRomanNumeralsHereTextField.tap()
let convertButton = app.buttons["Convert"]
//1
enterRomanNumeralsHereTextField.typeText("LL")
convertButton.tap()
XCTAssertTrue(app.staticTexts.element(matching:.any, identifier: "Roman Numerals").label == "NotValidRomanNumber")
//2
enterRomanNumeralsHereTextField.typeText("LXXXIX")
convertButton.tap()
XCTAssertEqual(app.otherElements.containing(.staticText, identifier:"Roman Numerals").element.value as! String, "89")
//3
enterRomanNumeralsHereTextField.typeText("")
enterRomanNumeralsHereTextField.typeText("LXXVIII")
convertButton.tap()
XCTAssertEqual(app.otherElements.containing(.staticText, identifier:"Roman Numerals").element.value as! String, "")
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
ความพยายามครั้งแรก (ป้ายกำกับ 1) ทำให้ฉันเกิดข้อผิดพลาดในการสร้างโดยบอกว่า "ไม่สามารถเรียกค่าของประเภทที่ไม่ใช่ฟังก์ชัน XCUIElement ได้ ความพยายามครั้งที่สองสร้างขึ้น แต่การทดสอบล้มเหลวเพราะแม้ว่าฉลากจะสร้างค่าที่ถูกต้องจริง ๆ แต่การทดสอบก็อ่านฉลากเป็น ว่างเปล่า ซึ่งนำเราไปสู่ความพยายามครั้งที่สามของฉันซึ่งผ่านการทดสอบเพราะฉันเปรียบเทียบกับฉลากเปล่าซึ่งเป็นสิ่งที่แสดงให้เห็น
อย่างที่บอกไปข้างต้น ฉันแค่สงสัยว่าจะดึงค่าป้ายกำกับที่เป็นผลมาจาก "การคำนวณ" หรือการกดปุ่มได้อย่างไร