Kristaps Mežavilks
Kristaps Mežavilks

Reputation: 595

Appium test launch fails on multiple devices

I am working on Windows 7 machine and trying to implement an Appium test to launch on 2 real Android devices parallel. I was able to launch on each of the 2 devices separately and test executed as expected but simultaneous launch using JUnit fails with following stacktrace for one of devices:

info: [debug] Pushing command to appium work queue: ["element:getText",{"elementId":"2"}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getText","params":{"elementId":"2"}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getText
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Sign up","status":0}
info: [debug] Responding to client with success: {"status":0,"value":"Sign up","sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}
info: <-- GET /wd/hub/session/c730d16f-ca7f-42aa-be23-da33bbefd9f0/element/2/text 200 56.413 ms - 81 {"status":0,"value":"Sign up","sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}
info: --> DELETE /wd/hub/session/c730d16f-ca7f-42aa-be23-da33bbefd9f0 {}
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: C:\Users\Kristaps.Mezavilks\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.1.204:5555 shell "input keyevent 3"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 6.985
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"c730d16f-ca7f-42aa-be23-da33bbefd9f0"}

Before launch I perform following actions:

Example of config file node_c.json:

{
   "capabilities":[
      {
         "browserName":"android",
         "version":"4.4.2",
         "maxInstances":3,
         "platform":"ANDROID",
         "deviceName":"192.168.1.204:5555"
      }
   ],
   "configuration":{
      "cleanUpCycle":2000,
      "timeout":30000,
      "proxy":"org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
      "url":"http://localhost:4730/wd/hub",
      "host":"localhost",
      "port":4730,
      "maxSession":1,
      "register":true,
      "registerCycle":5000,
      "hubPort":4444,
      "hubHost":"192.168.1.216"
   }
}

Getting Android driver:

static AndroidDriver get() {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setPlatform(Platform.ANDROID)
        capabilities.setBrowserName("")
        capabilities.setVersion(mobileVersion)
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceID);
        capabilities.setCapability(MobileCapabilityType.APP, appPath);
        capabilities.setCapability(MobileCapabilityType.UDID, deviceID)
        def URL remoteAddress = new URL("http://localhost:4444/wd/hub")
        new AndroidDriver(remoteAddress, capabilities)
    }

Do you have an idea what is the problem or at least could you point me in the right direction to look up the problem? Many thanks.

EDIT: After @Ageoffan suggestion fixed the first problem but now there is connection reset problem:

info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] json loading complete.
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
error: Unhandled error: Error: read ECONNRESET
    at exports._errnoException (util.js:746:11)
    at TCP.onread (net.js:559:26) context: [POST /wd/hub/session {"desiredCapabilities":{"app":"C:\\Users\\Kristaps.Mezavilks\\Workspace\\android-app\\project\\build\\outputs\\apk\\project-debug2.apk","browserName":"","udid":"192.168.1.219:5555","platformName":"Android]

Upvotes: 1

Views: 1199

Answers (3)

Kristaps Mežavilks
Kristaps Mežavilks

Reputation: 595

I was dealing with this problem over a week but finally I focused on the following stacktrace line info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724 and figured out that all instances connect to the same socket port (all tcp forwarding commands was equal for all instances).

So after a while I managed to find a way to define forwarding on custom ports by using bootstrap port parameter -bp <post_number> added to node command. After I had set custom ports I was able to launch simultaneous parallel tests even on 4 devices in real time.

Thanks to @Ageoffan for the help!

Upvotes: 1

SomeStudent
SomeStudent

Reputation: 3048

Post Edit, try seeing if the section in which you declare your capabilities is accurate. As the error log seems to point to that location. I know that my desired capabilities for my android tests looks as follows:

        File app = new File("pathway to your apk");

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");        
        capabilities.setCapability("platformName", "Android");        
        capabilities.setCapability("deviceName", "Android Emulator");        
        capabilities.setCapability("platformVersion", "4.4.2");  
        capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());

        driver = new AndroidDriver(new URL("your server url here"),capabilities);

Upvotes: 0

I think JUnit is using the same port for both of your test case when you are run in parallel. Try parameterising the port number.

Upvotes: 0

Related Questions