Web and WebView Performance Testing Guide

The Network panel in Chrome DevTools provides comprehensive insights into resource loading behavior. The timeline displays resource ordering based on load completion sequence, with vertical lines indicating key milestones:

  • Blue vertical line: DOM Content Loaded event fired
  • Red vertical line: All resources fully loaded

Key options for accurate testing:

  • Preserve log: Maintains network log across page navigations
  • Disable cache: Essential for performance testing to prevent cached responses from skewing results

The Waterfall view reveals resource loading sequences. Hold Shift while hovering over a resource to visualize its dependencies. Use the filter functionality too isolate specific resource types for detailed analysis.

Network Throttling and Offfline Testing

WebView environments support network condition simulation for testing under constrained bandwidth scenarios. The throttling dropdown allows selection of predefined profiles like "Slow 3G" or custom latency/throughput settings.

Offline mode tests application resilience. Most web applications fail gracefully when offline, displaying connectivity errors. Progressive Web Apps (PWAs) with service workers can provide offline functionality through cached assets.

Performance Profiling with DevTools

The Performance panel captures runtime behavior through recording sessions. Click the record button to capture a profiling session.

Navigation controls within the profiler:

  • A/D keys: Pan timeline left/right
  • W/S keys: Zoom in/out on timeline

The Main thread flame graph visualizes JavaScript execution stack. Focus analysis on the main thread to identify long tasks blocking rendering. The flame graph reveals call hierarchies and helps pinpoint performance bottlenecks.

Automated Performance Metrics Collection

The W3C Navigation Timing API provides programmatic access to page load metrics. This example demonstrates automated data collection from a WebView within a hybrid Android application:

import pytest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy


class PerformanceMetricsCollector:
    PACKAGE_NAME = "com.xueqiu.android"
    MAIN_ACTIVITY = ".view.WelcomeActivityAlias"
    CHROMEDRIVER_PATH = "C:/tools/chromedriver/chromedriver.exe"

    def setup_method(self):
        capabilities = {
            "platformName": "android",
            "deviceName": "test_device",
            "appPackage": self.PACKAGE_NAME,
            "appActivity": self.MAIN_ACTIVITY,
            "noReset": True,
            "chromedriverExecutable": self.CHROMEDRIVER_PATH
        }
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", capabilities)
        self.driver.implicitly_wait(10)

    def collect_webview_metrics(self):
        # Navigate to WebView section
        self.driver.find_element(AppiumBy.XPATH, "//*[@text='交易']").click()
        
        # Switch context to WebView
        webview_context = self.driver.contexts[-1]
        self.driver.switch_to.context(webview_context)
        
        # Extract timing data via JavaScript
        timing_data = self.driver.execute_script("return window.performance.timing")
        
        # Calculate response duration
        response_duration = timing_data['responseEnd'] - timing_data['responseStart']
        
        return {
            "response_time_ms": response_duration,
            "dom_complete": timing_data['domComplete'] - timing_data['navigationStart'],
            "load_complete": timing_data['loadEventEnd'] - timing_data['navigationStart']
        }

    def teardown_method(self):
        self.driver.quit()


class TestWebViewPerformance:
    def test_page_load_timing(self):
        collector = PerformanceMetricsCollector()
        collector.setup_method()
        metrics = collector.collect_webview_metrics()
        print(f"Response Time: {metrics['response_time_ms']}ms")
        collector.teardown_method()

Reference: W3C Navigation Timing Specification

System Resource Monitoring via ADB

Android's Linux kernel foundation enables system-level monitoring through ADB shell commands. The top command provides CPU utilization snapshots:

while true; do adb shell top -n 1 | grep com.xueqiu.android | awk '{print $3}'; sleep 1; done

Note: The top command introduces measurement overhead. For production monitoring, consider lightweight alternatives like dumpsys cpuinfo or dedicated profiling tools.

CPU time distribution:

  • User mode: Application code execution, computations
  • Kernel mode: System calls, I/O operations (file system access, network sockets)

Comprehensive performance analysis combines Navigation Timing metrics with resource utilizasion data (CPU, memory, I/O) to identify optimization opportunities.

Tags: Chrome DevTools WebView Performance Navigation Timing API appium ADB

Posted on Sun, 01 Nov 2026 16:07:04 +0000 by PHPiSean