Question

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.LaunchSettings

I want to send like

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

But getting error message like:

Unsupported standalone parameter.

tried like "Temple Run" or 'Temple Run' but no use.

Please suggest

Was it helpful?

Solution

    String defaultAppName = "My super App";

    String toAppName = getParams().getString("appName"); //pass app name with 'appName' key

    if (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();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top