java - android testing - EditText returning empty even when it has characters -


i'm trying perform functional test on edittext, sending text first gaining focus on field using following snippet:

instrumentation.runonmainsync(new runnable() {     @override     public void run() {          edittext.requestfocus();     } } 

and sending string via:

instrumentation.waitforidlesync(); instrumentation.sendstringsync("some text"); instrumentation.waitforidlesync(); 

if run test , watch it, text being input edittext, when try use in assertion, edittext returns empty text:

assertfalse(edittext.gettext().tostring().isempty()); 

i've tried logging text, returns empty string, if there no text in edittext. have tried running assertion on separate runnable or after delay no avail.

temporary solution: meantime, i'm passing test manually adding

edittext.settext("some text"); 

before assertion, though think there better or correct way.

another work-around i've found using android espresso. after sending string edittext via instrumentation, can assert validity via:

 onview(withtext("some text")).check(matches(isdisplayed())); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -