Issue
I'm testing a click on an AlertDialog's inner ListView using Espresso but keep getting NoMatchingViewException. The Dialog has a ListView that reads the accounts in the device.
AlertDialog.Builder builder = new AlertDialog.Builder(activity_reference);
builder.setTitle(R.string.main_dialog_title);
ListView lv = new ListView(activity_reference);
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(activity_reference, android.R.layout.simple_list_item_1, android.R.id.text1,
gUsernameList);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(activity_reference, "You selected :" + gUsernameList.get(position), Toast.LENGTH_LONG).show();
account_selected = gUsernameList.get(position);
}
}
);
builder.setView(lv);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton) {
if (account_selected == null) {
return;
}
dialog.dismiss();
Intent myIntent = new Intent(activity_reference, GraphActivity.class);
myIntent.putExtra("account_selected", account_selected); //Optional parameters
activity_reference.startActivity(myIntent);
}
}
);
final Dialog dialog = builder.create();
dialog.show();
And in the test
onView(withText(R.string.test_account)).inRoot(isDialog()).check(matches(isDisplayed()));
Am I doing anything wrong ? Thanks beforehand.
Edit : I tried using UIAutomator too but gets UIObjectNotFoundException, although it is clearly there in the uiautomatorviewer.
Solution
It seems I was just missing the initiation codes.
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
activityTestRule.getActivity();
Sorry for the false alarm.
Answered By - Sonny Kurniawan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.