Sha256: 8f67ee144c0d7eafbb1fec4742a43a0789cbcd046f46d3f1b1bfd91ec66ffdc0

Contents?: true

Size: 1.47 KB

Versions: 54

Compression:

Stored size: 1.47 KB

Contents

package sh.calaba.instrumentationbackend.actions.webview;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import sh.calaba.instrumentationbackend.Result;
import sh.calaba.instrumentationbackend.actions.Action;
import sh.calaba.org.codehaus.jackson.map.ObjectMapper;
import sh.calaba.org.codehaus.jackson.type.TypeReference;


public class SetText implements Action {

	/**
	 * args[0]: Selector type "xpath" or "css"
	 * args[1]: xpath or css selector
	 * args[2]: text to enter into the first selected element 
	 */
    @Override
    public Result execute(String... args) {
    	try {
	    	String queryResult = QueryHelper.executeJavascriptInWebview("calabash.js", args[1], args[0]);
	    	List<HashMap<String,Object>> p = new ObjectMapper().readValue(queryResult, new TypeReference<List<HashMap<String,Object>>>(){});
			
			if (p.isEmpty()) {
				throw new RuntimeException("No element found");
			}
			Map<String, Object> firstElement = QueryHelper.findFirstVisibleElement(p);
			//TODO: Hack! Should be serialized instead of removed
			firstElement.remove("class");
			firstElement.remove("html");
			String firstElementJson = QueryHelper.toJsonString(firstElement);
			
			String result = QueryHelper.executeJavascriptInWebview("set_text.js", firstElementJson, args[2]);
	    	return new Result(true, result);
    	} catch (Exception e) {
    		throw new RuntimeException(e);
		}
    }

    @Override
    public String key() {
        return "set_text";
    }
    
    

}

Version data entries

54 entries across 54 versions & 2 rubygems

Version Path
calabash-android-0.4.0.pre6 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.4.0.pre5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.4.0.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.4.0.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
testautoa-0.4.0 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.4.0.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.4.0.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.8 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.7 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.6 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.3.pre5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.3.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.3.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.3.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.2.pre5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java
calabash-android-0.3.2.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java