Back to Repositories

Testing DevTools Crash Prevention Workflow in NW.js

This test suite validates the stability of debugging tools in NW.js by automating interactions with Chrome DevTools. It focuses on preventing crashes during repeated debugging operations and breakpoint handling.

Test Coverage Overview

The test ensures robust debugging functionality by validating DevTools stability across multiple debug sessions.

Key areas covered include:
  • Window handle management for DevTools
  • Breakpoint execution and resume operations
  • Cross-platform keyboard shortcut handling
  • Crash prevention validation

Implementation Analysis

The test implements a Selenium WebDriver approach to automate Chrome DevTools interactions. It utilizes platform-specific keyboard shortcuts and action chains to control debugging flow, with careful exception handling and retry logic for reliability.

Notable patterns include:
  • Implicit wait mechanisms for UI synchronization
  • Platform-aware command key handling
  • Recursive retry logic for UI interactions

Technical Details

Tools and configurations:
  • Selenium WebDriver with Chrome Options
  • Custom nw_util helper functions
  • Platform-specific keyboard shortcut handling
  • ChromeDriver with verbose logging
  • Native module installation support
  • Window handle management utilities

Best Practices Demonstrated

The test exemplifies robust automation practices with comprehensive error handling and platform compatibility.

Notable practices include:
  • Proper test cleanup in finally blocks
  • Detailed progress logging
  • Timeout handling with retry mechanisms
  • Cross-platform compatibility checks
  • Modular utility function usage

nwjs/nwJs

test/sanity/issue5882-debugging-tools-crash/test.py

            
import time
import os
import platform
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

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.support.select import Select

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

install_native_modules()

def clickResume():
    if platform.system() != "Darwin":
        ActionChains(driver).key_down(Keys.CONTROL).send_keys("\\").key_up(Keys.CONTROL).perform()
    else:
        ActionChains(driver).key_down(Keys.COMMAND).send_keys("\\").key_up(Keys.COMMAND).perform()

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(2)
try:
    switch_to_app(driver)
    print(driver.current_url)
    print('wait for devtools open')
    wait_window_handles(driver, 2)
    print('switch to devtools')
    switch_to_devtools(driver)
    print("click Sources panel")
    devtools_click_tab(driver, 'sources')
    print('start to debug line 16 via breakpoint')
    for i in range(10):
        print("click Resume script execution button: %s" % i) 
        j = 0
        while j < 10:
            try:
                clickResume()
                break
            except selenium.common.exceptions.WebDriverException:
                pass
            time.sleep(1)
            j = j + 1
            if j >= 10:
                raise Exception('Timeout when waiting for clicking resume button')
    assert(len(driver.window_handles) is 2)
    print('There is no crash')
finally:
    driver.quit()