Back to Repositories

Testing Worker Crash Recovery Implementation in NW.js

This test suite validates worker crash handling in NW.js using Selenium WebDriver integration. It focuses on verifying the stability of web workers and proper crash recovery mechanisms in the NW.js runtime environment.

Test Coverage Overview

The test coverage encompasses worker crash scenarios and recovery mechanisms in NW.js applications.

  • Validates web worker stability under Chrome runtime
  • Tests crash recovery and cleanup processes
  • Verifies proper window state management
  • Ensures WebDriver integration functionality

Implementation Analysis

The implementation utilizes Selenium WebDriver with Chrome options to create a controlled testing environment. The test leverages Python’s system utilities and custom NW.js utility functions to manage the application state and verify worker behavior.

  • Custom Chrome options configuration
  • Webview window type specification
  • Implicit wait handling
  • Element content verification

Technical Details

  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Python sys and os modules for path management
  • Custom nw_util helper functions
  • ChromeDriver with verbose logging
  • Implicit wait timeout of 5 seconds

Best Practices Demonstrated

The test implementation showcases robust error handling and resource cleanup practices.

  • Proper test environment setup and teardown
  • Try-finally block for driver cleanup
  • Explicit path management
  • Standardized assertion patterns
  • Comprehensive logging configuration

nwjs/nwJs

test/sanity/issue7450-worker-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
from selenium.webdriver.common import utils

chrome_options = Options()
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))
chrome_options.add_experimental_option("windowTypes", ["webview"])

testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(5)
try:
    print(driver.current_url)
    result = wait_for_element_id_content(driver, 'result', 'success')
    print('result: %s' % result)
    assert('success' in result)
finally:
    driver.quit()