Back to Repositories

Testing Chrome DevTools Object Inspection Workflow in NW.js

This test suite validates the Chrome DevTools integration in NW.js, specifically focusing on the inspection functionality and crash prevention. It ensures robust handling of object inspection operations in the developer console while maintaining application stability.

Test Coverage Overview

The test coverage encompasses critical DevTools interaction scenarios and crash prevention mechanisms.

  • Tests Chrome DevTools console object inspection
  • Validates window handle management
  • Verifies proper DevTools panel switching
  • Tests console input handling
  • Ensures stable object expansion behavior

Implementation Analysis

The implementation utilizes Selenium WebDriver for automated DevTools interaction testing. The approach systematically validates each step of the DevTools workflow, from initialization to object inspection.

  • Chrome options configuration for NW.js app testing
  • Window handle management and switching logic
  • Console interaction automation
  • Asynchronous operation handling with wait states

Technical Details

  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Custom utility functions for DevTools interaction
  • CSS selectors for element identification
  • Implicit and explicit wait mechanisms
  • Exception handling for cleanup

Best Practices Demonstrated

The test implementation showcases robust automation practices for DevTools testing.

  • Proper test cleanup with driver quit
  • Structured wait mechanisms for UI synchronization
  • Modular utility function usage
  • Clear step-by-step validation flow
  • Effective error handling and resource management

nwjs/nwJs

test/sanity/issue3835-inspect-crash/test.py

            
import time
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(2)
try:
    switch_to_app(driver)
    print(driver.current_url)
    print('wait for devtools open')
    wait_window_handles(driver, 2)
    print(driver.window_handles)
    print('switch to devtools')
    switch_to_devtools(driver)
    print('click Console panel')
    devtools_click_tab(driver, 'console')
    wait_for_element_id(driver, 'console-prompt')
    print('send_keys "chrome<enter>"')
    devtools_type_in_console(driver, 'chrome\n')
    time.sleep(2)
    driver.execute_script('document.querySelector(".console-object-preview").click()')
    time.sleep(1) # wait for crash!
    expanded = driver.find_element_by_css_selector('.console-view-object-properties-section.expanded')
    assert(expanded is not None)
finally:
    driver.quit()