Espresso를 사용하여 다이얼로그가 표시되는지 확인하는 방법
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Check if a dialog is displayed with Espresso
Espresso를 사용하여 다이얼로그가 표시되는지 확인하는 방법
문제 내용
I'm trying to write some tests with the new android-test-kit (Espresso). But I can't find any information on how to check if a dialog is displayed and perform some actions on it (like clicking the positive and negative buttons, e.t.c.). Note that a dialog may be also displayed by a WebView
, not by the application it self.
저는 새로운 android-test-kit (Espresso)를 사용하여 몇 가지 테스트를 작성하려고 합니다. 그러나 다이얼로그가 표시되었는지 확인하고 양수 및 음수 버튼을 클릭하는 등 일부 작업을 수행하는 방법에 대한 정보를 찾을 수 없습니다. 참고로 다이얼로그는 애플리케이션 자체가 아닌 WebView에서도 표시될 수 있습니다.
Any help would be appreciated. I just need a link, or some example code for the basics:
아무런 도움이나 예제 코드가 있으면 감사하겠습니다. 기본적인 내용은 다음과 같습니다:
- Check if a dialog appears
- Perform clicks on dialog buttons
- Interact with the dialog's inner view (if it's a custom view)
- Preform clicks outside the dialog, and check if it's displaying or not (for example if
setCancelable(false)
was called on the dialog builder and we want to check that)
1. 다이얼로그가 표시되는지 확인합니다.
2. 다이얼로그 버튼을 클릭합니다.
3. 다이얼로그의 내부 뷰와 상호 작용합니다(사용자 정의 뷰인 경우).
4. 다이얼로그 외부를 클릭하고 표시되는지 확인합니다(다이얼로그 빌더에서 setCancelable(false)이 호출된 경우 등).
Thank you in advice!
미리 감사드립니다!
높은 점수를 받은 Solution
onView(withText("dialogText")).check(matches(isDisplayed()));
or, based on text with id
또는, id로 기반한 텍스트
onView(withId(R.id.myDialogTextId)).check(matches(allOf(withText(myDialogText), isDisplayed()));
onView(withId(android.R.id.button1)).perform(click());
UPDATE
갱신하다
- I think is possible since Espresso has multi window support.
에스프레소는 멀티 윈도우를 지원하기 때문에 가능하다고 생각합니다.
- Not sure about clicking outside the custom dialog view but for checking if it is displaying or not you have to create your custom matcher and check inside it.
사용자 정의 다이얼로그 뷰 바깥쪽을 클릭하는 것은 모르겠지만, 표시되는지 여부를 확인하려면 사용자 정의 matcher를 만들어 내부를 확인해야합니다.
가장 최근 달린 Solution
Just in case anyone stumbles across this question like I did. All the answers will only work for dialogs WITH dialog buttons. Do not try and use this for progress dialogs without user interaction. Espresso keeps waiting for the app to enter an idle state. As long as the progress dialog is visible the app is not idle.
어쩌면 누군가가 이 질문에 대해 제가 한 것처럼 우연히 발견할 수 있습니다. 모든 대답은 대화 상자 버튼이있는 대화 상자에만 작동합니다. 사용자 상호 작용이없는 진행 대화 상자에 대해서는 이를 시도하지 마십시오. Espresso는 앱이 대기 상태에 들어갈 때까지 기다립니다. 진행 대화 상자가 표시되는 한 앱은 대기 상태가 아닙니다.
출처 : https://stackoverflow.com/questions/21045509/check-if-a-dialog-is-displayed-with-espresso