Search code examples
androidmultithreadingappiumadbappium-android

Copying text to clipboard leads to crash on parallel tests execution on emulators


Running test on appium android on several emulators. Using ThreadLocal to separate driver instances. Faced with problem when one of emulators always crashes on the same step.

After investigating I came to the conclusion that the reason is clipboard. One emulator clicks on the clipboard field and after some time the second do the same and crashes.

Java exception:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up

Adb logs:

*** FATAL EXCEPTION IN SYSTEM PROCESS
  java.lang.IllegalStateException: beginBroadcast() called while already in a broadcast
    at android.os.RemoteCallbackList.beginBroadcast(RemoteCallbackList.java:241)
    at com.android.server.clipboard.ClipboardService.setPrimaryClipInternal(ClipboardService.java:583)
    at com.android.server.clipboard.ClipboardService$1.onHostClipboardUpdated(ClipboardService.java:205)
    at com.android.server.clipboard.HostClipboardMonitor.run(ClipboardService.java:125)
    at java.lang.Thread.run(Thread.java:919)

So my question is:

  1. Whether it is possible to disable saving anything to clipboard using adb or appium command?
  2. Whether it is possible to clear it so it would be a kind of resetting?
  3. Or maybe there is a decision in the multithreading area?
  4. Any other ways?

Thanks for help.


Solution

  • I solved the problem by resetting the clipboard right after anything was placed in it. Means immediately after clicking on the field.

    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(new StringSelection(null), null);