karatesaucelabs

[Karate Test][Saucelab]: Session disconnecting after launching mobile app installed in Saucelab


I am launching android test on Saucelab, however I can see the script is launching the mobile app on saucelab but not able to perform any action on it and throwing this exception:

12:54:20.931 [main] ERROR com.intuit.karate - java.net.SocketTimeoutException: Read timed out, http call failed after 32303 milliseconds for url: https://oauth-abdulkadir786-684f1:1bd00f8e-392f-4b4c-8f0e-2597cc9912a3@ondemand.eu-central-1.saucelabs.com:443/wd/hub/session

I am using the following steps for execute my test:

Configure driver in karate-config.js

   var android = {}
 android["desiredConfig"] = {
 "accessKey":"1bd00f8e-392f-4b4c-8f0e-2597cc9912a3",
 "deviceName":"Android GoogleAPI Emulator",
 "app" : "storage:b82d6099-60ad-49dd-b15f-925166e03dcd",
  "platformVersion" : "11.0",
  "platformName" : "Android",
  "newCommandTimeout":300,
  "automationName" : "UiAutomator2",
  "username": "oauth-abdulkadir786-684f1"
 }
 config["android"] = android

Then Writing the feature file to call the webDriverSession:

    Feature: Calling test from Sauce labs
    
  Background:
    * configure driver = { type: 'android', start: false, webDriverUrl: 'https://oauth-abdulkadir786-684f1:1bd00f8e-392f-4b4c-8f0e-2597cc9912a3@ondemand.eu-central-1.saucelabs.com:443/wd/hub' }

  Scenario: android mobile app UI tests
    Given driver { webDriverSession: { desiredCapabilities : "#(android.desiredConfig)"} }
    * delay(2000)
    Then click('/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.Button[3]')

Any help would be highly appreciated.....


Solution

  • It looks like Karate is timing out the session before the emulator and app gets a chance to load fully:

    Read timed out, http call failed after 32303 milliseconds for url: https://oauth-abdulkadir786-684f1:1bd00f8e-392f-4b4c-8f0e-2597cc9912a3@ondemand.eu-central-1.saucelabs.com:443/wd/hub/session
    

    The suspicious parts are Read timed out, 32303 milliseconds (which is pretty close to 30 seconds and so is probably a config thing; 30 or 60 seconds is a common default timeout) and the path /wd/hub/session looks like the initial POST request which starts a sesson.

    You'll probably have more luck if you increase the connectTimeout and readTimeout, either in your Background or in karate-config.js:

      karate.configure('connectTimeout', 60000);
      karate.configure('readTimeout', 60000);