TestProject Forum

Android commands fails

Hello Team,
it seems that running commands using adb is failing. i used the adb wrapper addon and also the shell command addon and they both fails to run basic commands like- adb devices / adb logcat > file.txt.

this is very critical thing for our tests . is there any option to resolve this issue?

Hello @geoedgeqa.

The ADB Wrapper addon runs ADB commands on the device itself.

That is why a command like adb devices will not work using that addon, however will work using the Execute action from the Shell Commands addon.

image

See following example:

image

I filled in the first command input field with:

adb devices

and the rest of the input fields are empty.

After running the command with my Xiaomi Android device connected to my PC, I received the expected output as I would if I ran this command from my terminal.

Action output:

My terminal output:

image

One again, you can use the same action to save device logs:

image

After running the adb -d logcat -d>C:\logs\log4.txt​ a file will be created in my logs directory on my PC:

image

You CAN save logs with the ADB Wrapper as well, however they will need to be stored ON the device itself in a writeable directory, if you just use logcat > file.txt the default location is the root directory of the device’s internal storage, which is normally read-only and you will be faced with the following error:

image

So specify a writeable directory on the device, for example this command will work:

adb shell logcat > mnt/sdcard/log.txt​

You should take note of the two additional fields in the action.

Some commands take more than 5 seconds, or are never terminated, for this you will need to specify a timeout, if you want logs for 10 seconds, specify 10000 milliseconds.

In addition, since the logcat command does not terminate on it’s own, specify the DoNotFailOnTimeout parameter to be true so that the step will not fail, of course you can also just use the always pass step failure behavior.

thanks for your reply, i tested it with my emulators per your steps! and it fails.
it created the file but it empty.


it should work with emulators also, correct?

see screenshot attached

Try it out in your PC’s terminal, if it works there it should work through the addon as well.

As for this case, from the error message, it looks like the command was interrupted since it did not finish after 15 seconds, depending on the runtime you see in your terminal, you can increase the timeout of this step through the Timeout field.

image

As I mentioned earlier, it’s in milliseconds.

You can also use the -t flag on the logcat command to get a specific amount of lines from the log, shortening the execution time.

For example:
adb logcat -t 100>C:\logs\log9.txt

Will get the last 100 lines.

And yes, it does work on Android emulators.

Android Studio emulators for example:

Unfortunately, I am not able to do this at the moment on other emulators from other providers, however we do support Genymotion emulators (Desktop Edition).

David,
Thanks for your assistance- it seems to work as you described.
great support- really appreciate it.

1 Like