Back to Repositories

Testing Child Process ExecSync Stability in NW.js

This test suite validates the child process execSync functionality in NW.js, ensuring the application handles synchronous execution without crashing. It implements Selenium WebDriver to automate browser interactions and verify process behavior.

Test Coverage Overview

The test suite focuses on validating the child process execSync stability in NW.js applications.

Key areas covered include:
  • Process synchronization verification
  • Crash prevention validation
  • Browser state persistence testing
  • Element interaction and response validation

Implementation Analysis

The implementation utilizes Selenium WebDriver with Chrome options for automated testing. The approach combines browser automation with process execution verification, using explicit wait patterns and element identification strategies.

Technical patterns include:
  • Chrome WebDriver configuration
  • Dynamic element waiting
  • Assertion-based validation
  • Error handling with try-finally blocks

Technical Details

Testing tools and configuration:
  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Custom utility functions from nw_util
  • Environment-based ChromeDriver path
  • Dynamic path resolution for test resources

Best Practices Demonstrated

The test implementation showcases robust testing practices for desktop applications.

Notable practices include:
  • Proper resource cleanup in finally blocks
  • Explicit waiting for element availability
  • Clear assertion messages
  • Modular test structure
  • Comprehensive error handling

nwjs/nwJs

test/sanity/issue6339-child-process-execSync-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)
try:
    print(driver.current_url)
    res = wait_for_element_id(driver, "result")
    print(res)
    assert("v" in res)
    driver.find_element_by_id("btn").click()
    print("waiting for crash")
    time.sleep(3)
    result = wait_for_element_id(driver, "result")
    assert("v" in result)
    print("There is no crash")
finally:
    driver.quit()