Back to Repositories

Validating DevTools Crash Prevention in NW.js

This test suite validates the stability of NW.js DevTools functionality by ensuring the application doesn’t crash when DevTools are opened. It implements automated browser testing using Selenium WebDriver to simulate DevTools interactions and verify window handle management.

Test Coverage Overview

The test focuses on critical DevTools stability verification in NW.js, specifically addressing issue #6001 regarding crash prevention.

Key areas covered:
  • DevTools window opening process
  • Window handle management and persistence
  • Application stability monitoring
  • Binary file compilation validation

Implementation Analysis

The test utilizes Selenium WebDriver with Chrome options to automate browser interactions and DevTools manipulation. It implements a systematic approach combining binary compilation verification and window handle management.

Notable patterns include:
  • Chrome WebDriver initialization with custom options
  • Window handle state verification
  • Implicit wait implementation for synchronization
  • Binary compilation validation steps

Technical Details

Testing tools and configuration:
  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • NWJC compiler for JavaScript binary compilation
  • Custom utility functions for window management
  • Platform-specific path handling for cross-OS compatibility

Best Practices Demonstrated

The test exemplifies robust testing practices through proper resource cleanup and error handling.

Quality aspects include:
  • Proper test cleanup with driver.quit()
  • Cross-platform compatibility considerations
  • Explicit state verification steps
  • Comprehensive error handling with try-finally blocks
  • Clear test flow organization

nwjs/nwJs

test/sanity/issue6001-devtools-open-crash/test.py

            
import time
import os
import shutil
import subprocess
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()
testdir = os.path.dirname(os.path.abspath(__file__))
chrome_options.add_argument("nwapp=" + testdir)
binfile = os.path.join(testdir, "index.bin")
nwjc = os.path.join(os.path.dirname(os.environ['CHROMEDRIVER']),
       "nwjc.exe" if os.name == "nt" else "nwjc")
os.chdir(testdir)

try:
  os.remove(binfile)
except:
  pass

assert(False == os.path.isfile(binfile))
subprocess.call([nwjc, "--future", "index.js", "index.bin"])
assert(os.path.isfile(binfile))

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('waiting for devtools open')
    wait_window_handles(driver, 2)
    print('switch to devtools')
    switch_to_devtools(driver, None, True)
    print('waiting for crash')
    time.sleep(5)
    handles = driver.window_handles
    assert(len(handles) is 2)
    print('There is no crash')
finally:
    driver.quit()