Skip to content Skip to sidebar Skip to footer

How To Send Text With Space In Android Uiautomator -e Command Line Parameter

I want to know how to send text with space in Android UIAutomator -e option (name-value pair) For Ex: adb shell uiautomator runtest LaunchSettings.jar -c com.uia.example.my.Launch

Solution 1:

StringdefaultAppName="My super App";

    StringtoAppName= getParams().getString("appName"); //pass app name with 'appName' keyif (toAppName != null) {
        toAppName = toAppName.replace("0"," "); //use 0 instead of space in app name
        defaultAppName=toAppName.trim();
    }

The above code will default to 'My super App' if no -e option (name-value pair) is passed when running this test.

To pass the arguments with space, like 'my super dooper app', according to the code above, 0 needs to be inserted for every space.

To pass 'my super dooper app' as an argument to the above code, one needs to send use:

-e appName "my0super0dooper0app"

In your case:

 adb shell uiautomator runtest LaunchSettings.jar -c com.uia.example.my.LaunchSettings -e appName Temple0Run

(Instead of '0' you can insert any alpha numeric character as a placeholder as shown in example below)

UiAutomator fails to understand command line parameters with space, &, <, > , (,) , ", ' , as well as some Unicode characters. In such a case, one has to replace a placeholder in command line with the desired symbol.

example:

if (toParam != null) {
        toParam = toParam.replace("0space0", " "); //insert 0space0 in command line parameters for every space
        toParam = toParam.replace("0amper0", "&"); //insert 0amper0 in command line parameters for every &
        toParam = toParam.replace("0less0", "<"); //insert 0less0 in command line parameters for every <
        toParam = toParam.replace("0more0", ">"); //insert 0more0 in command line parameters for every >
        toParam = toParam.replace("0openbkt0", "("); //insert 0openbkt0 in command line parameters for every (
        toParam = toParam.replace("0closebkt0", ")"); //insert 0closebkt0 in command line parameters for every )
        toParam = toParam.replace("0onequote0", "'"); //insert 0onequote0 in command line parameters for every '
        toNumber = toParam.trim();
    }

Post a Comment for "How To Send Text With Space In Android Uiautomator -e Command Line Parameter"