2015-09-09 16 views
5

मैं यूआई यूनिट परीक्षण कर रहा हूं। चित्र में।
वे लंबे विवरण को छोड़कर UILabels हैं जो UITextView है।
पृष्ठ में मैं जवाब में मूल्य का परीक्षण करना चाहता हूं।

UILabels में उत्तर ठीक है। मैं Xcode UI Test example
विधि का पालन करना बहुत आसान है, बस तत्व पर टैप करें और .tap() से .exist() से विधि बदलें, फिर assert() द्वारा इसे संलग्न करें;

मेरी समस्या UITextViewUILabel से अधिक जटिल है।
जोर देने के लिए मुझे UITextView का मूल्य कैसे प्राप्त हो सकता है?एक्सकोड 7 आईओएस 9 में टेक्स्ट व्यू मान कैसे डालें?

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); 
} 

UI with scrollbar

+1

क्या आपने 'value' को पढ़ने का प्रयास किया था? http://masilotti.com/xctest-documentation/Protocols/XCUIElementAttributes.html#//api/name/value – dasdom

+1

@dasdom। आपके जवाब के लिए धन्यवाद। मैंने मूल्य को आपके उत्तर के अनुसार रखा है। अब मैं 'XCTAssertEqual (app.scrollViews.childrenMatchingType (.TextView) .element.value के रूप में दावा कर सकता हूं? स्ट्रिंग, टेक्स्ट)' – Sarit

+1

इसे इस प्रश्न के उत्तर के रूप में जोड़ा जाना चाहिए। यह मेरे लिए काम किया। – moliveira

उत्तर

1

किसी और मामले किसी को भी इस सवाल पाता है, मैं

app.textViews.element.value as? String 

का उपयोग करके एक UITextView के पाठ प्राप्त करने में सक्षम हूँ यह वहाँ समय में स्क्रीन पर केवल एक ही पाठ दृश्य है मान लिया गया है।

1
XCTAssert(app.scrollViews.staticTexts[text].exists, "Didn't find the text!") 

पर विश्वास मत करो, ताकि आप केवल बात पर जोर देना है कि यह वहाँ होगा तुम यहाँ मूल्य मिल सकता है। यदि यह एक टेक्स्ट फ़ील्ड था तो आपको value प्राप्त करने का एक शानदार तरीका होगा।

+1

वाह। आपके जवाब के लिए धन्यवाद। यह मेरी तुलना में साफ दिखता है। अगर मुझे फिर से मेरे प्रश्न की तरह एक समस्या मिली है। मैं आपके उत्तर का पालन करूंगा। – Sarit

+0

मैंने इस तरह से कोशिश की और यह मेरे लिए काम नहीं किया। उपरोक्त टिप्पणियों में जवाब, हालांकि, काम करता है। ऊपर दिए गए उदाहरण और मेरे उपयोग के मामले के बीच एकमात्र अंतर यह है कि मेरा UITextView एक UIContainerView में एम्बेड किया गया है। – moliveira

संबंधित मुद्दे