Ich mache eine UI Unit Testing. In dem Bild.
Sie sind UILabels außer lange Beschreibung, die UITextView ist.
In der Seite möchte ich Assert Test den Wert in der Antwort.
Für die Antwort in der UILabels sind in Ordnung. Ich kann folgen Xcode UI Test example
Die Methode ist ziemlich einfach zu folgen, tippen Sie einfach auf das Element und ändern Sie die Methode von .tap()
zu .exist()
Dann legen Sie es durch assert()
;
Mein Problem ist UITextView
ist komplizierter als UILabel
.
Wie kann ich den Wert von UITextView
bekommen, um Assert-Check zu tun?Wie TextView Wert in XCode7 iOS9 geltend machen?
func testG(){
let app = XCUIApplication()
app.launch();
app.buttons["Enter"].tap()
app.tables.staticTexts["Bee"].tap()
assert(app.scrollViews.staticTexts["Name :"].exists);
assert(app.scrollViews.staticTexts["Age :"].exists);
assert(app.scrollViews.staticTexts["Specialty :"].exists);
assert(app.scrollViews.staticTexts["Description :"].exists);
assert(app.scrollViews.staticTexts["Bee"].exists);
assert(app.scrollViews.staticTexts["11"].exists);
assert(app.scrollViews.staticTexts["Sky Diver"].exists);
let text = "Bees are flying insects closely related to wasps and ants, known for their role in pollination and, in the case of the best-known bee species, the European honey bee, for producing honey and beeswax. Bees are a monophyletic lineage within the superfamily Apoidea, presently considered as a clade Anthophila. There are nearly 20,000 known species of bees in seven to nine recognized families,[1] though many are undescribed and the actual number is probably higher. They are found on every continent except Antarctica, in every habitat on the planet that contains insect-pollinated flowering plants.EOF";
assert(app.scrollViews.childrenMatchingType(.TextView).element.exists);
}
Haben Sie versucht, den 'Wert' zu lesen? http://masilotti.com/xctest-documentation/Protocols/XCUIElementAttributes.html#//api/name/value – dasdom
@dasdom. Danke für Ihre Antwort. Ich gebe den Wert entsprechend Ihrer Antwort an. Jetzt kann ich Assertion durch 'XCTAssertEqual (app.scrollViews.childrenMatchingType (.TextView) .element.value als? String, Text)' – Sarit
Dies sollte als Antwort auf diese Frage hinzugefügt werden. Es hat für mich funktioniert. – moliveira