Getting this error while running the script

Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: unknown error: unhandled inspector error: {“code”:-32000,“message”:“Promise was collected”}

I’m frequently encountering this error while running the script for a hybrid application. I’m not sure what’s causing it — could someone please look into this and assist as soon as possible?

Katalon version : 10.2.3

1 Like

kindly share the full error trace along with application technology

Based on the error message and your setup testing a hybrid app), here’s a structured approach to resolve the “Promise was collected” error:

Root Cause Analysis

This error typically occurs when:

  1. Appium loses connection with the WebView context
  2. JavaScript execution context changes during test execution
  3. WebView debugging issues in hybrid apps
  4. Timing issues between native↔web context switches

Solutions to Try

1. Update Appium and Drivers

bash

# Update to latest Appium (minimum 2.0+)
npm install -g appium@latest

# Update platform drivers
appium driver install uiautomator2
appium driver install xcuitest

2. Configure WebView Debugging

Add these capabilities to your mobile start method:

groovy

Mobile.startApplication('your_app_path', [
    'autoWebView': true,
    'autoWebViewTimeout': 20000,  // 20-second timeout for WebView
    'webviewConnectTimeout': 30000,
    'nativeWebScreenshot': true
])

3. Add Context Switching Safeguards

groovy

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import io.appium.java_client.AppiumDriver

// After launching app
Mobile.delay(5)  // Wait for WebView initialization

// Get current driver instance
AppiumDriver driver = MobileDriverFactory.getDriver()

// Wait for WebView context to appear
int attempts = 0
while (driver.contextHandles.size() <= 1 && attempts < 10) {
    Mobile.delay(2)
    attempts++
}

// Switch to WebView context
if (driver.contextHandles.size() > 1) {
    driver.context(driver.contextHandles.last())
} else {
    Mobile.takeScreenshot()
    throw new Exception("WebView context not found!")
}

4. JavaScript Execution Protection

Wrap all JavaScript executions with this safety check:

groovy

def safeExecuteJS(String script) {
    try {
        return Mobile.executeJavaScript(script, null)
    } catch(Exception e) {
        Mobile.switchToNative()
        Mobile.delay(1)
        Mobile.switchToWebView()
        return Mobile.executeJavaScript(script, null)
    }
}

// Usage:
safeExecuteJS("document.getElementById('myElement').click();")

5. ChromeDriver Configuration

For Android WebViews:

groovy

Map<String, Object> chromeOptions = new HashMap<>()
chromeOptions.put("w3c", false)  // Disable W3C protocol

Mobile.startApplication('app_path', [
    'chromeOptions': chromeOptions,
    'chromedriverExecutable': '/path/to/chromedriver-2.46'  // Match Chrome version
])

6. Debugging Mode Verification

Ensure your WebView is debuggable:

  • Android: Add to AndroidManifest.xml

xml

<application android:debuggable="true">
    <WebView android:webContentsDebuggingEnabled="true" />
</application>
  • iOS: Enable isInspectable in WKWebView

7. Appium Server Log Analysis

Add this capability to capture detailed logs:

groovy

Mobile.startApplication('app_path', [
    'appium:showServerLogs': true,
    'appium:logLevel': 'debug'
])

Additional Troubleshooting Steps

  1. Reset App State between tests:

groovy

@BeforeTestCase
def resetApp() {
    Mobile.resetApplication()
}
  1. Driver Restart Fallback:

groovy

try {
    Mobile.tap(testObject, 10)
} catch(Exception e) {
    Mobile.closeApplication()
    // Re-initialize with updated capabilities
    Mobile.startApplication(...) 
}
  1. Browser Version Check:

groovy

String webViewVersion = Mobile.executeJavaScript("return navigator.userAgent;", null)
println "WebView Version: $webViewVersion"
// Verify compatibility with chromedriver

Hi @vinodh.kanna1,

Welcome to our community. It seems like you’re encountering a hybrid app testing issue using Appium with Chromedriver for WebView automation.

Your error is WebDriverException:

unknown error: unhandled inspector error: {“code”:-32000, “message”:“Promise was collected”}

This error occurs when trying to interact with a WebView element inside a hybrid mobile app, possible cause can be:

  • Incorrect or mismatched Chromedriver version
  • WebView context not properly initialized or switched**
  • Timing issues when trying to access the DOM of the WebView
  • WebView content is not fully loaded or accessible when your test script attempts to interact

My suggestions will be that you ensure proper Chromedriver Matching, meaning to check that the Chromedriver version matches the WebView/Chrome version inside your app.

If WebView version is, for example, Chrome 138.0.7204.157, download Chromedriver 138, you should change it by:

  1. Go to Project > Settings > Desired Capabilities > Mobile > Android

  2. Add or update this key:

    chromedriverExecutable: <path-to-matching-chromedriver>
    

Before interacting with WebView elements, switch to the correct context:

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import io.appium.java_client.AppiumDriver

// Get Appium driver
AppiumDriver<?> driver = MobileDriverFactory.getDriver()

// Print available contexts
println driver.getContextHandles()

// Switch to WebView
driver.context("WEBVIEW_com.your.package.name")  // adjust as needed

You must add some wait / delay for the WebView context to become available.

Hope this can help! Please let us know if your issue is solved.