我有一個咖啡測試,其中我的屏幕包含EditText
和跳過Button
下面。 當我啓動活動時,鍵盤會彈出,重點在EditText
,並與Button
重疊。
我現在想寫一個跳過按鈕的測試,並斷言之後會發生什麼。意式咖啡並不等待鍵盤打開
問題在於espresso不會等待鍵盤打開。
所以會發生什麼是
- 咖啡不是等待鍵盤,並按下「跳過」
- 鍵盤滑開
- 斷言的東西,現在這就是下面的鍵盤出現故障
代碼看起來像這樣:
public void givenSkipped_whenConfirmed_thenMainActivityLaunched() {
Espresso.closeSoftKeyboard();// <- Not working as espresso seems to think it is not open yet
skipPostcodeEntry.perform(click()); //<- Can click this as keyboard is not open yet.
warningText.check(matches(withText(R.string.some_text)));
confirmationButton.perform(click());//<- Fails as this is now overlapped by KB
Assert.DoesSomething()
}
我發現咖啡是not waiting for the keyboard to close的問題,但沒有等待鍵盤打開。
有沒有人解決過這個問題?
編輯:
當你看看closeSoftKeyboard
方法,你可以找到一個名爲CloseKeyboardAction
類。當鍵盤未被識別爲打開時,您可以看到它甚至會記錄下來。
Log.w(TAG, "Attempting to close soft keyboard, while it is not shown.");