Issue
Logcat does not print anything while it's supposed to when the submit button is clicked!
What am I missing?
MainActivityFunctionalTest
public class MainActivityFunctionalTest extends
ActivityInstrumentationTestCase2<MainActivity> {
public void testRegistrationFormIsSubmitted() {
final MainActivity mainActivity = (MainActivity) solo.getCurrentActivity();
try {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
ImageButton submitBtn = (ImageButton) solo.getView(R.id.btn_next);
assertNotNull(submitBtn);
submitBtn.performClick();
}
});
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
MainActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageButton submitBtn = (ImageButton) findViewById(R.id.btn_next);
submitBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.i(TAG, "Submit button is clicked");// This is not printed
sendActivation(v);
}
});
}
Updates
So I changed submitBtn.performClick()
to solo.clickOnView(submitBtn)
but the issue remains the same
Solution
There were 2 issues with my codes:
1) ImageButton
click is not supported by Robotium (they recommend sticking to View
instead)
2) Click event cannot happen when the screen of my phone is off!
I made sure the screen of my phone is on and changed my code is the following and it works:
View submitBtn = solo.getView(R.id.btn_next);
assertNotNull(submitBtn);
solo.clickOnView(submitBtn);
Answered By - ericn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.