Back to Repositories

Testing MacOS Window Close Crash Prevention in NW.js

This test suite validates application window closing behavior on macOS platforms using Selenium WebDriver, specifically focusing on crash prevention during window closure operations. The test ensures proper cleanup and memory management when closing NW.js application windows on Mac systems.

Test Coverage Overview

The test coverage focuses on platform-specific window closing functionality for macOS environments.

Key areas tested include:
  • Platform-specific execution control
  • Window close button interaction
  • Post-closure element verification
  • Crash prevention validation

Implementation Analysis

The testing approach utilizes Selenium WebDriver with Chrome options for automated UI interaction testing. The implementation employs platform detection for Mac-specific execution and incorporates explicit element verification through DOM queries.

Key patterns include:
  • Platform-specific test filtering
  • WebDriver session management
  • Element interaction verification
  • Proper resource cleanup

Technical Details

Testing tools and configuration:
  • Selenium WebDriver for browser automation
  • Chrome Options for NW.js app configuration
  • Platform module for OS detection
  • Environment variable integration for ChromeDriver path
  • Try-finally block for resource management

Best Practices Demonstrated

The test demonstrates robust testing practices for desktop application automation.

Notable practices include:
  • Platform-specific test isolation
  • Proper exception handling
  • Resource cleanup in finally block
  • Explicit assertion validation
  • Environment-aware configuration

nwjs/nwJs

test/sanity/issue4056-mac-close-crash/test.py

            
import time
import os
import platform
import sys

if platform.system() != 'Darwin':
    print('Skipped for non Mac platform')
    sys.exit(0)

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)
    driver.find_element_by_id('winclose').click()
    assert(driver.find_element_by_id('result') is None)
finally:
    driver.quit()