2015-09-09 6 views
5

私はUIユニットテストを行っています。写真の中の。
UITextViewである長い説明以外のUILabelsです。
私はアサルトをしたいページで答えの値をテストします。

UILabelsの答えは問題ありません。私はそれに従うことができますXcode UI Test example
方法は非常に簡単に要素をタップし、.tap()から.exist()へのメソッドをタップするassert()で囲う;

私の問題はUITextViewUILabelより複雑です。
アサートチェックを行うには、どうすればUITextViewの値を取得できますか?XCode7 iOS9でTextView値をアサートする方法は?

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

関連する問題