I am having problems testing my app. I created an espresso test which is supposed to fail, since whenever I launch my app in the emulator, I get the expected behavior. There is my test:
onView(withText("wrong answer")).perform(click());
onView(withId(R.id.nextQuestionButton)).check(matches(isEnabled()));
When launching the test, nothing is reported, whereas nextQuestionButton should not be enabled upon clicking the radioButton whose text is "wrong answer".
ImageButton myButton = (ImageButton) findViewById(R. id. epic_button); if (myButton. isEnabled()){ //then the button is enabled. }
How to check whether the text box/field is Editable or not ? When you identify the object using uiautomatorviewer or appium inspector, in properties it will show you whether button is enabled and editable properties for textbox. You can use element. getAttribute(“enabled”), it will return you true or false.
see this: developer.android.com/reference/android/view/View.html. You can also use Next. setEnabled(false) for the required functionality.
According to what I understand, you want it to work like this:
if
nextQuestionButton
IS enabled, then take following actions:
- click on 'wrong answer',
- check if
nextQuestionButton
changed stated to NOT enabled.
If this is so, the code should be like this:
onView(withId(R.id.nextQuestionButton)).check(matches(isEnabled()));
onView(withText("wrong answer")).perform(click());
onView(withId(R.id.nextQuestionButton)).check(matches(not(isEnabled())));
Espresso allows you to use Hamcrest matchers in tests.
Hamcrest 1.3 Quick Reference.
Please check also this (if you haven't done that already):
Espresso 2.1. Espresso Cheat Sheet Master [updated]
According to this fragment of your post:
When launching the test, nothing is reported, whereas
nextQuestionButton
should not be enabled upon clicking theradioButton
whose text is "wrong answer".
It means that you hadn't set disabled your next question button, so Espresso passes this test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With