簡體   English   中英

Appium測試啟動在多個設備上失敗

[英]Appium test launch fails on multiple devices

我正在Windows 7計算機上工作,並嘗試實施Appium測試以在2個實際的Android設備上並行啟動。 我能夠分別在2個設備上分別啟動並按預期執行測試,但是使用JUnit同時啟動失敗,其中一個設備的堆棧跟蹤如下:

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"}

在啟動之前,我執行以下操作:

  • 啟動硒網格:
    java -jar selenium-server-standalone-2.46.0.jar -role -hub -throwOnCapabilityNotPresent
  • 啟動2個Appium節點:
    node appium --nodeconfig C:\\Users\\Kristaps.Mezavilks\\selenium\\node_p.json -p 4728 --udid 192.168.219:5555

    node appium --nodeconfig C:\\Users\\Kristaps.Mezavilks\\selenium\\node_c.json -p 4730 --udid 192.168.204:5555

配置文件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"
   }
}

獲取Android驅動程序:

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)
    }

您有什么問題的想法嗎?或者至少您可以指出正確的方向來查找問題? 非常感謝。

編輯: @Ageoffan建議修復了第一個問題后,現在有連接重置問題:

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]

我花了一周的時間來解決這個問題,但最終我專注於以下堆棧跟蹤行info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724 ,發現所有實例都連接到同一套接字端口(所有tcp轉發所有實例的命令均相同)。

因此,過了一會兒,我設法找到一種方法,通過使用添加到node命令的引導程序端口參數-bp <post_number>來定義自定義端口上的轉發。 設置自定義端口后,即使在4個設備上,我也能夠實時啟動並行並行測試。

感謝@Ageoffan的幫助!

我認為當您並行運行JUnit時,兩個測試用例都使用相同的端口。 嘗試參數化端口號。

編輯后,請嘗試查看聲明您的功能的部分是否正確。 由於錯誤日志似乎指向該位置。 我知道我的android測試所需的功能如下:

        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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM