All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jayway.android.robotium.solo.TextEnterer Maven / Gradle / Ivy

There is a newer version: 5.6.3
Show newest version
package com.jayway.android.robotium.solo;

import junit.framework.Assert;
import android.app.Instrumentation;
import android.widget.EditText;


/**
 * This class contains a method to enter text into text fields.
 * 
 * @author Renas Reda, [email protected]
 *
 */

class TextEnterer{
	
	private final Instrumentation inst;
	private final Waiter waiter;
	
    /**
     * Constructs this object.
     *
     * @param activityUtils the {@code ActivityUtils} instance
     * @param waiter the {@code Waiter} instance
     */
	
    public TextEnterer(Instrumentation inst, Waiter waiter) {
        this.inst = inst;
        this.waiter = waiter;
    }

	
	 /**
    * Sets an {@code EditText} text
    * 
    * @param index the index of the {@code EditText} 
    * @param text the text that should be set
    */
	
    public void setEditText(final EditText editText, final String text)
    {
    	waiter.waitForView(EditText.class, 0);
    	if(editText != null){
    		final String previousText = editText.getText().toString();
    		if(!editText.isEnabled())
    			Assert.assertTrue("Edit text is not enabled!", false);

    		inst.runOnMainSync(new Runnable()
    		{
    			public void run()
    			{
    				editText.setInputType(0); 
    				editText.performClick();
    				if(text.equals(""))
    					editText.setText(text);
    				else{
    					editText.setText(previousText + text);
    					editText.setCursorVisible(false);
    				}
    			}
    		});
    	}
    }
   

	
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy